Move all definitions to defs.txt.
This commit is contained in:
parent
ee395e91f1
commit
9ebc64541a
|
|
@ -1,31 +1,61 @@
|
||||||
++ == 1 +
|
++ == 1 +
|
||||||
anamorphism == [pop []] swap [dip swons] genrec
|
anamorphism == [pop []] swap [dip swons] genrec
|
||||||
|
app1 == grba infrst
|
||||||
|
app2 == [grba swap grba swap] dip [infrst] cons ii
|
||||||
|
at == drop first
|
||||||
average == [sum 1.0 *] [size] cleave /
|
average == [sum 1.0 *] [size] cleave /
|
||||||
|
b == [i] dip i
|
||||||
binary == unary popd
|
binary == unary popd
|
||||||
|
ccons == cons cons
|
||||||
cleave == fork [popd] dip
|
cleave == fork [popd] dip
|
||||||
codireco == cons dip rest cons
|
codireco == cons dip rest cons
|
||||||
dinfrirst == dip infra first
|
dinfrirst == dip infra first
|
||||||
disenstacken == ? [uncons ?] loop pop
|
disenstacken == ? [uncons ?] loop pop
|
||||||
down_to_zero == [0 >] [dup --] while
|
down_to_zero == [0 >] [dup --] while
|
||||||
|
drop == [rest] times
|
||||||
|
dupd == [dup] dip
|
||||||
|
dupdd == [dup] dipd
|
||||||
dupdipd == dup dipd
|
dupdipd == dup dipd
|
||||||
enstacken == stack [clear] dip
|
enstacken == stack [clear] dip
|
||||||
flatten == [] swap [concat] step
|
flatten == [] swap [concat] step
|
||||||
fork == [i] app2
|
fork == [i] app2
|
||||||
|
fourth == rest third
|
||||||
gcd == 1 [tuck modulus dup 0 >] loop pop
|
gcd == 1 [tuck modulus dup 0 >] loop pop
|
||||||
|
grba == [stack popd] dip
|
||||||
|
ifte == [nullary] dipd swap branch
|
||||||
|
ii == [dip] dupdip i
|
||||||
|
infra == swons swaack [i] dip swaack
|
||||||
|
infrst == infra first
|
||||||
make_generator == [codireco] ccons
|
make_generator == [codireco] ccons
|
||||||
|
neg == 0 swap -
|
||||||
|
nullary == stack popd [i] infrst
|
||||||
of == swap at
|
of == swap at
|
||||||
pam == [i] map
|
pam == [i] map
|
||||||
|
pm == [+] [-] cleave popdd
|
||||||
|
popd == [pop] dip
|
||||||
|
popdd == [pop] dipd
|
||||||
|
popop == pop pop
|
||||||
|
popopd == [popop] dip
|
||||||
|
popopdd == [popop] dipd
|
||||||
primrec == [i] genrec
|
primrec == [i] genrec
|
||||||
product == 1 swap [*] step
|
product == 1 swap [*] step
|
||||||
|
product == 1 swap [*] step
|
||||||
quoted == [unit] dip
|
quoted == [unit] dip
|
||||||
range == [0 <=] [1 - dup] anamorphism
|
range == [0 <=] [1 - dup] anamorphism
|
||||||
range_to_zero == unit [down_to_zero] infra
|
range_to_zero == unit [down_to_zero] infra
|
||||||
|
rrest == rest rest
|
||||||
run == [] swap infra
|
run == [] swap infra
|
||||||
|
second == rest first
|
||||||
size == 0 swap [pop ++] step
|
size == 0 swap [pop ++] step
|
||||||
sqr == dup *
|
sqr == dup *
|
||||||
step_zero == 0 roll> step
|
step_zero == 0 roll> step
|
||||||
|
sum == 0 swap [+] step
|
||||||
|
swons == swap cons
|
||||||
ternary == binary popd
|
ternary == binary popd
|
||||||
|
third == rest second
|
||||||
unary == nullary popd
|
unary == nullary popd
|
||||||
|
unit == [] cons
|
||||||
unquoted == [i] dip
|
unquoted == [i] dip
|
||||||
|
unswons == uncons swap
|
||||||
while == swap [nullary] cons dup dipd concat loop
|
while == swap [nullary] cons dup dipd concat loop
|
||||||
x == dup i
|
x == dup i
|
||||||
63
thun/thun.pl
63
thun/thun.pl
|
|
@ -51,10 +51,6 @@ chars([Ch]) --> char(Ch).
|
||||||
|
|
||||||
char(Ch) --> [Ch], {Ch \== 91, Ch \== 93, code_type(Ch, graph)}.
|
char(Ch) --> [Ch], {Ch \== 91, Ch \== 93, code_type(Ch, graph)}.
|
||||||
|
|
||||||
joy_def(Def ≡ Body) --> symbol(Def), blanks, "==", joy_parse(Body).
|
|
||||||
|
|
||||||
joy_defs([Def|Defs]) --> blanks, joy_def(Def), blanks, joy_defs(Defs).
|
|
||||||
joy_defs([]) --> [].
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Interpreter
|
Interpreter
|
||||||
|
|
@ -145,36 +141,23 @@ r_truth(1, true).
|
||||||
/*
|
/*
|
||||||
Definitions
|
Definitions
|
||||||
*/
|
*/
|
||||||
app1 ≡ [grba, infrst].
|
|
||||||
app2 ≡ [[grba, swap, grba, swap], dip, [infrst], cons, ii].
|
joy_def(Def ≡ Body) --> symbol(Def), blanks, "==", joy_parse(Body).
|
||||||
at ≡ [drop, first].
|
|
||||||
b ≡ [[i], dip, i].
|
joy_defs([Def|Defs]) --> blanks, joy_def(Def), blanks, joy_defs(Defs).
|
||||||
ccons ≡ [cons, cons].
|
joy_defs([]) --> [].
|
||||||
drop ≡ [[rest], times].
|
|
||||||
dupd ≡ [[dup], dip].
|
read_defs(DefsFile, Defs) :-
|
||||||
dupdd ≡ [[dup], dipd].
|
read_file_to_codes(DefsFile, Codes, []),
|
||||||
fourth ≡ [rest, third].
|
phrase(joy_defs(Defs), Codes).
|
||||||
grba ≡ [[stack, popd], dip].
|
|
||||||
ifte ≡ [[nullary], dipd, swap, branch].
|
assert_defs(DefsFile) :-
|
||||||
ii ≡ [[dip], dupdip, i].
|
read_defs(DefsFile, Defs),
|
||||||
infra ≡ [swons, swaack, [i], dip, swaack].
|
forall(member(Def, Defs), assert_def(Def)).
|
||||||
infrst ≡ [infra, first].
|
|
||||||
neg ≡ [0, swap, -].
|
assert_def(Def≡Body) :- retractall(Def≡_), assertz(Def≡Body).
|
||||||
nullary ≡ [stack, popd, [i], infrst].
|
|
||||||
pm ≡ [[+], [-], cleave, popdd].
|
:- assert_defs("defs.txt").
|
||||||
popd ≡ [[pop], dip].
|
|
||||||
popdd ≡ [[pop], dipd].
|
|
||||||
popop ≡ [pop, pop].
|
|
||||||
popopd ≡ [[popop], dip].
|
|
||||||
popopdd ≡ [[popop], dipd].
|
|
||||||
product ≡ [1, swap, [*], step].
|
|
||||||
rrest ≡ [rest, rest].
|
|
||||||
second ≡ [rest, first].
|
|
||||||
sum ≡ [0, swap, [+], step].
|
|
||||||
swons ≡ [swap, cons].
|
|
||||||
third ≡ [rest, second].
|
|
||||||
unit ≡ [[], cons].
|
|
||||||
unswons ≡ [uncons, swap].
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -228,15 +211,3 @@ contracto, [Def] --> {Def ≡ Body}, Body.
|
||||||
|
|
||||||
% phrase(expando, ExprIn, ExprOut).
|
% phrase(expando, ExprIn, ExprOut).
|
||||||
|
|
||||||
|
|
||||||
read_defs(DefsFile, Defs) :-
|
|
||||||
read_file_to_codes(DefsFile, Codes, []),
|
|
||||||
phrase(joy_defs(Defs), Codes).
|
|
||||||
|
|
||||||
assert_defs(DefsFile) :-
|
|
||||||
read_defs(DefsFile, Defs),
|
|
||||||
forall(member(Def, Defs), assert_def(Def)).
|
|
||||||
|
|
||||||
assert_def(Def≡Body) :- retractall(Def≡_), assertz(Def≡Body).
|
|
||||||
|
|
||||||
:- assert_defs("defs.txt").
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue