Saturday, April 08, 2006
I think Forth is a higher level language than Lisp
The preceding chapter discussed the list, Lisp's most versatile data structure. This chapter show how to use Lisp's other data structures: arrays (including vectors and arrays), structures, and hash tables. They may not be as flexible as lists, but they can make access faster, and take up less space.
Chapter 4, ANSI Common Lisp
I'm tempted to read that paragraph as:
The preceding chapter discussed the list, Lisp's
most versatileonly data structure. This chapter show how to use Lisp's other badly implemented data structures: arrays (including vectors and arrays), structures, and hash tables. They may not be asflexibleslow as lists, but they can make access faster and at the same time, more tedious, and take up less space.Chapter 4, ANSI Common Lisp
But I'm better than that.
Yes, structures in Common Lisp are a
bit easier than in guile
:
(defstruct foo x y)
You have the name of the structure and each field. The
(defstruct)
function, however, will go ahead and make several
functions for you to help “manage” the structure, such as
(make-foo)
, (foo-p)
(foo-x)
and
(foo-y)
.
Yes, by declaring a structure, one ends up with a function per field, plus two additional functions. So one goes:
(defstruct foo x y) (setf a (make-foo)) (setf (foo-x a) 42) (setf (foo-y a) 12)
Which to me doesn't make any sense. And to describe
why it doesn't make sense, I have to go into some depth about
Common Lisp symbols. A symbol in Common Lisp is what most people would
consider a name. In (setf x 42)
both setf
and
x
are symbols. But internally symbols are just more
than a name. Way more.
A symbol is also a type unto itself in Common Lisp (as in Scheme, but there, they're way simpler) and contain more than just its name:
Name | foo |
---|---|
Value | 42 |
Function | (some internal pointer to code) |
There are a few other fields, like which package it's in, and property lists (a series of name/value pairs, much like Common Lisp's associated lists, but aren't stored or implemented as associated lists—go figure) that aren't germane to this discussion, so they're left out.
But notice that each symbol has both a “function” and a “value.” That
means one can define setf
to have a value, like:
(setq setf 42)
A parenthetical aside: “But wait a second,” you say, “didn't you use
(setf)
above to set the value?” Yes, but one can also use
(setq)
to make sure one sets the “value” of a symbol to a
given value. (setf)
is now preferred over (setq)
because it's more generalized:
(setf {place value}*
A generalization of
setq
: stores in the locaiton associated with each place the value of the corresponding value expression. If a value expression refers to one of the preceding places, it will get the new value. Returns the value of the last value.A valid place expression may be: a variable; a call to any function designated here as “settable” so long as the relevant argument is a valid place; a call to
apply
whose first argument is#'aref
,#'bit
, or#'sbit
; a call to an accessor function defined bydefstruct
; athe
orvalues
expression in which the argument(s) are valid places; a call to an operator for which asetf
expansion has been defined; or a macro call that expands into any of the preceding.
Hey! I didn't write this crazy language! And thus ends the parenthetical aside.
Now, given that each symbol can have both code and data associated with it, why one couldn't have done:
(defstruct foo x y) (foo a) (setf (a x) 42) (setf (a y) 12)
Something like that is the first think a programmer in Forth (yet another language where one has to implement common data structures by hand, yet it never claimed to be a HLL to begin with, and one can write a Forth compiler in about 1k of code, so it's a very simple langauge).
But no, we get a profusion of “special functions” created for each structure. And heaven help you if you create a structure with a field named “p”!
Oh, what does (foo-p)
do?
By Common Lisp convention, functions that end in “p” or “-p” are
queries, such as (string-greaterp)
(is one string greater than
another?) or (equalp)
(one of the five or so equality
functions) or (complexp)
(is a value a complex number?) so in
this case, (foo-p)
is asking if the value is a structure of
type foo
(and since I don't have a Common Lisp environment, I
can't see what happens if one does create a structure with a field
named “p”).
Yeah, I'm really begining to agree with John McCarthy about Lisp.
American Splendor
I just watched American Splendor, a biography of Harvey Pekar, writer of the comic book American Splendor which chronicles his life as a file clerk (and he remained a file clerk while writing the comic—I guess you could say he was a blogger before blogging was invented, using comics as his vehicle instead of a huge ever growing pulsating webpage that rules from the center of cyberspace).
The movie wasn't a documentary. I think.
I mean, it starred Paul Giamatti as Harvey, and Hope Davis as his third wife, Joyce, but it was narrated by Harvey Pekar (who commented that Paul Giamatti doesn't look anything like him), and had interviews with both him and his wife, and even some commentary from Harvey's friend Toby Radloff (played by Judah Friedlander in the film).
A real mind-bending scene was when Harvey (as played by Giamatti) and Joyce (played by Davis) went to the opening of a play based upon the comic book (which is based upon the life of Harvey)—so Harvey is providing narration, we're watching Giamatti and Davis (portraying Harvey and Joyce) watching Donal Logue and Molly Shannon playing Harvey and Davis.
It was probably the most self-referential film I've ever seen.
Overall, it was a good film (Spring was expecting to suffer through watching it, but ended up enjoying it) and a very unique way of handling the subject matter.