Applicative Syntax == Concatenative Syntax

Christopher Diggins — 2007-01-16 16:49:34

Consider if we were to define our stack-based (concatenative)
functions as quotations such as:

define Add { [+] }

We can define the open paranthesis, close paranthesis, and comma as follows:

define ( { }
define , { curry }
define ) { curry eval }

This allows us to write:

Add(2, 3)

Which leaves the value 5 on the stack just as we would like to see.

I've implemented this in the most recent version of Cat (which I have
posted at http://www.cat-language.com/cat.zip , but haven't officially
announced yet).

--
http://www.cdiggins.com

Robbert van Dalen — 2007-01-16 19:41:46

That's really very interesting and inventive - I like it a lot!

but I wouldn't trust such expressions with the correct counting of
parenthesis, i.e:

Add(2,Add(3,4)))

... oops, 1 closing parenthesis to many...

But I'm sure the curry function can be extended somehow (or that '('
could be redefined to do something more intelligent) to catch such
errors.

On Jan 16, 2007, at 5:49 PM, Christopher Diggins wrote:

> Consider if we were to define our stack-based (concatenative)
> functions as quotations such as:
>
> define Add { [+] }
>
> We can define the open paranthesis, close paranthesis, and comma as
> follows:
>
> define ( { }
> define , { curry }
> define ) { curry eval }
>
> This allows us to write:
>
> Add(2, 3)
>
> Which leaves the value 5 on the stack just as we would like to see.
>
> I've implemented this in the most recent version of Cat (which I have
> posted at http://www.cat-language.com/cat.zip , but haven't officially
> announced yet).
>
> --
> http://www.cdiggins.com
>
>

William Tanksley, Jr — 2007-01-19 16:59:08

Christopher Diggins <cdiggins@...> wrote:
> We can define the open paranthesis, close paranthesis, and comma as follows:
> define ( { }
> define , { curry }
> define ) { curry eval }
> This allows us to write:
> Add(2, 3)
> Which leaves the value 5 on the stack just as we would like to see.

Clever and sneaky! I like it.

Of course, I should note that it's missing the main attraction of
applicative languages -- the ability to name parameters. But anyhow,
it's at least a great way to provide a bridge to a traditionally
applicative API, perhaps one that has more parameters being passed to
functions than it really should :-).

And that's _practical_.

-Billy