-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.hum
54 lines (44 loc) · 1.05 KB
/
lambda.hum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#
# Core λ-calculus
#
CREATE empty_env WITH λ(cust, _).[
SEND ? TO cust
]
LET env_beh(ident, value, next) = λ(cust, ident').[
IF $ident' = $ident [
SEND value TO cust
] ELSE [
SEND (cust, ident') TO next
]
]
LET const_expr_beh(value) = λ(cust, #eval, _).[
SEND value TO cust
]
LET ident_expr_beh(ident) = λ(cust, #eval, env).[
SEND (cust, ident) TO env
]
LET abs_expr_beh(ident, body_expr) = λ(cust, #eval, env).[
CREATE closure WITH λ(cust, #apply, arg).[
CREATE env' WITH env_beh(ident, arg, env)
SEND (cust, #eval, env') TO body_expr
]
SEND closure TO cust
]
LET app_expr_beh(abs_expr, arg_expr) = λ(cust, #eval, env).[
SEND (k_abs, #eval, env) TO abs_expr
CREATE k_abs WITH λabs.[
SEND (k_arg, #eval, env) TO arg_expr
CREATE k_arg WITH λarg.[
SEND (cust, #apply, arg) TO abs
]
]
]
# (λx.x)(42) -> 42
CREATE example WITH app_expr_beh(
NEW abs_expr_beh(
#x,
NEW ident_expr_beh(#x)
),
NEW const_expr_beh(42)
)
SEND (println, #eval, empty_env) TO example