OSDN Git Service

Working on bug #15
[joypy/Thun.git] / docs / 0._This_Implementation_of_Joy_in_Python.md
index cc61da8..ff42b83 100644 (file)
@@ -1,4 +1,3 @@
-
 # Joypy
 
 ## Joy in Python
@@ -49,7 +48,7 @@ import inspect
 import joy.utils.stack
 
 
-print inspect.getdoc(joy.utils.stack)
+print(inspect.getdoc(joy.utils.stack))
 ```
 
     When talking about Joy we use the terms "stack", "quote", "sequence",
@@ -59,8 +58,8 @@ print inspect.getdoc(joy.utils.stack)
     
     There is no "Stack" Python class, instead we use the  `cons list`_, a 
     venerable two-tuple recursive sequence datastructure, where the
-    empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the recursive
-    form of a stack with one or more items on it::
+    empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the
+    recursive form of a stack with one or more items on it::
     
         stack := () | (item, stack)
     
@@ -140,8 +139,8 @@ stack = ()
 for n in [1, 2, 3]:
     stack = n, stack
 
-print stack
-print list(joy.utils.stack.iter_stack(stack))
+print(stack)
+print(list(joy.utils.stack.iter_stack(stack)))
 ```
 
     (3, (2, (1, ())))
@@ -161,7 +160,7 @@ Each function is passed the stack, expression, and dictionary and returns them.
 ```python
 import joy.joy
 
-print inspect.getsource(joy.joy.joy)
+print(inspect.getsource(joy.joy.joy))
 ```
 
     def joy(stack, expression, dictionary, viewer=None):
