[comp.lang.misc] Programs as data

mhcoffin@tolstoy.waterloo.edu (Michael Coffin) (06/28/91)

It's true that Prolog handles programs-as-data nicely, but I don't
think it's true that Prolog has a conventional syntax.  Other than
using infix notation, it looks nothing like any of the popular
languages.  That's not surprising; Prolog almost entirely lacks
explicit control structures, which are everywhere in conventional
languages. 

And unless you are willing to give up explicit control structures,
things are much more difficult than Prolog.  You have to devise ways
to represent not just infix notation, which has a fairly natural tree
representation, but while statements, case statements, for loops,
blocks, procedures, exit statements, ---the list goes on.  This has in
fact been done; I once saw a proposal for a Pascal-like language that
allowed programs as data.  Each control construct had an internal
format that amounted to a record with fields for each piece.  Most of
the fields, were, of course pointers to other records.  The result
was, in my opinion, a mess.

By the way, I think we ought to keep in mind that there are several
Lisps.  Common Lisp has a rather complicated syntax, as has been
pointed out.  Scheme, on the other hand, has a syntax that will fit on
a single page and leave room for comments.

-mike

rockwell@socrates.umd.edu (Raul Rockwell) (06/29/91)

Michael Coffin:
   Prolog almost entirely lacks explicit control structures, which are
   everywhere in conventional languages.

   And unless you are willing to give up explicit control structures,
   things are much more difficult than Prolog.  You have to devise
   ways to represent not just infix notation, which has a fairly
   natural tree representation, but while statements, case statements,
   for loops, blocks, procedures, exit statements, ---the list goes
   on.

There is no reason these things can't be expressed as functions and/or
meta-functions.  For example, a case statement may be represented as a
meta-function which takes two arguments:  (1) a list of function
representations and (2) a selection argument.

Blocks are even simpler -- use the same notation you use to describe
data and pass the results to a meta-function which returns a usable
function.

There are a number of ways to construct for/while loops, ranging from
repeated application of a function to some data (similar to
"foreach"), to a more explicit iteration where you supply a predicate
to determine when the loop is complete.

I'll agree (in advance) that you'll want some sort of meta-function
syntax so that you can take functions as arguments, but that need not
be complex.

-- 
Raul <rockwell@socrates.umd.edu>

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (06/30/91)

In article <1991Jun28.133708.3776@watserv1.waterloo.edu>, mhcoffin@tolstoy.waterloo.edu (Michael Coffin) writes:
> It's true that Prolog handles programs-as-data nicely, but I don't
> think it's true that Prolog has a conventional syntax.

Prolog syntax is (extensible) operator-precedence.  That's about as
conventional as you can get.

> Other than
> using infix notation, it looks nothing like any of the popular
> languages.  That's not surprising; Prolog almost entirely lacks
> explicit control structures, which are everywhere in conventional
> languages. 

Prolog has sequence and if->then;else.  What's missing?  Assignment
and `obvious' while-loops, which go together.

-- 
I agree with Jim Giles about many of the deficiencies of present UNIX.