 
   get: (key) ->
     value = @get_raw(key)
-    return value(@,{}) if isFunction(value)
+    return value(@,{}) if _.isFunction(value)
     value
 
   owner: (key) ->

AUTHORITY = "_AUTHORITY"
INDEX = "_INDEX"

isFunction = (value) ->
  typeof(value) == "function"

isObject = (value) ->
  typeof(value) == "object"

isString = (value) ->
  typeof(value) == "string"

class World
  constructor: (up, label, rx) ->
    assert up, "up always exists"
    assert isObject(up), "up is an object"
    @up = up
    cache_rx = rx or @up.get_raw(RX)
    assert cache_rx, "cache_rx"
    @doc = cache_rx.map()
    assert isString(label), "label is string"
    @doc.put(LABEL, label)
    @doc.put(CHILDREN, cache_rx.array())
    @doc.put(RX, rx) if rx?


  call: (key, args) ->
    closure = @get_raw(key)
    assert _.isFunction(closure), "#{key}: #{closure} is not a function"
    closure(@, args)
    
  # TODO: refactor import_dict methods somewhere
  _import_children: (array) ->
    result = @rx().array()
    assert _.isArray(array), "_import_children: #{array} is not an array"
    for value in array
      assert value, 'import child'
      result.push @make_world(value)
