parent
7594fb887f
commit
08f977324f
|
|
@ -86,7 +86,7 @@ def isnt_stack(el):
|
||||||
Raise NotAListError if el isn't a stack/quote/list.
|
Raise NotAListError if el isn't a stack/quote/list.
|
||||||
'''
|
'''
|
||||||
if not isinstance(el, tuple):
|
if not isinstance(el, tuple):
|
||||||
raise NotAListError(f'Not a list {_s(el)}')
|
raise NotAListError(f'Not a list: {_s(el)}')
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
@ -828,8 +828,11 @@ def pop(stack):
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
'''
|
'''
|
||||||
_, s23 = get_n_items(1, stack)
|
try:
|
||||||
return s23
|
_, stack = stack
|
||||||
|
except ValueError:
|
||||||
|
raise StackUnderflowError('Cannot pop empty stack.') from None
|
||||||
|
return stack
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
|
@ -845,7 +848,10 @@ def rest(stack):
|
||||||
'''
|
'''
|
||||||
s0, stack = get_n_items(1, stack)
|
s0, stack = get_n_items(1, stack)
|
||||||
isnt_stack(s0)
|
isnt_stack(s0)
|
||||||
_, s1 = get_n_items(1, s0)
|
try:
|
||||||
|
_, s1 = s0
|
||||||
|
except ValueError:
|
||||||
|
raise StackUnderflowError('Cannot take rest of empty list.') from None
|
||||||
return s1, stack
|
return s1, stack
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1074,6 +1080,16 @@ Start with increment and decrement:
|
||||||
< ≡ lt
|
< ≡ lt
|
||||||
>= ≡ ge
|
>= ≡ ge
|
||||||
<= ≡ le
|
<= ≡ le
|
||||||
|
!= ≡ ne
|
||||||
|
<> ≡ ne
|
||||||
|
|
||||||
|
% ≡ mod
|
||||||
|
+ ≡ add
|
||||||
|
- ≡ sub
|
||||||
|
* ≡ mul
|
||||||
|
/ ≡ floordiv
|
||||||
|
div ≡ floordiv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
? ≡ dup bool
|
? ≡ dup bool
|
||||||
|
|
@ -1086,114 +1102,113 @@ abs ≡ dup 0 < [] [neg] branch
|
||||||
anamorphism ≡ [pop []] swap [dip swons] genrec
|
anamorphism ≡ [pop []] swap [dip swons] genrec
|
||||||
app1 ≡ grba infrst
|
app1 ≡ grba infrst
|
||||||
app2 ≡ [grba swap grba swap] dip [infrst] cons ii
|
app2 ≡ [grba swap grba swap] dip [infrst] cons ii
|
||||||
app3 3 appN
|
app3 ≡ 3 appN
|
||||||
appN [grabN] codi map disenstacken
|
appN ≡ [grabN] codi map disenstacken
|
||||||
at drop first
|
at ≡ drop first
|
||||||
average [sum] [size] cleave /
|
average ≡ [sum] [size] cleave /
|
||||||
b [i] dip i
|
b ≡ [i] dip i
|
||||||
binary unary popd
|
binary ≡ unary popd
|
||||||
ccccons ccons ccons
|
ccccons ≡ ccons ccons
|
||||||
ccons cons cons
|
ccons ≡ cons cons
|
||||||
clear [] swaack pop
|
clear ≡ [] swaack pop
|
||||||
cleave ≡ fork popdd
|
cleave ≡ fork popdd
|
||||||
clop cleave popdd
|
clop ≡ cleave popdd
|
||||||
cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
|
cmp ≡ [[>] swap] dipd [ifte] ccons [=] swons ifte
|
||||||
codi ≡ cons dip
|
codi ≡ cons dip
|
||||||
codireco codi reco
|
codireco ≡ codi reco
|
||||||
dinfrirst dip infrst
|
dinfrirst ≡ dip infrst
|
||||||
dipd ≡ [dip] codi
|
dipd ≡ [dip] codi
|
||||||
disenstacken ? [uncons ?] loop pop
|
disenstacken ≡ ? [uncons ?] loop pop
|
||||||
down_to_zero [0 >] [dup --] while
|
down_to_zero ≡ [0 >] [dup --] while
|
||||||
drop [rest] times
|
drop ≡ [rest] times
|
||||||
dupd ≡ [dup] dip
|
dupd ≡ [dup] dip
|
||||||
dupdd [dup] dipd
|
dupdd ≡ [dup] dipd
|
||||||
dupdip ≡ dupd dip
|
dupdip ≡ dupd dip
|
||||||
dupdipd ≡ dup dipd
|
dupdipd ≡ dup dipd
|
||||||
enstacken stack [clear] dip
|
enstacken ≡ stack [clear] dip
|
||||||
first uncons pop
|
first ≡ uncons pop
|
||||||
flatten <{} [concat] step
|
flatten ≡ <{} [concat] step
|
||||||
fork ≡ [i] app2
|
fork ≡ [i] app2
|
||||||
fourth rest third
|
fourth ≡ rest third
|
||||||
gcd true [tuck mod dup 0 >] loop pop
|
gcd ≡ true [tuck mod dup 0 >] loop pop
|
||||||
genrec [[genrec] ccccons] nullary swons concat ifte
|
genrec ≡ [[genrec] ccccons] nullary swons concat ifte
|
||||||
grabN <{} [cons] times
|
grabN ≡ <{} [cons] times
|
||||||
grba ≡ [stack popd] dip
|
grba ≡ [stack popd] dip
|
||||||
hypot [sqr] ii + sqrt
|
hypot [sqr] ii + sqrt
|
||||||
ifte [nullary] dipd swap branch
|
ifte ≡ [nullary] dipd swap branch
|
||||||
ii ≡ [dip] dupdip i
|
ii ≡ [dip] dupdip i
|
||||||
infra ≡ swons swaack [i] dip swaack
|
infra ≡ swons swaack [i] dip swaack
|
||||||
infrst ≡ infra first
|
infrst ≡ infra first
|
||||||
make_generator [codireco] ccons
|
make_generator ≡ [codireco] ccons
|
||||||
manual ≡ [] words [help] step pop
|
manual ≡ [] words [help] step pop
|
||||||
mod %
|
neg ≡ 0 swap -
|
||||||
neg 0 swap -
|
not ≡ [true] [false] branch
|
||||||
not [true] [false] branch
|
nulco ≡ [nullary] cons
|
||||||
nulco [nullary] cons
|
nullary ≡ [stack] dinfrirst
|
||||||
nullary [stack] dinfrirst
|
of ≡ swap at
|
||||||
of swap at
|
pam ≡ [i] map
|
||||||
pam [i] map
|
pm ≡ [+] [-] clop
|
||||||
pm [+] [-] clop
|
|
||||||
popd ≡ [pop] dip
|
popd ≡ [pop] dip
|
||||||
popdd ≡ [pop] dipd
|
popdd ≡ [pop] dipd
|
||||||
popop ≡ pop pop
|
popop ≡ pop pop
|
||||||
popopop ≡ pop popop
|
popopop ≡ pop popop
|
||||||
popopd [popop] dip
|
popopd ≡ [popop] dip
|
||||||
popopdd [popop] dipd
|
popopdd ≡ [popop] dipd
|
||||||
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
|
||||||
reco rest cons
|
reco ≡ rest cons
|
||||||
rest uncons popd
|
rest ≡ uncons popd
|
||||||
reverse <{} shunt
|
reverse ≡ <{} shunt
|
||||||
roll> ≡ swap swapd
|
roll> ≡ swap swapd
|
||||||
roll< ≡ swapd swap
|
roll< ≡ swapd swap
|
||||||
rollup roll>
|
rollup ≡ roll>
|
||||||
rolldown roll<
|
rolldown roll<
|
||||||
rrest rest rest
|
rrest ≡ rest rest
|
||||||
run <{} infra
|
run ≡ <{} infra
|
||||||
second rest first
|
second ≡ rest first
|
||||||
shift uncons [swons] dip
|
shift ≡ uncons [swons] dip
|
||||||
shunt [swons] step
|
shunt ≡ [swons] step
|
||||||
size [pop ++] step_zero
|
size ≡ [pop ++] step_zero
|
||||||
spiral_next [[[abs] ii <=] [[<>] [pop !-] ||] &&] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
|
spiral_next ≡ [[[abs] ii <=] [[<>] [pop !-] ||] &&] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
|
||||||
split_at [drop] [take] clop
|
split_at ≡ [drop] [take] clop
|
||||||
split_list [take reverse] [drop] clop
|
split_list ≡ [take reverse] [drop] clop
|
||||||
sqr dup *
|
sqr ≡ dup *
|
||||||
stackd [stack] dip
|
stackd ≡ [stack] dip
|
||||||
step_zero 0 roll> step
|
step_zero ≡ 0 roll> step
|
||||||
stuncons stack uncons
|
stuncons ≡ stack uncons
|
||||||
sum [+] step_zero
|
sum ≡ [+] step_zero
|
||||||
swapd ≡ [swap] dip
|
swapd ≡ [swap] dip
|
||||||
swons ≡ swap cons
|
swons ≡ swap cons
|
||||||
swoncat swap concat
|
swoncat ≡ swap concat
|
||||||
sqr dup mul
|
sqr ≡ dup mul
|
||||||
tailrec [i] genrec
|
tailrec ≡ [i] genrec
|
||||||
take <<{} [shift] times pop
|
take ≡ <<{} [shift] times pop
|
||||||
ternary binary popd
|
ternary ≡ binary popd
|
||||||
third rest second
|
third ≡ rest second
|
||||||
tuck dup swapd
|
tuck ≡ dup swapd
|
||||||
unary nullary popd
|
unary ≡ nullary popd
|
||||||
uncons ≡ [first] [rest] cleave
|
uncons ≡ [first] [rest] cleave
|
||||||
unit ≡ [] cons
|
unit ≡ [] cons
|
||||||
unquoted [i] dip
|
unquoted ≡ [i] dip
|
||||||
unswons uncons swap
|
unswons ≡ uncons swap
|
||||||
while swap nulco dupdipd concat loop
|
while ≡ swap nulco dupdipd concat loop
|
||||||
x ≡ dup i
|
x ≡ dup i
|
||||||
step ≡ [_step0] x
|
step ≡ [_step0] x
|
||||||
_step0 ≡ _step1 [popopop] [_stept] branch
|
_step0 ≡ _step1 [popopop] [_stept] branch
|
||||||
_step1 ≡ [?] dipd roll<
|
_step1 ≡ [?] dipd roll<
|
||||||
_stept ≡ [uncons] dipd [dupdipd] dip x
|
_stept ≡ [uncons] dipd [dupdipd] dip x
|
||||||
times [_times0] x
|
times ≡ [_times0] x
|
||||||
_times0 _times1 [popopop] [_timest] branch
|
_times0 ≡ _times1 [popopop] [_timest] branch
|
||||||
_times1 [dup 0 >] dipd roll<
|
_times1 ≡ [dup 0 >] dipd roll<
|
||||||
_timest [[--] dip dupdipd] dip x
|
_timest ≡ [[--] dip dupdipd] dip x
|
||||||
map [_map0] cons [[] [_map?] [_mape]] dip tailrec
|
map ≡ [_map0] cons [[] [_map?] [_mape]] dip tailrec
|
||||||
_map? pop bool not
|
_map? ≡ pop bool not
|
||||||
_mape popd reverse
|
_mape ≡ popd reverse
|
||||||
_map0 [_map1] dipd _map2
|
_map0 ≡ [_map1] dipd _map2
|
||||||
_map1 stackd shift
|
_map1 ≡ stackd shift
|
||||||
_map2 [infrst] cons dipd roll< swons
|
_map2 ≡ [infrst] cons dipd roll< swons
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue