On 6/30/2015 5:34 PM, 'John Clements' via Racket Users wrote:
> On Jun 30, 2015, at 8:10 AM, Alexey Cherkaev <alexey.cherk...@gmail.com>
wrote:
>
> ... wouldn't it be beneficial to have such a generalised 'set!' system-wide?
I understand that Racket focusses more on immutable structures, but there are
still vectors and hash-tables which are inherently mutable and still have their
niche.
This style of set! seems like a bad idea to me.
Specifically, one of the basic ideas of algebraic languages is that programs
are compositional. Specifically, if I write (a (b x) c), then the meaning of
this term depends on the meanings of a, (b x), and c. That is, I can combine
these three values to get the result. Generalized set! breaks this intuition.
Specifically, (set! (aref x 0 1) 13) does not depend on the value of (aref x 0
1). Rather, it pulls apart this term and uses its subterm’s meanings. Put
differently, this is lvalues.
I know, I know, I sound like a pure-functional snooty-poo.
Don't confuse source syntax with what goes on under the hood - compilers
for imperative languages often go to great lengths to transform programs
into more "functional" forms. Search for "value numbering" and "static
single assignment" for more information. [Those aren't the only
functionalizing transformations, but they are the most commonly used.]
Moreover, assignment per se is not incompatible with composition -
that's just semantics. On real hardware, assignment is all you have:
"binding" is implemented as assignment to a (possibly) new location.
Tail recursion is an important case of invisibly "binding" new values to
the same locations (i.e. assigning to the control variables of an
imperative loop).
George
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.