Working on README, put defs in joy.py
I'm on an Ubuntu system right now and the split command doesn't have the '-p' switch. :( I wasn't happy with that janky solution anyway.
This commit is contained in:
parent
975924f632
commit
ced691279a
|
|
@ -59,10 +59,9 @@ For more information see [Square Spiral Example Joy Code](/notebooks/Square_Spir
|
||||||
It might seem unreadable but with familiarity it becomes as legible as any other notation.
|
It might seem unreadable but with familiarity it becomes as legible as any other notation.
|
||||||
|
|
||||||
|
|
||||||
|
## Project Hosted on [SourceHut](https://git.sr.ht/~sforman/Thun)
|
||||||
|
|
||||||
## Project Hosted on [OSDN](https://osdn.net/projects/joypy/)
|
* [Source Repository](https://git.sr.ht/~sforman/Thun)
|
||||||
|
|
||||||
* [Source Repository](https://osdn.net/projects/joypy/scm/git/Thun/)
|
|
||||||
([mirror](https://github.com/calroc/Thun))
|
([mirror](https://github.com/calroc/Thun))
|
||||||
* [Bug tracker](https://todo.sr.ht/~sforman/thun-der)
|
* [Bug tracker](https://todo.sr.ht/~sforman/thun-der)
|
||||||
([old tracker](https://osdn.net/projects/joypy/ticket/))
|
([old tracker](https://osdn.net/projects/joypy/ticket/))
|
||||||
|
|
@ -159,7 +158,6 @@ Joy is [stack-based](https://en.wikipedia.org/wiki/Stack-oriented_programming_la
|
||||||
There is a single main __stack__ that holds data items, which can be integers, bools,
|
There is a single main __stack__ that holds data items, which can be integers, bools,
|
||||||
symbols (names), or sequences of data items enclosed in square brackets (`[` or `]`).
|
symbols (names), or sequences of data items enclosed in square brackets (`[` or `]`).
|
||||||
|
|
||||||
23 dup [21 18 add] true false [1 [2 [3]]] cons
|
|
||||||
|
|
||||||
### Expression
|
### Expression
|
||||||
|
|
||||||
|
|
@ -189,7 +187,7 @@ All control flow works by
|
||||||
__Combinators__ (see below) alter control flow by prepending quoted programs to the pending
|
__Combinators__ (see below) alter control flow by prepending quoted programs to the pending
|
||||||
expression (aka "continuation".)
|
expression (aka "continuation".)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Stack / Quote / List / Sequence
|
## Stack / Quote / List / Sequence
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
# split on Ubuntu doesn't have '-p' option! Wah!
|
||||||
joy: joy.py ../defs.txt
|
joy: joy.py ../defs.txt
|
||||||
split -p \'\'\'\.splitlines\(\) joy.py joy.py.
|
split -p \'\'\'\.splitlines\(\) joy.py joy.py.
|
||||||
cat joy.py.aa ../defs.txt joy.py.ab > joy
|
cat joy.py.aa ../defs.txt joy.py.ab > joy
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,137 @@ import operator
|
||||||
|
|
||||||
|
|
||||||
DEFS = '''\
|
DEFS = '''\
|
||||||
'''.splitlines()
|
eq [false] [true] [false] cmp
|
||||||
|
gt [true] [false] [false] cmp
|
||||||
|
lt [false] [false] [true] cmp
|
||||||
|
neq [true] [false] [true] cmp
|
||||||
|
le [false] [true] [true] cmp
|
||||||
|
ge [true] [true] [false] cmp
|
||||||
|
-- 1 -
|
||||||
|
? dup bool
|
||||||
|
and nulco [nullary [false]] dip branch
|
||||||
|
++ 1 +
|
||||||
|
or nulco [nullary] dip [true] branch
|
||||||
|
!- 0 >=
|
||||||
|
<{} [] swap
|
||||||
|
<<{} [] rollup
|
||||||
|
abs dup 0 < [] [neg] branch
|
||||||
|
anamorphism [pop []] swap [dip swons] genrec
|
||||||
|
app1 grba infrst
|
||||||
|
app2 [grba swap grba swap] dip [infrst] cons ii
|
||||||
|
app3 3 appN
|
||||||
|
appN [grabN] codi map reverse disenstacken
|
||||||
|
at drop first
|
||||||
|
average [sum] [size] cleave /
|
||||||
|
b [i] dip i
|
||||||
|
binary unary popd
|
||||||
|
ccccons ccons ccons
|
||||||
|
ccons cons cons
|
||||||
|
clear [] swaack pop
|
||||||
|
cleave fork popdd
|
||||||
|
clop cleave popdd
|
||||||
|
cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
|
||||||
|
codi cons dip
|
||||||
|
codireco codi reco
|
||||||
|
dinfrirst dip infrst
|
||||||
|
dipd [dip] codi
|
||||||
|
disenstacken swaack pop
|
||||||
|
divmod [/] [%] clop
|
||||||
|
down_to_zero [0 >] [dup --] while
|
||||||
|
drop [rest] times
|
||||||
|
dupd [dup] dip
|
||||||
|
dupdd [dup] dipd
|
||||||
|
dupdip dupd dip
|
||||||
|
dupdipd dup dipd
|
||||||
|
enstacken stack [clear] dip
|
||||||
|
first uncons pop
|
||||||
|
flatten <{} [concat] step
|
||||||
|
fork [i] app2
|
||||||
|
fourth rest third
|
||||||
|
gcd true [tuck mod dup 0 >] loop pop
|
||||||
|
genrec [[genrec] ccccons] nullary swons concat ifte
|
||||||
|
grabN <{} [cons] times
|
||||||
|
grba [stack popd] dip
|
||||||
|
hypot [sqr] ii + sqrt
|
||||||
|
ifte [nullary] dipd swap branch
|
||||||
|
ii [dip] dupdip i
|
||||||
|
infra swons swaack [i] dip swaack
|
||||||
|
infrst infra first
|
||||||
|
make_generator [codireco] ccons
|
||||||
|
mod %
|
||||||
|
neg 0 swap -
|
||||||
|
not [true] [false] branch
|
||||||
|
nulco [nullary] cons
|
||||||
|
null [] concat bool not
|
||||||
|
nullary [stack] dinfrirst
|
||||||
|
of swap at
|
||||||
|
pam [i] map
|
||||||
|
pm [+] [-] clop
|
||||||
|
popd [pop] dip
|
||||||
|
popdd [pop] dipd
|
||||||
|
popop pop pop
|
||||||
|
popopop pop popop
|
||||||
|
popopd [popop] dip
|
||||||
|
popopdd [popop] dipd
|
||||||
|
product 1 swap [*] step
|
||||||
|
quoted [unit] dip
|
||||||
|
range [0 <=] [-- dup] anamorphism
|
||||||
|
range_to_zero unit [down_to_zero] infra
|
||||||
|
reco rest cons
|
||||||
|
rest uncons popd
|
||||||
|
reverse <{} shunt
|
||||||
|
roll> swap swapd
|
||||||
|
roll< swapd swap
|
||||||
|
rollup roll>
|
||||||
|
rolldown roll<
|
||||||
|
rrest rest rest
|
||||||
|
run <{} infra
|
||||||
|
second rest first
|
||||||
|
shift uncons [swons] dip
|
||||||
|
shunt [swons] step
|
||||||
|
size [pop ++] step_zero
|
||||||
|
small dup null [rest null] [pop true] branch
|
||||||
|
spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
|
||||||
|
split_at [drop] [take] clop
|
||||||
|
split_list [take reverse] [drop] clop
|
||||||
|
sqr dup mul
|
||||||
|
stackd [stack] dip
|
||||||
|
step_zero 0 roll> step
|
||||||
|
stuncons stack uncons
|
||||||
|
sum [+] step_zero
|
||||||
|
swapd [swap] dip
|
||||||
|
swons swap cons
|
||||||
|
swoncat swap concat
|
||||||
|
tailrec [i] genrec
|
||||||
|
take <<{} [shift] times pop
|
||||||
|
ternary binary popd
|
||||||
|
third rest second
|
||||||
|
tuck dup swapd
|
||||||
|
unary nullary popd
|
||||||
|
uncons [first] [rest] cleave
|
||||||
|
unit [] cons
|
||||||
|
unquoted [i] dip
|
||||||
|
unstack [[] swaack] dip swoncat swaack pop
|
||||||
|
unswons uncons swap
|
||||||
|
while swap nulco dupdipd concat loop
|
||||||
|
x dup i
|
||||||
|
step [_step0] x
|
||||||
|
_step0 _step1 [popopop] [_stept] branch
|
||||||
|
_step1 [?] dipd roll<
|
||||||
|
_stept [uncons] dipd [dupdipd] dip x
|
||||||
|
times [_times0] x
|
||||||
|
_times0 _times1 [popopop] [_timest] branch
|
||||||
|
_times1 [dup 0 >] dipd roll<
|
||||||
|
_timest [[--] dip dupdipd] dip x
|
||||||
|
map [_map0] cons [[] [_map?] [_mape]] dip tailrec
|
||||||
|
_map? pop bool not
|
||||||
|
_mape popd reverse
|
||||||
|
_map0 [_map1] dipd _map2
|
||||||
|
_map1 stackd shift
|
||||||
|
_map2 [infrst] cons dipd roll< swons
|
||||||
|
_\/_ [not not] [not] branch
|
||||||
|
/\ [not not] ii [pop false] [] branch
|
||||||
|
\/ [not not] ii [] [pop true] branch'''.splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue