The Artima Developer Community
Sponsored Link

Weblogs Forum
The Two Problems of the Joy Programming Language

15 replies on 2 pages. Most recent reply: Feb 17, 2006 4:30 PM by Christopher Diggins

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 15 replies on 2 pages [ 1 2 | » ]
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

The Two Problems of the Joy Programming Language (View in Weblogs)
Posted: Feb 10, 2006 2:00 PM
Reply to this message Reply
Summary
Okay Joy has more than two problems, but two problems really stick out.
Advertisement
Achilleas Margaritas and I are designing a concatenative programming language as an alternative to Joy called Unimperative. So far we have identified two major problems with Joy, which we are seeking to address:
  1. The syntax is backwards. e.g. (5, 2, add, 3, multiply). Well at least from a Westerner's perspective. My apologies to my Arabic friends who may disagree. Unimperative will be flipping the syntax back around to the more common prefix notation (multiply, 3, add, 2, 5)
  2. There is no type checking. Type checking can be very useful for debugging and understanding code. It's kind of silly to be obliged to check documentation to see what a function expects to see on the stack. Currently we are discussing the precise syntax to use. I am trying to get Achilleas to agree on the following :
    let<List> second = (first, rest); 
    let<int> double = (multiply, 2); 
    
Any comments?


Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The Two Problems of the Joy Programming Language Posted: Feb 10, 2006 4:46 PM
Reply to this message Reply
I should probably add a third: lack of namespaces. This is something else we are trying to address in the Unimperative language.

Michel Parisien

Posts: 25
Nickname: kriggs
Registered: Jul, 2005

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 2:16 AM
Reply to this message Reply
To be honest, I know postfix very well. It certainly is what I keep seeing pop-up in the textbooks, what many low-level languages seem to use, including unix's famous dc program. I actually didn't know there was an usable alternative to infix and postfix... How do you use a stack with prefix?

Keith Gaughan

Posts: 17
Nickname: kgaughan
Registered: Feb, 2003

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 6:55 AM
Reply to this message Reply
I'm a little puzzled by your first objection. Joy is a concatenative language (like Forth and others), and because of that it uses postfix. Get rid of that, and the language ceases to be concatenative, or at least that's what Manfred would say.

Keith Gaughan

Posts: 17
Nickname: kgaughan
Registered: Feb, 2003

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 6:57 AM
Reply to this message Reply
Ditto. A language that uses prefix (or infix for that matter) is inherently applicative.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 9:55 AM
Reply to this message Reply
> To be honest, I know postfix very well. It certainly is
> what I keep seeing pop-up in the textbooks, what many
> low-level languages seem to use, including unix's famous
> dc program. I actually didn't know there was an usable
> alternative to infix and postfix... How do you use a stack
> with prefix?

You simply apply functions in a list from right to left.

In joy

DEFINE x == 1 2 [*] 3 [+];

Is in Uimperative:

let<> x == (plus, 3, multiply, 1, 2);

It is a simple as that.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 10:00 AM
Reply to this message Reply
> I'm a little puzzled by your first objection. Joy is a
> concatenative language (like Forth and others), and
> because of that it uses postfix.

It is right concatenative. In joy

f g

is mathematically equivalent to the composition of functions:

g(f)

Whereas in Unimperative the sequences

f, g

it equal to:

f(g)

> Get rid of that, and the
> language ceases to be concatenative, or at least that's
> what Manfred would say.

He might call it a compositional language, but the languages are actually equivalent. One is concatenative to the right, and the other is concatenative to the left.

> Ditto. A language that uses prefix (or infix for that matter) is inherently applicative.

That isn't true.

Speaking of Manfred, could you ask the concatenative discussion group why they won't let me join? It's been several days and I am still awaiting moderator approval to join.

Thanks a lot.

Michel Parisien

Posts: 25
Nickname: kriggs
Registered: Jul, 2005

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 11:21 AM
Reply to this message Reply
Well in that case, don't you need to read from right to left to understand it? I thought that was your initial complaint about postfix.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 11:43 AM
Reply to this message Reply
> Well in that case, don't you need to read from right to
> left to understand it? I thought that was your initial
> complaint about postfix.

My complaint against postfix was that the the application of functions was in the reverse order of common mathematical notation.

Consider:

let<> f = square;
let<> g = add_one;
let<> h = double;
let<> fubar = (f, g, h, 4);


So mathematically you would write this:

f(g(h(4)));


However if you want to write the same thing using Joy you would write:

DEFINE 
  f == square;
  g == add_one;
  h == double;
  fubar = 4 h g f;


This is the opposite of function composition. Sometime right-concatenative notation is indeed more appropriate. For example, if we view the programs as sequencable "actions" as opposed to functions. For this Unimperative will support a sequencing operator ">>":

  let<> fubar = 4 >> h >> g >> f;


The two forms would be interchangeable:

  let<> fubar = 4 >> f, g, h; 


In order to make all of this more clear, think of ">>" as a left to right sequencing operator, and "," as the function composition operator.

Hopefully this clears things up.

Michel Parisien

Posts: 25
Nickname: kriggs
Registered: Jul, 2005

Re: The Two Problems of the Joy Programming Language Posted: Feb 11, 2006 2:16 PM
Reply to this message Reply
Yeah, I get it. Though personally, I still prefer postfix. ;) If you keep a stack in your mind, it is extremely easy to read.

I think in the end it is just a question of preference. And that being the case, I won't hold it against Joy to have decided on one rather than the other. Of course, you can feel free to continue hating it :)

Keith Gaughan

Posts: 17
Nickname: kgaughan
Registered: Feb, 2003

Re: The Two Problems of the Joy Programming Language Posted: Feb 13, 2006 1:25 PM
Reply to this message Reply
Have you tried posting to it? The group's been rather quiet lately, so you might have been approved but not have noticed.

stevan apter

Posts: 2
Nickname: stevan
Registered: Feb, 2006

Re: The Two Problems of the Joy Programming Language Posted: Feb 13, 2006 8:44 PM
Reply to this message Reply
i think there's an argument to be made for a left-concatenative joy which is rooted in the fact that we read the code left-to-right. my own mental habits cause me to read

2 3 + 4 *

as "push 2, push 3, add, push 4, multiply." so how would i read

* 4 + 3 2

? perhaps as

"multiply the result of pushing 4 onto the result of adding the result of pushing 3 after pushing 2," which is, i hope you will agree, slightly more awkward. (the alternative is to *read* from right-to-left.)

as for type-checking, i, personally, am no fan, although i suppose this will mark me as a hopeless retrograde.

best

sa

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The Two Problems of the Joy Programming Language Posted: Feb 13, 2006 8:58 PM
Reply to this message Reply
> i think there's an argument to be made for a
> left-concatenative joy which is rooted in the fact that we
> read the code left-to-right. my own mental habits cause
> me to read
>
> 2 3 + 4 *
>
> as "push 2, push 3, add, push 4, multiply." so how would
> i read
>
> * 4 + 3 2
>
> ? perhaps as

In Unimperative there isn't any operators so that would read:

multiply << 4 << add << 3 << 2;

or equivalently:

(multiply << 4) << (add << 3 << 2);

> "multiply the result of pushing 4 onto the result of
> adding the result of pushing 3 after pushing 2," which is,
> i hope you will agree, slightly more awkward. (the
> alternative is to *read* from right-to-left.)

I agree that instructions for doing things makes sense left to right, but the composition of mathematical functions is more natural right to left.

Either way, I am more flexible on this point, then when I original posted. The latest version of Unimperative ( which now has its own website at http://www.unimperative.com ), now provides two concatenation operators ">>" and "<<". I am phasing out the usage of ",". This way people get to have whatever they prefer.

(add << 3 << 2) >> (multiply << 4);

or

begin >> 3 >> 2 >> add >> 4 >> multiply;

The begin, is a neccessary evil of C++ ">>" operator overloading.

stevan apter

Posts: 2
Nickname: stevan
Registered: Feb, 2006

Re: The Two Problems of the Joy Programming Language Posted: Feb 13, 2006 10:05 PM
Reply to this message Reply
also recall that in joy

[1 2 3] first <-> 1

i.e. the head of the list is on the left.

so

2 [[3 +] 10 20 junk morejunk] first i <-> 5

in the right-concatenative version

i first [morejunk junk 20 10 [+ 3]] 2 <-> 5

that is, the first of a list would be the *rightmost* element.

Gregg Wonderly

Posts: 317
Nickname: greggwon
Registered: Apr, 2003

Re: The Two Problems of the Joy Programming Language Posted: Feb 17, 2006 1:33 PM
Reply to this message Reply
> I'm a little puzzled by your first objection. Joy is a
> concatenative language (like Forth and others), and
> because of that it uses postfix.\

There is a long history of the simplicity of postfix languages. The particular issue of interest is the simplicity of interpreter design. There is no "context" required, all operators merely operate off of a stack. Values go on the stack, operators execute using stack values.

HP scientific calculators of old used Reverse Polish Notation, or postfix. One of the more powerful features is that it allows you to investigate another calculations related to what you've already started without loosing those. A standard calculator typically has a great deal of problems handling randomly ordered calculations. Postfix operators such as swap, peek, exchange etc make it easy to manipulate the stack as you reframe your thoughts on the calculation you are trying to make, without loosing everything.

10 10 moveto
100 0 rlineto stroke
100 neg 3 rmoveto
/Times-Roman findfont 40 scalefont setfont
(This is Text) show
showpage

Flat View: This topic has 15 replies on 2 pages [ 1  2 | » ]
Topic: Where is Thinking in Java, 4th Edition? Previous Topic   Next Topic Topic: Unimperative: A Lisp Dialect and a C++ Subset


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us