diff --git a/docs/html/FuncRef.html b/docs/html/FuncRef.html index c4a346f..c21e7a3 100644 --- a/docs/html/FuncRef.html +++ b/docs/html/FuncRef.html @@ -1,4 +1,4 @@ -Thun Function Reference

Thun Function Reference

Home

Version -10.0.0

Each function, combinator, or definition should be documented here.


!-

Not negative.

+Thun Function Reference

Thun Function Reference

Home

Version -10.0.0

Each function, combinator, or definition should be documented here.


!-

Not negative.

    n !-
 ----------- n < 0
    false
@@ -8,13 +8,13 @@
 ---------- n >= 0
    true
 

Definition

0 >=

Discussion

Return a Boolean value indicating if a number is greater than or equal to -zero.


!=

built-in

See neq.


%

built-in

See mod.


*

built-in

See mul.


+

built-in

See add.


++

See succ.

Definition

1 +

-

built-in

See sub.


--

See pred.

Definition

1 -

/

built-in

See div.


/\

Binary Boolean and.

Definition


<

built-in

See lt.


<<

built-in

See lshift.

Definition


<<{}

   ... b a <{}
+zero.


!=

built-in

See neq.


%

built-in

See mod.


*

built-in

See mul.


+

built-in

See add.


++

See succ.

Definition

1 +

-

built-in

See sub.


--

See pred.

Definition

1 -

/

built-in

See div.


/\

Binary Boolean and.

Definition


<

built-in

See lt.


<<

built-in

See lshift.

Definition


<<{}

   ... b a <{}
 -----------------
    ... [] b a
 

Definition

Discussion

Tuck an empty list just under the first two items on the stack.


<=

built-in

See le.


<>

built-in

See neq.


<{}

   ... a <{}
 ----------------
    ... [] a
-

Definition

[] swap

Discussion

Tuck an empty list just under the first item on the stack.


=

built-in

See eq.


>

built-in

See gt.


>=

built-in

See ge.


>>

built-in

See rshift.

Definition


?

Is the item on the top of the stack "truthy"?

Definition

Discussion

You often want to test the truth value of an item on the stack without +

Definition

[] swap

Discussion

Tuck an empty list just under the first item on the stack.


=

built-in

See eq.


>

built-in

See gt.


>=

built-in

See ge.


>>

built-in

See rshift.

Definition


?

Is the item on the top of the stack "truthy"?

Definition

Discussion

You often want to test the truth value of an item on the stack without consuming the item.


\/

Binary Boolean or.

Definition


abs

Take an integer from the stack and replace it with its absolute value.

Definition

dup 0 < [] [neg] branch

add

built-in

Take two integers from the stack and replace them with their sum.


anamorphism

combinator

Build a list of values from a generator program G and a stopping predicate P.

           [P] [G] anamorphism
@@ -113,7 +113,7 @@ empty list is false and all other lists are true.

< T

Discussion

This is one of the fundamental operations (although it can be defined in terms of [choice] as above). The more common "if..then..else" construct -[ifte] adds a predicate function that is evaluated [nullary].


ccccons

   a b c d [...] ccccons
+[ifte] adds a predicate function that is evaluated [nullary].


ccccons

   a b c d [...] ccccons
 ---------------------------
        [a b c d ...]
 
@@ -184,7 +184,7 @@ as well as
   [a b c] [d e f] concat
 ----------------------------
        [a b c d e f]
-

cond

combinator

This combinator works like a case statement. It expects a single quote +


cond

combinator

This combinator works like a case statement. It expects a single quote on the stack that must contain zero or more condition quotes and a default quote. Each condition quote should contain a quoted predicate followed by the function expression to run if that predicate returns @@ -206,7 +206,7 @@ expressions, e.g.: ------------------ [a ...]

Discussion

Cons is a venerable old function from Lisp. -Its inverse operation is [uncons].


dinfrirst

combinator

Specialist function (that means I forgot what it does and why.)

Definition


dip

combinator built-in

The dip combinator expects a quoted program on the stack and below it +Its inverse operation is [uncons].


dinfrirst

combinator

Specialist function (that means I forgot what it does and why.)

Definition


dip

combinator built-in

The dip combinator expects a quoted program on the stack and below it some item, it hoists the item into the expression and runs the program on the rest of the stack.

   ... x [Q] . dip
@@ -228,7 +228,7 @@ pending expression (not counting modifications to the dictionary.)

... y x [Q] . dipd ------------------------- ... . Q y x -

Definition

[dip] codi

Discussion

See [dip].


dipdd

combinator

Like [dip] but expects three items. :

+

Definition

Discussion

See [dip].


dipdd

combinator

Like [dip] but expects three items. :

   ... z y x [Q] . dipdd
 -----------------------------
              ... . Q z y x
@@ -264,7 +264,7 @@ items removed off the top.

   a dup
 -----------
     a a
-

dupd

[dup] the second item down on the stack.

+

dupd

[dup] the second item down on the stack.

   a b dupd
 --------------
     a a b
@@ -288,7 +288,8 @@ a F a
 
   a [F] dupdipd
 -------------------
       F a [F]
-

Definition


enstacken

Put the stack onto the stack replacing the contents of the stack.

+

Definition


empty?

Expects a list on the stack and pushes true if it's empty and false otherwise. +It doesn't consume the list.

Definition


enstacken

Put the stack onto the stack replacing the contents of the stack.

   ... a b c enstacken
 -------------------------
        [c b a ...]
@@ -303,7 +304,7 @@ them with a Boolean value.

   [a ...]
 --------------
       a
-

Definition


first_two

Replace a list with its first two items.

+

Definition


first_two

Replace a list with its first two items.

   [a b ...] first_two
 -------------------------
            a b
@@ -313,7 +314,7 @@ them with a Boolean value.

------------------------------------- [1 2 3 [4] 5 6 7]

Definition

Discussion

Note that only one "level" of lists is flattened. In the example above -[4] is not unquoted.


fork

combinator

Run two quoted programs in parallel and replace them with their results.

+[4] is not unquoted.


fork

combinator

Run two quoted programs in parallel and replace them with their results.

   ... [F] [G] fork
 ----------------------
        ... f g
@@ -374,7 +375,7 @@ nth position in the quote counting from 0.

c

Definition

Discussion

If the number isn't a valid index into the quote getitem will cause some sort of problem (the exact nature of which is -implementation-dependant.)


grabN

Expect a number on the top of the stack and [cons] that many items from under it onto a new list.

+implementation-dependant.)


grabN

Expect a number on the top of the stack and [cons] that many items from under it onto a new list.

Example

   a b c d e 3 grabN
 -----------------------
@@ -390,21 +391,16 @@ It's part of the [app2] definition.

Definition

[true] [false] [false] cmp

help

Accepts a quoted symbol on the top of the stack and prints its -documentation.

-
   [foo] help
-----------------
-

Discussion

Technically this is equivalent to pop, but it will only work if the -item on the top of the stack is a quoted symbol.


i

combinator built-in

Append a quoted expression onto the pending expression.

+

Definition

[true] [false] [false] cmp

i

combinator built-in

Append a quoted expression onto the pending expression.

   [Q] . i
 -------------
        . Q
 

Discussion

This is a fundamental combinator. It is used in all kinds of places. For -example, the [x] combinator can be defined as dup i.


id

The identity function.

Discussion

Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.


ifte

combinator

If-Then-Else combinator, a common and convenient specialization of [branch].

+example, the [x] combinator can be defined as dup i.


ifte

combinator

If-Then-Else combinator, a common and convenient specialization of [branch].

        [if] [then] [else] ifte
 ---------------------------------------
    [if] nullary [else] [then] branch
-

Definition


ii

combinator

Take a quoted program from the stack and run it twice, first under the +

Definition


ii

combinator

Take a quoted program from the stack and run it twice, first under the top item, then again with the top item.

... a [Q] ii
 ------------------
@@ -427,7 +423,7 @@ top item, then again with the top item.

1 9 1 2 3 4 [+] app2 ---------------------- - 1 2 5 6


infra

combinator

Accept a quoted program and a list on the stack and run the program with + 1 2 5 6


infra

combinator

Accept a quoted program and a list on the stack and run the program with the list as its stack. Does not affect the stack (below the list.)

   ... x y z [a b c] [Q] infra
 ---------------------------------
@@ -515,12 +511,12 @@ parallelism combinator due to the "pure" nature of the language.

   [1 2 3 4] max
 -------------------
          4
-

min

Given a list find the minimum.

+

max-of-two

