Reputation: 4020
No idea if anyone on this site happens to know about $vau calculi, but anyway, for some reason, this snippet leads to an infinite loop, and I'm not sure if it's due to the $vau implementation I use, or some bug in the snippet code itself.
($begin
(display "hello world")
($define! $lambda
($vau (ptree . body) static-env
(wrap (eval (list* $vau ptree #ignore body)
static-env))))
($define! $cond
($vau clauses env
($define! aux
($lambda ((test . body) . clauses)
($if (eval test env)
(apply (wrap $sequence) body env)
(apply (wrap $cond) clauses env))))
($if (null? clauses)
#inert
(apply aux clauses))))
($define! $if
($vau (x y z) env
($cond ((eval x env) (eval y env))
(#t (eval z env)))))
($if 0
(display "1")
(display "2")
)
(display "end")
)
Full description of $vau can be found https://klisp.org/wp-content/uploads/2023/07/jshutt.pdf and https://ftp.cs.wpi.edu/pub/techreports/pdf/05-07.pdf
I'm using a JavaScript implementation of Vau: https://github.com/tonyg/js-vau/blob/master/vau2.js
Upvotes: 0
Views: 50
Reputation: 11
I'm sorry for not spotting what the problem is in the code or implementation, but the following modified code seems to work as expected (output 2?) in the above example. However, the parentheses are actually not closing correctly, the )
for defining $cond
, as the comment below)
($begin
($define! $lambda
($vau (ptree . body) static-env
(wrap (eval (list* $vau ptree #ignore body)
static-env))))
($define! $cond
($vau clauses env
($define! aux
($lambda ((test . body) . clauses) #ignore
($if (eval test env)
(apply (wrap $sequence) body env)
(apply (wrap $cond) clauses env)))
($if (null? clauses) #inert (apply aux clauses))))
($define! $if
($vau (x y z) env
($cond ((eval x env) (eval y env))
(#t (eval z env)))))) ;; The last one is actually the closing parentheses of "$define! $cond"
($if 0
(print "1")
(print "2")
)
)
So, it may be caused by parsing error?
An error of undefined variable was reported when I used te
to evaluate script, so I replaced it with print
.
Upvotes: 1