I tried a definition of factorial in Prolog using Shen:
(defprolog fac
0 1 <--;
N R <-- (when (> N 0))
(is N1 (- N 1))
(fac N1 R1)
(is R (* N R1));
)
The equivalent definition in Prolog:
fac(0,1).
fac(N,R) :- N > 0,
N1 is N - 1,
fac(N1, R1),
R is N * R1.
In prolog I can do:
?- fac(5,120).
true ;
But in Shen this doesn't work:
(prolog? (fac 5 120))
vector-ref: not a vector: (120)
But this does give a result of 120:
(prolog? (fac 5 X) (return X))
120
What am I doing wrong?
I'm using the Shen Scheme version on Chibi Scheme.
--
http://bluishcoder.co.nz