From 6b07d7d30b60af8d8aae458f2fdbff6ff698468c Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 14 Sep 2022 09:46:31 -0700 Subject: [PATCH] Minor cleanup --- implementations/Python/joy/library.py | 2 - implementations/Python/simplejoy.py | 64 ++++++++++----------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/implementations/Python/joy/library.py b/implementations/Python/joy/library.py index 1236783..8362738 100644 --- a/implementations/Python/joy/library.py +++ b/implementations/Python/joy/library.py @@ -3,8 +3,6 @@ ALIASES = ( ('mod', ['%', 'rem', 'remainder', 'modulus']), ('getitem', ['pick', 'at']), ('xor', ['^']), - ('eh', ['?']), - ('id', [u'•']), ) # diff --git a/implementations/Python/simplejoy.py b/implementations/Python/simplejoy.py index a3d0241..33bc982 100755 --- a/implementations/Python/simplejoy.py +++ b/implementations/Python/simplejoy.py @@ -130,10 +130,10 @@ x ≡ dup i pam ≡ [i] map -nullary ≡ [stack] dinfrirst -unary ≡ nullary popd -binary ≡ unary popd -ternary ≡ binary popd + nullary ≡ [stack] dip infra first + unary ≡ nullary popd + binary ≡ unary popd + ternary ≡ binary popd ccccons ≡ ccons ccons ccons ≡ cons cons @@ -558,7 +558,9 @@ def text_to_expression(text): ''' frame = [] stack = [] + for tok in text.replace('[', ' [ ').replace(']', ' ] ').split(): + if tok == '[': stack.append(frame) frame = [] @@ -899,7 +901,7 @@ def i(stack, expr, dictionary): return stack, push_quote(quote, expr), dictionary -LOOP = Symbol('loop') +S_loop = Symbol('loop') @inscribe @@ -921,7 +923,7 @@ def loop(stack, expr, dictionary): isnt_bool(flag) isnt_stack(quote) if flag: - expr = push_quote((quote, (LOOP, ())), expr) + expr = push_quote((quote, (S_loop, ())), expr) expr = push_quote(quote, expr) return stack, expr, dictionary @@ -1349,6 +1351,21 @@ inscribe(UnaryWrapper(isnt_stack)) ''' +S_swaack = Symbol('swaack') +S_genrec = Symbol('genrec') +S_ifte = Symbol('ifte') +S_infra = Symbol('infra') +S_first = Symbol('first') +S_primrec = Symbol('primrec') +S_choice = Symbol('choice') +S_i = Symbol('i') +S_cond = Symbol('cond') +S_step = Symbol('step') +S_times = Symbol('times') + +_ifte_ = (S_infra, (S_first, (S_choice, (S_i, ())))) + + def dnd(stack, from_index, to_index): ''' Given a stack and two indices return a rearranged stack. @@ -1857,9 +1874,6 @@ def dupdip(stack, expr, dictionary): return stack, expr, dictionary -S_swaack = Symbol('swaack') - - @inscribe def infra(stack, expr, dictionary): ''' @@ -1880,10 +1894,6 @@ def infra(stack, expr, dictionary): return aggregate, expr, dictionary -S_genrec = Symbol('genrec') -S_ifte = Symbol('ifte') - - @inscribe def genrec(stack, expr, dictionary): ''' @@ -1949,10 +1959,6 @@ def genrec(stack, expr, dictionary): return stack, expr, dictionary -S_infra = Symbol('infra') -S_first = Symbol('first') - - @inscribe def map_(stack, expr, dictionary): ''' @@ -1973,9 +1979,6 @@ def map_(stack, expr, dictionary): return stack, expr, dictionary -S_primrec = Symbol('primrec') - - @inscribe def primrec(stack, expr, dictionary): ''' @@ -2021,21 +2024,10 @@ def primrec(stack, expr, dictionary): return stack, expr, dictionary -S_choice = Symbol('choice') -S_i = Symbol('i') - - @inscribe def ifte(stack, expr, dictionary): ''' If-Then-Else Combinator - :: - - ... [if] [then] [else] ifte - --------------------------------------------------- - ... [[else] [then]] [...] [if] infra select i - - ... [if] [then] [else] ifte @@ -2047,15 +2039,11 @@ def ifte(stack, expr, dictionary): if-part using infra. ''' else_, then, if_, stack = get_n_items(3, stack) - e = (S_infra, (S_first, (S_choice, (S_i, ())))) - expr = push_quote(e, expr) + expr = push_quote(_ifte_, expr) stack = (if_, (stack, (then, (else_, stack)))) return stack, expr, dictionary -S_cond = Symbol('cond') - - @inscribe def cond(stack, expr, dictionary): ''' @@ -2167,10 +2155,6 @@ def cmp_(stack, expr, dictionary): return stack, expr, dictionary -S_step = Symbol('step') -S_times = Symbol('times') - - @inscribe def step(stack, expr, dictionary): '''