[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: data structure in LL
Dan Sugalski wrote:
> I think we've already got them. Lists can't be in lists, but we fake it
> pretty well with arrays. The s-exp
>
> ("foo" "bar" (1 2 3))
>
> turns into
>
> ["foo", "bar", [1, 2, 3]]
>
> in perl. Rather than a list with an embedded list, it's an array with an
> embedded array. Output from subs could be embedded there, but I don't know
> enough Lisp/Scheme to do it properly.
The list/array distinction isn't important. The point about
s-expressions is not that they offer a nice syntax for lists. So do
lots of languages. Their key property is that Lisp/Scheme provides a
primitive named READ, which converts external Scheme data -- including
*program text* -- into s-expressions. (It doesn't parse them, it
reads them; this is an important distinction, but perhaps one we can
gloss over momentarily.)
You say Perl has eval. What does eval in Perl consume? Scheme's EVAL
doesn't consume a *string*: it consumes a list (which you can generate
through any means, including writing it as an s-expression). In
particular, then, you can READ a program and EVAL it. You can do that
just as easily in a string-based EVAL. But you can also throw your
entire suite of list-processing functions at this list between READ
and EVAL to manipulate your program (eg, implementing a macro system).
Which is a lot nicer than trying to pull it apart and put it back
together with regexps.
Shriram