Bring in the Prolog impl.

This commit is contained in:
Simon Forman
2022-01-15 17:23:11 -08:00
parent 564417c985
commit 839b376d73
60 changed files with 19083 additions and 0 deletions
@@ -0,0 +1,21 @@
?- phrase(joy_parse(Expression), `truedat`).
Expression = [bool(true), symbol(dat)] .
Oops!
I knew about:
?- phrase(joy_parse(Expression), `23dat`).
Expression = [int(23), symbol(dat)] .
should probably fix it too
still want:
?- phrase(joy_parse(Expression), `[2[3]]`).
Expression = [list([int(2), list([int(3)])])] .
?- phrase(joy_parse(Expression), `[true[false]]`).
Expression = [list([bool(true), list([bool(false)])])] .
...to work. That is, you shouldn't need spaces around '[' and ']'.
@@ -0,0 +1,2 @@
disenstacken is in the defs.txt
it needs to be updated to reflect the unstack<->disenstacken switch.
@@ -0,0 +1,132 @@
Each function should have full documentation including examples,
deriviation, history, background, crosslinks (like "Pattern Language"),
rationale, details of implementation, etc.
Still to do:
%
&&
*
+
++
-
--
/
/%
<
<=
<>
=
>
>=
?
abs
anamorphism
and
app2
app3
appN
at
average
bool
branch
clear
cleave
clop
codireco
concat
dinfrirst
dip
dipd
disenstacken
down_to_zero
drop
dup
dupd
dupdd
dupdip
dupdipd
empty?
enstacken
first
flatten
fork
fourth
gcd
genrec
grabN
grba
hypot
ifte
ii
infrst
list?
loop
make_generator
map
neg
not
of
one-or-more?
or
over
pam
pm
pop
popd
popdd
popop
popopd
popopdd
primrec
product
quoted
range
range_to_zero
rest
reverse
rolldown
rollup
rrest
run
second
shift
shunt
size
spiral_next
split_at
sqr
stack
step
step_zero
sum
swaack
swap
swons
take
third
times
tuck
unit
unquoted
unswons
while
words
||
-------
Done:
!-
app1
b
binary
ccons
cons
i
infra
nullary
ternary
unary
uncons
x
@@ -0,0 +1,18 @@
?- sjc(add_twice, `[36 *] ii`).
func(add_twice, [int(B), int(D)|A], [int(C), int(E)|A]) :-
maplist(call,
[clpfd:(36*B#=C), clpfd:(36*D#=E)]).
true ;
func(add_twice, [symbol(swap), int(D), int(B)|A], [int(C), int(E)|A]) :-
maplist(call,
[clpfd:(36*B#=C), clpfd:(36*D#=E)]).
true ;
func(add_twice, [symbol(dup), int(D)|A], [int(C), int(B)|A]) :-
maplist(call,
[clpfd:(36*B#=C), clpfd:(36*D#=B)]).
true ;
func(add_twice, [symbol(pop), int(D), int(B)|A], [int(C)|A]) :-
maplist(call,
[clpfd:(36*B#=C), clpfd:(36*D#=_)]).
true .
@@ -0,0 +1,13 @@
What about a kind of interpolation literal?
{} -> []
\n -> nth stack item.
So:
a b c { \0 { \2 { \0 \1 }}}
---------------------------------
[ c [ a [ c b ]]]
And so on...