Re: [stack] Syntax for combinators

John Cowan <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
James Hague scripsit:

> I would like to see [if-part] replaced with a simple Boolean flag.
> Is there a reason it needs to be a quotation?  I believe it's a Boolean
> in Factor.

There are two separate two-armed conditional words in Joy, "ifte" and
"choice".  The latter behaves as you suggest: it takes a boolean
value and two quotations on the stack.  However, "ifte" works differently:
after executing the [if-part], it gets the boolean value from the
top of the stack and then restores the stack to its former state.

Thus the program

	20 [pop true] ["yes"] ["no"] ifte

is equivalent to

	20 "yes"

because although the pop is executed, its effect is undone by the
stack restoration.

There are many other Joy combinators with similar behavior.  For example,
"nullary" pops a combinator from the stack, preserves the stack, executes
the combinator, saves the top value, restores the stack, and pushes the
top value.  Thus it does not matter how many items are popped from the
stack by the combinator.

In the Joy interpreter, the stack is a linked list rather than a vector,
and garbage collection is used to reclaim stack fragments.  Consequently,
restoring the stack is a cheap operation.

-- 
Time alone is real                      John Cowan <[email protected]>
  the rest imaginary
like a quaternion       --phma          http://www.ccil.org/~cowan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.