Skip to content

Commit e5173fb

Browse files
committed
lis.py: added 'define' procedure short form
1 parent 0cbb0c5 commit e5173fb

File tree

1 file changed

+9
-9
lines changed
  • 18-context-mngr/lispy/py3.10

1 file changed

+9
-9
lines changed

18-context-mngr/lispy/py3.10/lis.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,22 @@ def lispstr(exp: object) -> str:
142142
def evaluate(x: Expression, env: Environment) -> Any:
143143
"Evaluate an expression in an environment."
144144
match x:
145-
case Symbol(var): # variable reference
145+
case Symbol(var): # variable reference
146146
return env[var]
147-
case literal if not isinstance(x, list): # constant literal
147+
case literal if not isinstance(x, list): # constant literal
148148
return literal
149-
case ['quote', exp]: # (quote exp)
149+
case ['quote', exp]: # (quote exp)
150150
return exp
151-
case ['if', test, conseq, alt]: # (if test conseq alt)
151+
case ['if', test, conseq, alt]: # (if test conseq alt)
152152
exp = conseq if evaluate(test, env) else alt
153153
return evaluate(exp, env)
154-
case ['define', Symbol(var), exp]: # (define var exp)
154+
case ['lambda', parms, body]: # (lambda (parm...) body)
155+
return Procedure(parms, body, env)
156+
case ['define', Symbol(var), exp]: # (define var exp)
155157
env[var] = evaluate(exp, env)
156-
case ['define', [name, *parms], body]: # (define (fun parm...) body)
158+
case ['define', [name, *parms], body]: # (define (fun parm...) body)
157159
env[name] = Procedure(parms, body, env)
158-
case ['lambda', parms, body]: # (lambda (parm...) body)
159-
return Procedure(parms, body, env)
160-
case [op, *args]: # (proc arg...)
160+
case [op, *args]: # (proc arg...)
161161
proc = evaluate(op, env)
162162
values = (evaluate(arg, env) for arg in args)
163163
return proc(*values)

0 commit comments

Comments
 (0)