9 func env_new
(outer_ptr
, binds
=, exprs
=)
11 env
= Env
(outer
=outer_ptr
, data
=hash_new
())
12 for
(i
= 1; i
<= numberof
(binds
); ++i
) {
13 if
(binds
(i
)->val
== "&") {
14 rest_args
= numberof
(exprs
) >= i ? exprs
(i
:) : []
15 env_set
, env
, binds
(i
+ 1)->val
, MalList
(val
=&rest_args)
18 env_set
, env
, binds
(i
)->val
, *exprs
(i
)
24 func env_find
(env
, key
)
26 if
(hash_has_key
(env.data
, key
)) return env
27 if
(is_void
(*env.outer
)) return nil
28 return env_find
(*env.outer
, key
)
31 func env_get
(env
, key
)
33 found_env
= env_find
(env
, key
)
34 if
(is_void
(found_env
)) return MalError
(message
=("'" + key
+ "' not found"))
35 return hash_get
(found_env.data
, key
)
38 func env_set
(&env, key, val)