@@ -214,7 +213,7 @@ One day I thought, What happens if you rewrite Joy to use [CSP](https://en.wikip
 ```python
 import joy.parser
 
-print inspect.getdoc(joy.parser)
+print(inspect.getdoc(joy.parser))
 ```
 
     This module exports a single function for converting text to a joy
@@ -239,7 +238,7 @@ The parser is extremely simple, the undocumented `re.Scanner` class does most of
 
 
 ```python
-print inspect.getsource(joy.parser._parse)
+print(inspect.getsource(joy.parser._parse))
 ```
 
     def _parse(tokens):
@@ -338,21 +337,20 @@ The Joy library of functions (aka commands, or "words" after Forth usage) encaps
 ```python
 import joy.library
 
-print ' '.join(sorted(joy.library.initialize()))
+print(' '.join(sorted(joy.library.initialize())))
 ```
 
-    != % & * *fraction *fraction0 + ++ - -- / // /floor < << <= <> = > >= >> ? ^ _Tree_add_Ee _Tree_delete_R0 _Tree_delete_clear_stuff _Tree_get_E abs add anamorphism and app1 app2 app3 at average b binary bool branch ccons choice clear cleave cmp codireco concat cond cons dinfrirst dip dipd dipdd disenstacken divmod down_to_zero drop dup dupd dupdd dupdip dupdipd enstacken eq first first_two flatten floor floordiv fork fourth gcd ge genrec getitem gt help i id ifte ii infer infra inscribe le least_fraction loop lshift lt make_generator map max min mod modulus mul ne neg not nullary of or over pam parse pick pm pop popd popdd popop popopd popopdd pow pred primrec product quoted range range_to_zero rem remainder remove rest reverse roll< roll> rolldown rollup round rrest rshift run second select sharing shunt size sort sqr sqrt stack step step_zero stuncons stununcons sub succ sum swaack swap swons take ternary third times truediv truthy tuck unary uncons unique unit unquoted unstack unswons void warranty while words x xor zip •
+    != % & * *fraction *fraction0 + ++ - -- / // /floor < << <= <> = > >= >> ? ^ _Tree_add_Ee _Tree_delete_R0 _Tree_delete_clear_stuff _Tree_get_E abs add anamorphism and app1 app2 app3 at average b binary bool branch ccons choice clear cleave cmp codireco concat cond cons dinfrirst dip dipd dipdd disenstacken div divmod down_to_zero drop dup dupd dupdd dupdip dupdipd enstacken eq first first_two flatten floor floordiv fork fourth gcd ge genrec getitem gt help i id ifte ii infra inscribe le least_fraction loop lshift lt make_generator map max min mod modulus mul ne neg not nullary of or over pam parse pick pm pop popd popdd popop popopd popopdd pow pred primrec product quoted range range_to_zero rem remainder remove rest reverse roll< roll> rolldown rollup round rrest rshift run second select sharing shunt size sort sqr sqrt stack step step_zero stuncons stununcons sub succ sum swaack swap swoncat swons tailrec take ternary third times truediv truthy tuck unary uncons unique unit unquoted unstack unswons void warranty while words x xor zip •
 
 
 Many of the functions are defined in Python, like `dip`:
 
 
 ```python
-print inspect.getsource(joy.library.dip)
+print(inspect.getsource(joy.library.dip))
 ```
 
     @inscribe
-    @combinator_effect(_COMB_NUMS(), a1, s1)
     @FunctionWrapper
     def dip(stack, expression, dictionary):
        '''
@@ -361,9 +359,9 @@ print inspect.getsource(joy.library.dip)
        on the rest of the stack.
        ::
     
-                        ... x [Q] dip
+                  ... x [Q] dip
                -------------------
-                                ... Q x
+                    ... Q x
     
        '''
        (quote, (x, stack)) = stack
@@ -376,45 +374,47 @@ Some functions are defined in equations in terms of other functions.  When the i
 
 
 ```python
-print joy.library.definitions
+print(joy.library.definitions)
 ```
 
-    ii == [dip] dupdip i
-    of == swap at
-    product == 1 swap [*] step
-    flatten == [] swap [concat] step
-    quoted == [unit] dip
-    unquoted == [i] dip
-    enstacken == stack [clear] dip
-    ? == dup truthy
-    disenstacken == ? [uncons ?] loop pop
-    dinfrirst == dip infra first
-    nullary == [stack] dinfrirst
-    unary == nullary popd
-    binary == nullary [popop] dip
-    ternary == unary [popop] dip
-    pam == [i] map
-    run == [] swap infra
-    sqr == dup mul
-    size == 0 swap [pop ++] step
-    fork == [i] app2
-    cleave == fork [popd] dip
-    average == [sum 1.0 *] [size] cleave /
-    gcd == 1 [tuck modulus dup 0 >] loop pop
-    least_fraction == dup [gcd] infra [div] concat map
-    *fraction == [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons
-    *fraction0 == concat [[swap] dip * [*] dip] infra
-    down_to_zero == [0 >] [dup --] while
-    range_to_zero == unit [down_to_zero] infra
-    anamorphism == [pop []] swap [dip swons] genrec
-    range == [0 <=] [1 - dup] anamorphism
-    while == swap [nullary] cons dup dipd concat loop
-    dupdipd == dup dipd
-    primrec == [i] genrec
-    step_zero == 0 roll> step
-    codireco == cons dip rest cons
-    make_generator == [codireco] ccons
-    ifte == [nullary not] dipd branch
+    ? dup truthy
+    *fraction [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons
+    *fraction0 concat [[swap] dip * [*] dip] infra
+    anamorphism [pop []] swap [dip swons] genrec
+    average [sum 1.0 *] [size] cleave /
+    binary nullary [popop] dip
+    cleave fork [popd] dip
+    codireco cons dip rest cons
+    dinfrirst dip infra first
+    unstack ? [uncons ?] loop pop
+    down_to_zero [0 >] [dup --] while
+    dupdipd dup dipd
+    enstacken stack [clear] dip
+    flatten [] swap [concat] step
+    fork [i] app2
+    gcd 1 [tuck modulus dup 0 >] loop pop
+    ifte [nullary not] dipd branch
+    ii [dip] dupdip i
+    least_fraction dup [gcd] infra [div] concat map
+    make_generator [codireco] ccons
+    nullary [stack] dinfrirst
+    of swap at
+    pam [i] map
+    tailrec [i] genrec
+    product 1 swap [*] step
+    quoted [unit] dip
+    range [0 <=] [1 - dup] anamorphism
+    range_to_zero unit [down_to_zero] infra
+    run [] swap infra
+    size 0 swap [pop ++] step
+    sqr dup mul
+    step_zero 0 roll> step
+    swoncat swap concat
+    tailrec [i] genrec
+    ternary unary [popop] dip
+    unary nullary popd
+    unquoted [i] dip
+    while swap [nullary] cons dup dipd concat loop