local obj="${ANON["${1}"]}"
eval r="\${${obj}[\"${2}\"]}" ;;
list|vector)
- _nth "${1}" "${2}"
+ _nth "${1}" "${2}" ;;
+ nil)
+ r="${__nil}" ;;
esac
}
get () {
} else {
return &mal_nil;
}
+ case MAL_NIL:
+ return &mal_nil;
default:
abort("get called on unsupported type %d", obj->type);
}
static MalFunction get = new MalFunction(
a => {
string key = ((MalString)a[1]).getValue();
- var dict = ((MalHashMap)a[0]).getValue();
- return dict.ContainsKey(key) ? dict[key] : Nil;
+ if (a[0] == Nil) {
+ return Nil;
+ } else {
+ var dict = ((MalHashMap)a[0]).getValue();
+ return dict.ContainsKey(key) ? dict[key] : Nil;
+ }
});
static MalFunction keys = new MalFunction(
static MalFunction get = new MalFunction() {
public MalVal apply(MalList a) throws MalThrowable {
- String key = ((MalString)a.nth(1)).getValue();
- MalHashMap mhm = (MalHashMap)a.nth(0);
- HashMap<String,MalVal> hm = (HashMap<String,MalVal>)mhm.value;
- if (hm.containsKey(key)) {
- return hm.get(key);
- } else {
+ if (a.nth(0) == Nil) {
return Nil;
+ } else {
+ String key = ((MalString)a.nth(1)).getValue();
+ MalHashMap mhm = (MalHashMap)a.nth(0);
+ HashMap<String,MalVal> hm = (HashMap<String,MalVal>)mhm.value;
+ if (hm.containsKey(key)) {
+ return hm.get(key);
+ } else {
+ return Nil;
+ }
}
}
};
return reader.read_str(((MalString)args.nth(0)).getValue());
} catch (MalContinue c) {
return types.Nil;
- return reader.read_str(((MalString)args.nth(0)).getValue());
+ }
}
});
_ref(repl_env, "eval", new MalFunction() {
return reader.read_str(((MalString)args.nth(0)).getValue());
} catch (MalContinue c) {
return types.Nil;
- return reader.read_str(((MalString)args.nth(0)).getValue());
+ }
}
});
_ref(repl_env, "eval", new MalFunction() {
}
function get(hm, key) {
- if (key in hm) {
+ if (hm != null && key in hm) {
return hm[key];
} else {
return null;
}
function _EVAL(ast, env) {
+ //printer.println("EVAL:", types._pr_str(ast, true));
if (!types._list_Q(ast)) {
return eval_ast(ast, env);
}
}
function _EVAL(ast, env) {
+ //printer.println("EVAL:", types._pr_str(ast, true));
if (!types._list_Q(ast)) {
return eval_ast(ast, env);
}
}
function _EVAL(ast, env) {
+ //printer.println("EVAL:", types._pr_str(ast, true));
if (!types._list_Q(ast)) {
return eval_ast(ast, env);
}
# retrieve the value of a string key object from the hash map, or
# retrive a vector by number object index
get = $(strip \
- $(if $(call _hash_map?,$(word 1,$(1))),\
- $(call _get,$(word 1,$(1)),$(call str_decode,$($(word 2,$(1))_value))),\
- $(call _get,$(word 1,$(1)),$(call int_decode,$($(word 2,$(1))_value)))))
+ $(if $(call _nil?,$(word 1,$(1))),\
+ $(__nil),\
+ $(if $(call _hash_map?,$(word 1,$(1))),\
+ $(call _get,$(word 1,$(1)),$(call str_decode,$($(word 2,$(1))_value))),\
+ $(call _get,$(word 1,$(1)),$(call int_decode,$($(word 2,$(1))_value))))))
contains? = $(if $(call _contains?,$(word 1,$(1)),$(call str_decode,$($(word 2,$(1))_value))),$(__true),$(__false))
return hm
def get(hm, key):
- if key in hm:
+ if hm and key in hm:
return hm[key]
else:
return None
:map? => lambda {|a| a.is_a? Hash},
:assoc => lambda {|*a| a[0].merge(Hash[a.drop(1).each_slice(2).to_a])},
:dissoc => lambda {|*a| h = a[0].clone; a.drop(1).each{|k| h.delete k}; h},
- :get => lambda {|a,b| a[b]},
+ :get => lambda {|a,b| return nil if a == nil; a[b]},
:contains? => lambda {|a,b| a.key? b},
:keys => lambda {|a| List.new a.keys},
:vals => lambda {|a| List.new a.values},