Joy Question
Christopher Diggins — 2006-02-20 04:03:52
Hello all,
Here is a brief question about Joy. In Joy the combinator "ifte" takes three
quotations, but why not instead a boolean value and two quotations? I find
it just as useful, and far easier to implement efficiently because we don't
have to copy and restore the stack. Any explanation would be useful, because
I suspect I am overlooking something here.
Thanks,
--
Christopher Diggins
http://www.cdiggins.com
[Non-text portions of this message have been removed]
Manfred Von Thun — 2006-02-20 04:55:42
Hi Chris,
Your question has come up before on the group, and several people come up
with the same opinion as you.
First, there is in fact an operator ³choice² in Joy which does exactly what
you want. Actually, when I wrote the implementation, this is the one I
implemented
before ³ifte² because it is easier to implement.
Whether ³ifte² and many others like ³linrec² and even ³nullary² require
copying
the stack depends on how the stack is implemented. If it is implemented as
an array of consecutive memory locations, then indeed much copying may be
involved. But if the stack is implemented as just another linked list, then
³ifte²
and the others are easy and efficient: just keep a pointer to the old stack
and
then mangle the stack as much as much as needed by the if-part (or whatever)
and, when done restore the old stack from the saved pointer. So for this way
of implementing the stack ³choice² and ³ifte² are almost equally easy to
implement
and equally easy to implement efficiently. I once even proposed a hybrid
solution in which the execution of the if-part for ³ifte² and others creates
some
restoring code for just those parts of an array-implemented stack that have
been
mangled by the if-part.
This then raises the question which of ³choice² and ³ifte² is better from
the
user¹s point of view. Using ³choice² the programmer has to either duplicate
all the values that will be needed to compute the Boolean, of to restore
them
somehow before the chosen branch is executed. This can be bothersome and
errorprone if many values are needed for computing the Boolean. This is why
I prefer ³ifte² in a high level language.
Not everybody agreed with this. In particular, Billy Tanksley (Hi Billy!)
and
some others felt that the invisible copying or saving and restoring involved
³too much action behind the scenes² and that ³everything should be under
user control², or some such expression was used. This is indeed how Forth
does it.
So, this is the situation. Do keep in mind that ³ifte² is only one of many
combinators for which this question arises.
Thanks for the interest and the question.
- Manfred
On 20/2/06 3:03 PM, "Christopher Diggins" <cdiggins@...> wrote:
> Hello all,
>
> Here is a brief question about Joy. In Joy the combinator "ifte" takes three
> quotations, but why not instead a boolean value and two quotations? I find
> it just as useful, and far easier to implement efficiently because we don't
> have to copy and restore the stack. Any explanation would be useful, because
> I suspect I am overlooking something here.
>
> Thanks,
>
> --
> Christopher Diggins
> http://www.cdiggins.com
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
[Non-text portions of this message have been removed]
Christopher Diggins — 2006-02-20 05:13:51
Hi Manfred,
Thanks for your prompt and informative response.
Christopher
http://www.unimperative.com
[Non-text portions of this message have been removed]
William Tanksley, Jr — 2006-02-21 22:46:27
Manfred Von Thun <
m.vonthun@...> wrote:
> This then raises the question which of ³choice² and ³ifte² is better from
> the
> user¹s point of view. Using ³choice² the programmer has to either duplicate
> all the values that will be needed to compute the Boolean, of to restore
> them
> somehow before the chosen branch is executed. This can be bothersome and
> errorprone if many values are needed for computing the Boolean. This is why
> I prefer ³ifte² in a high level language.
There's a third choice: the user has to arrange the computation so
that the values needed to compute the booleans are not needed after
the boolean has been determined. All three choices are perfectly
reasonable, of course, but given that all of the other operations in
the language consume their operands, I don't see why this particular
one has to do something different.
> Not everybody agreed with this. In particular, Billy Tanksley (Hi Billy!)
Hi! :-)
> and
> some others felt that the invisible copying or saving and restoring involved
> ³too much action behind the scenes² and that ³everything should be under
> user control², or some such expression was used. This is indeed how Forth
> does it.
True dat. Well summarized. We also referred to "linear logic" and
Baker's essay whose title contains "The Forth Shall Be First".
Interestingly, though, if one reads Baker enough, one also finds
justification for your position, Manfred. It might be said that the
opposite of linear logic is reversible logic. With linear logic, every
datum is destroyed the first time it's used (you have to manually copy
the datum if you want to keep a copy); but with reversible logic, no
information is ever truly destroyed. Every function has a true
inverse, and any program could be halted at any given point and run
backwards. The trick is to figure out what operations can be both
reversible and useful. For example, a reversible + might leave two
numbers on the stack -- one of them the sum of the inputs,and the
other one the first input. When run in reverse, + would have to leave
the first input and the difference of the first and the second (which
is, nicely enough, also a good definition for the - operator, and it's
fitting that + and - should be operational inverses).
Now, your ifte combinator isn't at all reversible, but you can see
(I'm sure) that there's at least a passing similarity.
> - Manfred
-Billy
sa@dfa.com — 2006-02-23 18:15:42
Christopher Diggins — 2006-05-29 18:04:02
I have a question about Joy:
5 [succ succ] head i => ?
5 [succ succ] tail i => ?
What is the answer, and why?
Thanks,
Christopher Diggins
[Non-text portions of this message have been removed]
John Cowan — 2006-05-30 02:51:45
Christopher Diggins scripsit:
> 5 [succ succ] head i => ?
> 5 [succ succ] tail i => ?
>
> What is the answer, and why?
(Note: In Joy the primitives are "first" and "rest").
The first one pushes 5 on the stack, then the list [succ succ], then
pops [succ succ] and pushes succ, then tries to evaluate i and fails
because i wants a list on the top of the stack.
The second one pushes 6 on the stack, then the list [succ succ], then
pops [succ succ] and pushes [succ], then evaluates i, which applies
succ to 5, giving 6.
--
I marvel at the creature: so secret and John Cowan
so sly as he is, to come sporting in the pool
cowan@...
before our very window. Does he think that
http://www.ccil.org/~cowan
Men sleep without watch all night?
Christopher Diggins — 2006-05-30 03:06:07
Hi John,
Thank you very much for answering. That is what I had thought. I just
surprised myself to realize that unquoted programs can exist on the stack.
e.g. [succ] first where there isn't really much you can do with them.
I assume that "[foo 1] tail i" will work similarly?
On 5/29/06, John Cowan <cowan@...> wrote:
>
> Christopher Diggins scripsit:
>
>
> > 5 [succ succ] head i => ?
> > 5 [succ succ] tail i => ?
> >
> > What is the answer, and why?
>
> (Note: In Joy the primitives are "first" and "rest").
>
> The first one pushes 5 on the stack, then the list [succ succ], then
> pops [succ succ] and pushes succ, then tries to evaluate i and fails
> because i wants a list on the top of the stack.
>
> The second one pushes 6 on the stack, then the list [succ succ], then
> pops [succ succ] and pushes [succ], then evaluates i, which applies
> succ to 5, giving 6.
>
> --
> I marvel at the creature: so secret and John Cowan
> so sly as he is, to come sporting in the pool cowan@...
> before our very window. Does he think that http://www.ccil.org/~cowan
> Men sleep without watch all night?
>
[Non-text portions of this message have been removed]
John Cowan — 2006-05-30 03:41:09
Christopher Diggins scripsit:
> Thank you very much for answering. That is what I had thought. I just
> surprised myself to realize that unquoted programs can exist on the stack.
> e.g. [succ] first where there isn't really much you can do with them.
Not unquoted programs, but words that don't appear in a list.
They are the datatype corresponding to symbols in Lisp. You can intern
a string to generate a symbol, and you can retrieve the body (definition)
of a symbol. Furthermore, you can cons a symbol onto an existing list
to create a new list which can then be executed as a program.
> I assume that "[foo 1] tail i" will work similarly?
That's equivalent to the program "1".
--
John Cowan
http://ccil.org/~cowan cowan@...
'Tis the Linux rebellion / Let coders take their place,
The Linux-nationale / Shall Microsoft outpace,
We can write better programs / Our CPUs won't stall,
So raise the penguin banner of / The Linux-nationale. --Greg Baker
stevan apter — 2006-05-30 10:53:03
you might wish to check the archives for this list, starting
around message 1621. the question of what e.g. [+] first
should mean was a lively topic throughout 2003.
http://groups.yahoo.com/group/concatenative/message/1621
----- Original Message -----
From: "Christopher Diggins" <cdiggins@...>
To: <concatenative@yahoogroups.com>
Sent: Monday, May 29, 2006 11:06 PM
Subject: Re: [stack] Joy Question
> Hi John,
>
> Thank you very much for answering. That is what I had thought. I just
> surprised myself to realize that unquoted programs can exist on the stack.
> e.g. [succ] first where there isn't really much you can do with them.
>
> I assume that "[foo 1] tail i" will work similarly?
>
>
> On 5/29/06, John Cowan <cowan@...> wrote:
> >
> > Christopher Diggins scripsit:
> >
> >
> > > 5 [succ succ] head i => ?
> > > 5 [succ succ] tail i => ?
> > >
> > > What is the answer, and why?
> >
> > (Note: In Joy the primitives are "first" and "rest").
> >
> > The first one pushes 5 on the stack, then the list [succ succ], then
> > pops [succ succ] and pushes succ, then tries to evaluate i and fails
> > because i wants a list on the top of the stack.
> >
> > The second one pushes 6 on the stack, then the list [succ succ], then
> > pops [succ succ] and pushes [succ], then evaluates i, which applies
> > succ to 5, giving 6.
> >
> > --
> > I marvel at the creature: so secret and John Cowan
> > so sly as he is, to come sporting in the pool cowan@...
> > before our very window. Does he think that http://www.ccil.org/~cowan
> > Men sleep without watch all night?
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>