As the mentioned SRFI states it:
"This is a proposal to allow procedure calls that evaluate to the "value
of a location" to be used to /set/ the value of the location, when used
as the first operand of |set!|."
The term "location" is only used in the introductory part but for those
who know the way behind the scenes it clearly refers to the concept of
memory addresses of current register machines. By not introducing the
domain of memory addresses (where you might as well SETF your graphics
card ROM, EFI boot loaders and other registered beings in that "real"
address space that is then virtualized but still contains your call
stack) they push you into the world of nameless concepts which would be
the same as lambda forms without define. Just try this in your favorite
clean Scheme environment but don't call it algorithmic language then.
With generics it is possible to define the necessary methods for set! -
one such method exists in GOOPS (sorry!) which is able to set slots of
objects by accessor. The name or identifier isn't gone yet but its
"sequence of symbols" or syntax just looks awful:
(define point (make <point> #:x 1 #:y 2))
(x point) => 1
(set! (x point) 2)
(x point) => 2
With common sense (and not behind scenes) /x/ denotes both the value as
well as a method to set it. Other programming systems use the dot syntax
which works slightly better, e.g. /point.x/./
/
Generics and a generalized /set!/ have been en vogue in the 80s as far
as I know and have then been substituted by message passing interfaces
where you usually define your own getters and setters for each and every
variable which might behind the scenes turn out to be stored on a server
on the next floor or it might just be your favorite terminal emulation
dimming some little lights called pixels.
Back to the generalized /set!/: it leaves you in a world of invisible
pointers or location which might even be called concepts. When one
starts thinking in abstract concepts and goes from concept to concept
one might end up where one has to invent new words to "grab" them
mentally. This is what Latin is good for. But a generalized set! might
just do away with that little rest of "language" that remained in the
Algorithmic Language Scheme.
I think I'm going to purge some /set!/ methods from VSI/goops.
Regards,
Michael
On 29/06/2015 11:56, Alexey Cherkaev wrote:
Hi all,
Common Lisp has a very useful idiom of SETF that can set values to arbitrary
places. For example, one can set (1 2)-th item of an array A as:
(SETF (AREF A 1 2) 20.0d0)
Scheme preferred way is to use `*-set!` procedures. However, sometimes it is
inconvenient. For example, if I want to swap two elements in the array/vector,
I would like to use `swap`:
(define-syntax swap
(syntax-rules ()
((swap ?place1 ?place2 ?tmp)
(begin
(set! ?tmp ?place1)
(set! ?place1 ?place2)
(set! ?place2 ?place1)))))
But it will only work for vectors if `set!` can act as CL's SETF on generalised
places, such as
(swap (vector-ref v 5) (vector-ref v 3) tmp)
SRFI-17 contains the definition of such a `set!` and I can use it from there
(AFAIR Racket supports it).
I was wondering if there is more Racket-way of doing this? And is there maybe a
reason why `set!` wasn't given the same power as SETF?
For example, I was thinking of defining syntax to access my implementation of
multidimensional arrays
as
(define-syntax aref
(syntax-rules (set!)
[(set! (aref ?a ?i ...) ?v) (array-set! ?a ?i ... ?v)]
[(aref ?a ?i ...) (array-ref ?a ?i ...)]))
but obviously it won't work now as `set!` expects the `id` not an expression
(`syntax-id-rules` won't work either as `aref` is not an `id`).
Regards, Alexey
--
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.