
Setter Variables and Re: Multiple Values
I do not see where on pp. 61-62, it states that X-SETTER is not used
except with the "extended form" version of set!. I do see that it
"must" be used with the extended form.
Its says "If _place_ is a variable name, then _new value_ is stored in
the corresponding variable." That's it. There's no way to do what
you describe:
I thought the idea was to allow a programmer to "override" a setter
function thereby gaining access to all which set a variable. I
believe this can be done with slots, and my question was if it can
be done with module variables.
No. That might be a useful mechanism, but it's not provided.
Why doesn't (SET! X 42) check for an X-SETTER and call it if it
exists? ... Is it the way it is primarily for performance reasons?
If for no other reason than because X-SETTER is what would be used by
the form (SET! (X FOO) 42). But I think you're confusing the
variables with the values. X-SETTER isn't necessarily bound at
compile-time, and neither X nor X-SETTER (the symbols) necessarily
exist at run-time (indeed, strictly speaking, symbols are only
syntactic constructs in Dylan), and so what should the expansion of
(SET! X 42) check?
Also, I think you're correct in that the gist of what you're
describing would be deemed hideously expensive, as most programmers
expect variable access to be a few instructions AT MOST.
Regarding multiple values, Richard writes:
Then:
(PRINT (VALUES 1 2 3))
would print:
1
right?
But (on p. 30):
(VALUES 1 2 3)
prints:
1
2
3
Does this mean that the "READ-EVAL-PRINT" loop in Dylan has built-in
knowlege of how to print multiple values?
Yes, it must, except, of course, that such a thing is not defined as
part of the language.
This would imply that the REV loop could not be written in Dylan
wouldn't it?
No, BIND could be used to capture a list of values, which could then
be iterated over. Here's an example:
(BIND ((#REST LIST-O-VALUES (VALUES 1 2 3)))
(DO PRINT LIST-O-VALUES)
LIST-O-VALUES)
1
2
3
=> (1 2 3)
BTW, I've never actually programmed in Dylan, not even Thomas. I'm
making all this up from extensive CommonLisp experience and the
printed Dylan material. Hope it's useful nonetheless.
John Burger