[Omake] adding a python-like "dict.get"

Erick Tryzelaar erickt at dslextreme.com
Fri Feb 23 02:26:08 PST 2007


Hi guys,

I use python's get function on dictionaries to simplify a bunch of code. 
It's pretty trivial to add functions to handle this, so think it'd 
worthwhile enough to be added?

   obj-get(o, v, x) =
      result =
         try
            value $(obj-find $o, $v)
         default
            value $x
      return $(result)

   Object. +=
      object-find(v, x) =
         return $(obj-get $(this), $v, $x)

   map-get(o, v, x) =
      result =
         try
            value $(map-find $o, $v)
         default
            value $x
      return $(result)

   Map. +=
      get(v, x) =
         return $(map-get $(this), $v, $x)


Also, things would be a little simpler if we could do this:

   obj-get(o, v, x) =
      return
         try
            value $(obj-find $o, $v)
         default
            value $x

Could this (or something equivalent) ever be supported?

-e


More information about the Omake mailing list