Re: [stack] sweetening concatenative syntax

[email protected]
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
> John Nowak <[email protected]> wrote:
>
>>  I don't understand. It seems I can indeed have it both ways. Isn't
>>  converting a language to a simpler language what compilers do all the
>>  time? Maybe I'm misunderstanding.
>
> But you can't measure the readability of a language NOTATION in
> comparison to a different notation by converting the first one into
> the second. By that standard Brainf**k and Haskell have the same
> readability (they can both be converted to x86 machine code).

I didn't think I was doing that. I don't mean to suggest that lambda
expressions are superior to pointfree code because they can be converted
to pointfree code and therefore are just as readable if not more so. There
are certainly cases where lambda expressions are less readable. We got
confused somewhere back there...

>>  This is incorrect. "Linear" means that *values* have at most one
>>  reference to them. It has nothing to do really with how often a given
>>  variable shows up the source code. Take a look at Henry Baker's Linear
>>  Lisp. It certainly has lambdas, but it is also certainly linear. There
>>  are also languages like Clean that enforce linearity through the type
>>  system.
>
> I'm trying to find where linear lisp or Clean's uniqueness types allow
> multiple uses of the same variable. I'm not finding that; it appears
> to me that the opposite of what you claim is true: those languages
> claim to be linear BECAUSE they enforce only one use of each variable.
>
> What am I missing?

Here's a function from Baker's "The Forth Shall Be First":

   (defun abs (x)
     (if-minusp x (- x) x))

Here, 'x' appears more than once in the source code, yet it is still
linear. The only claim I was making is that variables can appear more than
once and the language can still be linear.

What Linear Lisp disallows is implicit copying. For example, to write
"square", you need to do something like this:

   (defun square (x)
     (let* ((x x-prime (dup x)))  ; use Dylan syntax [Shalit92].
       (* x x-prime)))

The difference between Linear Lisp and Fifth is that Fifth essentially
just inserts the 'dup' expressions for you. Dan has suggested that perhaps
there should be an option to disallow this behavior so that copying is
explicit. I'm not sure this is necessary provided that there is a clear
and simple set of rules for when copying will occur as I've laid out.

>> Likewise, you can have non-linear languages that do not have
>> variables. Look at Joy for example.
>
> Joy appears to be linear. What am I missing?

Joy is not linear because Joy allows values to have multiple references to
them. For example, if I do '[1 2 3] dup', the list does not get copied.
Instead, there are now two references to the same list on the stack.
Because values can have multiple references to them, it is not safe to
mutate values because you will have visible side effects. This is in
contrast to Fifth where you can always mutate, and hence use more
efficient non-persistent data structures, while remaining purely
functional. (The one exception to this are references. The type system
separates functions that read from or write to reference values from
"pure" code.) Joy's non-linear nature is also the reason it requires a
garbage collector whereas Fifth gets on fine without one as no garbage is
ever created.

In short, enforcing that values are singly referenced is the definition of
linearity. Use-once variables are a means to achieve this that requires
explicit copying. However, you can also have a linear language by
automatically inserting the necessary copying which is what Fifth does.

- John
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.