Expects two integers on the stack and removes the lesser of them, if they are equal just remove one.

Definition

[>] [pop] [popd] ifte

min

Given a list find the minimum.

Example

   [1 2 3 4] min
 -------------------
          1
-

mod

Return the remainder of a divided by b.

+

Definition


min-of-two

Expects two integers on the stack and removes the greater of them, if they are equal just remove one.

Definition

[<] [pop] [popd] ifte

mod

Return the remainder of a divided by b.

   a b mod
 -------------
     (a%b)
@@ -552,7 +548,7 @@ stack, replacing them with a Boolean value.

[[F] nullary]

Definition

Discussion

Helper function for [or] and [and].


null

True if the item on the top of the stack is an empty list, false if it's a list but not empty, -and an error if it's not a list.

Definition


nullary

combinator

Run a quoted program without using any stack values and leave the first +and an error if it's not a list.

Definition


nullary

combinator

Run a quoted program without using any stack values and leave the first item of the result on the stack.

   ... [P] nullary
 ---------------------
@@ -614,11 +610,11 @@ the underlying [map] function is so implemented, of course.)

Definition

[+] [-] clop

pop

built-in

Pop the top item from the stack and discard it.

   a pop
 -----------
-

popd

[pop] the second item down on the stack.

+

popd

[pop] the second item down on the stack.

   a b popd
 --------------
       b
-

Definition


popdd

[pop] the third item on the stack.

+

Definition


popdd

[pop] the third item on the stack.

   a b c popdd
 -----------------
        b c
@@ -679,11 +675,19 @@ together.

Or,

[1] [[mul]] [primrec]

-

Definition

1 swap [*] step

quoted

"Quote D" Wrap the second item on the stack in a list.

+

Definition

1 swap [*] step

quote-two

Take two items from the stack and put them into a new list.

+
joy? 1 2 3 4
+
+1 2 3 4
+
+joy? quote-two
+
+1 2 [3 4]
+

Definition


quoted

"Quote D" Wrap the second item on the stack in a list.

   a b quoted
 ----------------
      [a] b
-

Definition

Discussion

This comes from the original Joy stuff.


range

Expect a number n on the stack and replace it with a list: +

Definition

Discussion

This comes from the original Joy stuff.


range

Expect a number n on the stack and replace it with a list: [(n-1)...0].

Example

     5 range
@@ -703,15 +707,7 @@ together.

   a [b ...] reco
 --------------------
      [a ...]
-

Definition


rem

built-in

See mod.


remainder

built-in

See mod.


remove

Expects an item on the stack and a quote under it and removes that item -from the the quote. The item is only removed once. If the list is empty -or the item isn't in the list then the list is unchanged.

-
   [1 2 3 1] 1 remove
-------------------------
-        [2 3 1]
-
-

Definition

-

See the "Remove Function" notebook.


rest

built-in

   [a ...] rest
+

Definition


rem

built-in

See mod.


remainder

built-in

See mod.


rest

built-in

   [a ...] rest
 ------------------
       [...]
 

Definition


reverse

Reverse the list on the top of the stack.

@@ -740,7 +736,7 @@ or the item isn't in the list then the list is unchanged.

Definition


second

   [a b ...] second
 ----------------------
           b
-

Definition


select

Use a Boolean value to select one of two items from a sequence. :

+

Definition


select

Use a Boolean value to select one of two items from a sequence. :

   [a b] false select
 ------------------------
            a
@@ -748,7 +744,7 @@ or the item isn't in the list then the list is unchanged.

[a b] true select ----------------------- b -

Discussion

The sequence can contain more than two items but not fewer.


sharing

Print redistribution information.

Discussion

Mathematically this is a form of [id], but it has the side-effect of +

Definition

Discussion

The sequence can contain more than two items but not fewer.


sharing

Print redistribution information.

Discussion

Mathematically this is a form of [id], but it has the side-effect of printing out the GPL notice.


shift

Move the top item from one list to another.

Example

   [x y z] [a b c] shift
@@ -767,12 +763,7 @@ preserve order.

Definition


small

Return true if the item on the top of the stack is a list with zero or one item in it, false if it is a list with more than one item in it, -and an error if it is not a list.

Definition


sort

Given a list return it sorted.

-

Example

-
   [4 2 5 7 1] sort
