# On comments 1..6

## phimvt@lurac.latrobe.edu.au — 2000-09-05 02:09:59

    Hello friends,

        I am now catching up with the catching up: comments on the

    comments. Thanks for the feedback in general, it has been helpful

    and interesting.

        Manfred

    Comments - 1:

        Stevan reported on inlining in his conk. Louis reminded me

    of Juho Snellman's  lambdas in Joy. I'll have more to say on

    both some time later. In the meantime, thanks.

    Comments - 2:

        Louis reported on static typechecking for Joy. Very interesting.

    I still do not know what sort of restrictions should be imposed on,

    say, lists of a type. Should there be a universal type for programs?

    Comments from ML/Miranda/Haskell/Mercury programmers about possible

    polymorphism most welcome.

        (Since I wrote this, Serguey and Louis have started on this topic.)

    Comments - 3:

        Louis asked more about closures. Sorry it has taken me so long

    to answer. A closure is a piece of code possibly containing free

    variables, plus enough of the current environment/symboltable

    to find their bindings/values. In combinatory logic all functions

    are curried. Combinatory logic and Joy do not have variables and

    hence no closures. The closest in Joy is a quotation - but since

    it does not contain variables, there is no need to resolve them.

    If you are a Pascal programmer, you might find it useful to look

    at Wirth's book Data Structures + Algorithms = Programs, the early

    (1976 ?) edition with the chapter on compilers, the PLzero compiler.

    The quite difficult stuff on static chains (= list of bindings)

    is made intelligible there. In other compilers (e.g. Wirth's PascalS)

    the static chain is replaced by what is called a display. If you

    have seen a Lisp-in-Lisp (in many of the older Lisp books), the

    eval(expression,environment) function has to take care of the

    environment. You might also have come across the SECD machine

    (the Lisp virtual machine, due to P.(?) Landin (196?) for his ISWIM

    language), with the S (Stack), E (Environment), C (Code) and D (Dump) registers,which has to do the same thing in a more machine oriented way -

    but it is a very high level machine, of course.

         But, to repeat, Joy has no variables of abstraction, and hence

    no closures. Hope this helps.

    Comments - 4

        I enjoyed Billy's reference to my (wrongly parenthesised)

    functional expression as "an abomination from the lowest pits

    of hell". He also showed how to rewrite it in concatenative

    form. I think we agree: when it must be messy, then it must be messy.

    Comments - 5

        I forgot the to update the subject line - so this never existed.

    Comments - 6

        I had considered a certain extension of Joy, something like

    a macro preprocessor. Louis said it would not be necessary because

    "Joy is its own macro language". While it is true that Joy can

    manipulate its own programs, that isn't quite the same as being

    its own macro language. In a later message I suggested looking at

    M4 as a suitable testbed. (Whether M4 is the best is debateable,

    but if it was good enough for Ratfor, then it is good enough for

    some experiments here).

        For ease of reading, I'll define macro names with a capital

    letter. Then the joy definition of square and the M4 definition

    of Square look like this:

        square  ==  dup *

        define(Square, dup *)

    Both can be used in  the same way:

        3 square  ==  9

        3 Square  ==  9

    But Square is an in-line version of square. For example

        [square] size  ==  1

        [Square] size  ==  [dup *] size  == 2

    Some people want inline definitions for efficiency, since it saves

    a call. I am not all that keen on it.

        But there may be other uses of M4 style macros, especially

    for definitions. Consider

        n1  ==  ...x1...

        n2  ==  ...x2...

    where the dots represent some fairly complicated stuff. With M4

    definitions that use parameters ($1, $2 and so on), such definitions

    look like this

        define(N, ...$1...)

        n1  ==  N(x1)

        n2  ==  N(x2)

    The alternative in "pure" Joy is to have

        n  ==  shuffle x into the right position inside ...x...

        n1  ==  x1 n

        n2  ==  x2 n

    All the shuffling has to take place at run time, for every call.

    (Some of my own programs do this - e.g. mk_qsort in STDLIB.JOY.)

    It may be possible to enter things into the symbol table after

    some preliminary (="compile time") processing, but I do not yet

    see through all this too clearly. Maybe somebody will want to

    have a look at using M4 in detail. _If_ it turns out useful,

    one should investigate a taylor-made preprocessor for Joy.

        Manfred