1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-09 13:33:26 +00:00

Fix swapping of lambda arguments and gcd example

This commit is contained in:
David Schmenk 2024-07-08 17:09:31 -07:00
parent 5e00ed6a4d
commit 6f58db9b92
4 changed files with 28 additions and 3 deletions

7
src/lisp/gcd.lisp Normal file
View File

@ -0,0 +1,7 @@
(label gcd (lambda (x y)
(cond ((> x y) (gcd y x))
((eq (rem y x) 0) x)
(t (gcd (rem y x) x))
)
)
)

View File

@ -490,6 +490,7 @@ end
def eval_lambda(expr, params)
var args, assoc_org, result
var newlist, pairlist, pair
if !expr or expr=>car <> sym_lambda
puts("Invalid LAMBDA expression: ")
@ -498,11 +499,26 @@ def eval_lambda(expr, params)
fin
assoc_org = assoc_list
args = expr=>cdr=>car
newlist = NULL
while args
new_assoc(args=>car, eval_expr(params=>car))
args = args=>cdr
params = params=>cdr
if !newlist
newlist = new_cons
pairlist = newlist
else
pairlist=>cdr = new_cons
pairlist = pairlist=>cdr
fin
pair = new_cons
pair=>car = args=>car
pair=>cdr = eval_expr(params=>car)
pairlist=>car = pair
args = args=>cdr
params = params=>cdr
loop
if newlist
pairlist=>cdr = assoc_list
assoc_list = newlist
fin
result = eval_expr(expr=>cdr=>cdr=>car)
assoc_list = assoc_org
return result

View File

@ -21,3 +21,4 @@ cat lisp/drawl.pla | ./ac.jar -ptx DRAWL.po lisp/DRAWL.PLA TXT
cat lisp/set.lisp | ./ac.jar -ptx DRAWL.po lisp/SET.LISP TXT
cat lisp/list.lisp | ./ac.jar -ptx DRAWL.po lisp/LIST.LISP TXT
cat lisp/maplist.lisp | ./ac.jar -ptx DRAWL.po lisp/MAPLIST.LISP TXT
cat lisp/gcd.lisp | ./ac.jar -ptx DRAWL.po lisp/GCD.LISP TXT

View File

@ -181,6 +181,7 @@ cp lisp/drawl.pla prodos/bld/lisp/DRAWL.PLA.TXT
cp lisp/set.lisp prodos/bld/lisp/SET.LISP.TXT
cp lisp/list.lisp prodos/bld/lisp/LIST.LISP.TXT
cp lisp/maplist.lisp prodos/bld/lisp/MAPLIST.LISP.TXT
cp lisp/gcd.lisp prodos/bld/lisp/GCD.LISP.TXT
#mkdir prodos/bld/examples
#cp samplesrc/examples/ex.1.pla prodos/bld/examples/EX.1.PLA.TXT