-----------------------
-      [1 2 4 5 7]
-

spiral_next

Example code.

Definition

[[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte

Discussion


split_at

Split a list (second on the stack) at the position given by the number on +and an error if it is not a list.

Definition


spiral_next

Example code.

Definition

[[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte

Discussion


split_at

Split a list (second on the stack) at the position given by the number on the top of the stack.

Example

   [1 2 3 4 5 6 7] 4 split_at
@@ -825,12 +816,7 @@ complement to the "destructive" pair [enstacken] and [disenstacken].

1 2 3 stuncons -------------------- 1 2 3 3 [2 1] -

Definition

stack uncons

stununcons

Take the [stack] and [uncons] the top two items.

-

Example

-
   1 2 3 stununcons
-----------------------
-    1 2 3 3 2 [1]
-

sub

built-in

Subtract the number on the top of the stack from the number below it.

+

Definition


sub

built-in

Subtract the number on the top of the stack from the number below it.

   a b sub
 -------------
     (a-b)
@@ -854,7 +840,7 @@ definition of [infra].

Definition

[swap] dip

swoncat

[concat] two lists, but [swap] the lists first.

Definition


swons

Like [cons] but [swap] the item and list.

+

Definition


swoncat

[concat] two lists, but [swap] the lists first.

Definition


swons

Like [cons] but [swap] the item and list.

   [...] a swons
 -------------------
       [a ...]
@@ -920,10 +906,18 @@ the list.  You cannot uncons an item from an empty list.

   [a ...] uncons
 --------------------
       a [...]
-

Definition

Discussion

This is the inverse of [cons].


unique

Given a list remove duplicate items.


unit

   a unit
+

Definition

Discussion

This is the inverse of [cons].


uncons-pair

Expect two non-empty lists on the stack and uncons the first item from each and put them in a new list.

+
joy? [1 2] [3 4] uncons-pair
+
+[1 3] [2] [4]
+

Definition


uncons-two

Expect two non-empty lists on the stack and uncons the first item from each.

+
joy? [1 2] [3 4] uncons-two
+
+1 3 [2] [4]
+

Definition


unit

   a unit
 ------------
     [a]
-

Definition

[] cons

unquoted

combinator

Unquote (using [i]) the list that is second on the stack.

+

Definition

[] cons

unquoted

combinator

Unquote (using [i]) the list that is second on the stack.

Example

   1 2 [3 4] 5 unquoted
 --------------------------
@@ -939,9 +933,7 @@ joy? unstack
 

Definition


unswons

   [a ...] unswons
 ---------------------
        [...] a
-

Definition


void

True if the form on TOS is void otherwise False.

Discussion

A form is any Joy expression composed solely of lists. -This represents a binary Boolean logical formula in the arithmetic of the -"Laws of Form", see The Markable Mark


warranty

Print warranty information.


while

combinator

A specialization of [loop] that accepts a quoted predicate program P +

Definition


warranty

Print warranty information.


while

combinator

A specialization of [loop] that accepts a quoted predicate program P and runs it [nullary].

   [P] [F] while
 ------------------- P -> false
@@ -949,7 +941,7 @@ and runs it [nullary].

[P] [F] while --------------------- P -> true F [P] [F] while -

Definition


words

Print all the words in alphabetical order.

Discussion

Mathematically this is a form of [id].


x

combinator

Take a quoted function F and run it with itself as the first item on +

Definition


x

combinator

Take a quoted function F and run it with itself as the first item on the stack.

   [F] x
 -----------
@@ -963,4 +955,4 @@ from each list. The smallest list sets the length of the result list.

   [1 2 3] [4 5 6] zip
 -------------------------
    [[1 4] [2 5] [3 6]]
-

Definition

+

Definition

[null] [pop] [uncons-pair] [i cons] genrec
diff --git a/docs/reference/Function-Reference.md b/docs/reference/Function-Reference.md index 8e49a71..97578b4 100644 --- a/docs/reference/Function-Reference.md +++ b/docs/reference/Function-Reference.md @@ -583,7 +583,6 @@ Concatinate two lists. [flatten] [fourth] [getitem] -[remove] [rest] [reverse] [rrest] @@ -591,7 +590,6 @@ Concatinate two lists. [shift] [shunt] [size] -[sort] [split_at] [split_list] [swaack] @@ -1099,7 +1097,6 @@ Note that only one "level" of lists is flattened. In the example above [first_two] [fourth] [getitem] -[remove] [rest] [reverse] [rrest] @@ -1107,7 +1104,6 @@ Note that only one "level" of lists is flattened. In the example above [shift] [shunt] [size] -[sort] [split_at] [split_list] [swaack] @@ -1283,7 +1279,6 @@ implementation-dependant.) [first_two] [flatten] [fourth] -[remove] [rest] [reverse] [rrest] @@ -1291,7 +1286,6 @@ implementation-dependant.) [shift] [shunt] [size] -[sort] [split_at] [split_list] [swaack] @@ -1374,22 +1368,6 @@ Greater-than comparison of two numbers. ------------------------------------------------------------------------ -## help - -Accepts a quoted symbol on the top of the stack and prints its -documentation. - - [foo] help - ---------------- - -### Discussion - -Technically this is equivalent to `pop`, but it will only work if the -item on the top of the stack is a quoted symbol. - - --------------- - ## -- See [pred](#pred). @@ -1402,16 +1380,6 @@ See [pred](#pred). See [sub](#sub). ------------------------------------------------------------------------- - -## id - -The identity function. - -### Discussion - -Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy. - ------------------------------------------------------------------------ ## ifte @@ -2338,6 +2306,7 @@ This comes from the original Joy stuff. ### Crosslinks +[quote-two] [unit] @@ -2420,23 +2389,6 @@ See [mod](#mod). See [mod](#mod). ------------------------------------------------------------------------- - -## remove - -Expects an item on the stack and a quote under it and removes that item -from the the quote. The item is only removed once. If the list is empty -or the item isn't in the list then the list is unchanged. - - [1 2 3 1] 1 remove - ------------------------ - [2 3 1] - -### Definition - -See the ["Remove Function" notebook](https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb). - - ------------------------------------------------------------------------ ## rest @@ -2670,19 +2622,6 @@ and an error if it is not a list. [null] ------------------------------------------------------------------------- - -## sort - -Given a list return it sorted. - -### Example - - [4 2 5 7 1] sort - ---------------------- - [1 2 4 5 7] - - ------------------------------------------------------------------------ ## spiral_next @@ -2854,23 +2793,6 @@ Take the [stack] and [uncons] the top item. -------------------- 1 2 3 3 [2 1] ------------------------------------------------------------------------- - -## stununcons - -Take the [stack] and [uncons] the top two items. - -### Example - - 1 2 3 stununcons - ---------------------- - 1 2 3 3 2 [1] - -### Crosslinks - -[stuncons] - - ------------------------------------------------------------------------ ## sub @@ -3170,13 +3092,6 @@ This is the inverse of [cons]. [cons] ------------------------------------------------------------------------- - -## unique - -Given a list remove duplicate items. - - ------------------------------------------------------------------------ ## unit @@ -3259,19 +3174,6 @@ stack.) The quoted programs are run with [nullary]. [and] ------------------------------------------------------------------------- - -## void - -True if the form on TOS is void otherwise False. - -### Discussion - -A form is any Joy expression composed solely of lists. -This represents a binary Boolean logical formula in the arithmetic of the -"Laws of Form", see [The Markable Mark](http://www.markability.net/) - - ------------------------------------------------------------------------ ## warranty @@ -3299,22 +3201,6 @@ and runs it [nullary]. [loop] - ------------------------------------------------------------------------- - -## words - -Print all the words in alphabetical order. - -### Discussion - -Mathematically this is a form of [id]. - -### Crosslinks - -[help] - - -------------------- ## x @@ -3349,3 +3235,74 @@ from each list. The smallest list sets the length of the result list. ------------------------- [[1 4] [2 5] [3 6]] + + +------------------------------------------------------------------------ + +## empty? + +Expects a list on the stack and pushes `true` if it's empty and `false` otherwise. +It doesn't consume the list. + +### Crosslinks + +[null] + +------------------------------------------------------------------------ + +## max-of-two + +Expects two integers on the stack and removes the lesser of them, if they are equal just remove one. + + +------------------------------------------------------------------------ + +## min-of-two + +Expects two integers on the stack and removes the greater of them, if they are equal just remove one. + +------------------------------------------------------------------------ + +## quote-two + +Take two items from the stack and put them into a new list. + + joy? 1 2 3 4 + + 1 2 3 4 + + joy? quote-two + + 1 2 [3 4] + + +### Crosslinks + +[quoted] + +------------------------------------------------------------------------ + +## uncons-two + +Expect two non-empty lists on the stack and `uncons` the first item from each. + + joy? [1 2] [3 4] uncons-two + + 1 3 [2] [4] + +------------------------------------------------------------------------ + +## uncons-pair + +Expect two non-empty lists on the stack and `uncons` the first item from each and put them in a new list. + + joy? [1 2] [3 4] uncons-pair + + [1 3] [2] [4] + + + + + + + diff --git a/implementations/defs.txt b/implementations/defs.txt index a2ada1e..934989a 100644 --- a/implementations/defs.txt +++ b/implementations/defs.txt @@ -99,8 +99,9 @@ run <{} infra second rest first shift uncons [swons] dip shunt [swons] step +select [first] [second] branch size [pop ++] step_zero -small dup null [rest null] [pop true] branch +small empty? [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 diff --git a/implementations/scheme-chicken/defs.scm b/implementations/scheme-chicken/defs.scm index 554a38c..aa860ae 100644 --- a/implementations/scheme-chicken/defs.scm +++ b/implementations/scheme-chicken/defs.scm @@ -1 +1 @@ -(define (defs) (list "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" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "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" "choice [pop] [popd] branch" "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" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "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" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "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" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "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" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max empty? [uncons [max-of-two] step] [] branch")) \ No newline at end of file +(define (defs) (list "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" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "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" "choice [pop] [popd] branch" "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" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "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" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "select [first] [second] branch" "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" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "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" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max [uncons [max-of-two] step] on-non-empty-list" "min-of-two [<] [pop] [popd] ifte" "min [uncons [min-of-two] step] on-non-empty-list" "on-non-empty-list [empty?] dip [first] branch")) \ No newline at end of file diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 2341636..db750c1 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -55,18 +55,18 @@ (define (joy-eval symbol stack expression dict) (match symbol - ((or "+" "add") ((joy-func +) stack expression dict)) - ((or "-" "sub") ((joy-func -) stack expression dict)) - ((or "*" "mul") ((joy-func *) stack expression dict)) - ((or "/" "div") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!? - ((or "%" "mod") ((joy-func modulo) stack expression dict)) + ((or "+" "add") (joy-func + stack expression dict)) + ((or "-" "sub") (joy-func - stack expression dict)) + ((or "*" "mul") (joy-func * stack expression dict)) + ((or "/" "div") (joy-func quotient stack expression dict)) ; but for negative divisor, no!? + ((or "%" "mod") (joy-func modulo stack expression dict)) - ("<" ((joy-func <) stack expression dict)) - (">" ((joy-func >) stack expression dict)) - ("<=" ((joy-func <=) stack expression dict)) - (">=" ((joy-func >=) stack expression dict)) - ("=" ((joy-func =) stack expression dict)) - ((or "<>" "!=") ((joy-func not-equal) stack expression dict)) + ((or "<" "lt") (joy-func < stack expression dict)) + ((or ">" "gt") (joy-func > stack expression dict)) + ((or "<=" "le") (joy-func <= stack expression dict)) + ((or ">=" "ge") (joy-func >= stack expression dict)) + ((or "=" "eq") (joy-func = stack expression dict)) + ((or "<>" "!=" "neq") (joy-func not-equal stack expression dict)) ("bool" (joy-bool stack expression dict)) @@ -76,8 +76,8 @@ ("swaack" (values (cons (cdr stack) (car stack)) expression dict)) ("swap" (values (cons (cadr stack) (cons (car stack) (cddr stack))) expression dict)) - ("concat" ((joy-func append) stack expression dict)) - ("cons" ((joy-func cons) stack expression dict)) + ("concat" (joy-func append stack expression dict)) + ("cons" (joy-func cons stack expression dict)) ("first" (values (cons (caar stack) (cdr stack)) expression dict)) ("rest" (values (cons (cdar stack) (cdr stack)) expression dict)) @@ -92,9 +92,8 @@ (define (not-equal a b) (not (= a b))) -(define (joy-func op) - (lambda (stack expression dict) - (values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict))) +(define (joy-func op stack expression dict) + (values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict)) (define (joy-bool stack expression dict)