On Jul 1, 2015, at 4:27 AM, Alexey Cherkaev <alexey.cherk...@gmail.com> wrote:

> Hi all,
> 
> Thanks to all replies, at the moment I would tend to agree that generalised 
> `set!` might not be such a great idea after all:
> The notion of 'place' is essentially a pointer to a memory location, but it 
> is not the first-class citizen: the following expressions are not equivalent: 
> (let ((x (aref v 5))) (set! x 100)) and (set! (aref v 5) 100), and it might 
> be the place for confusion.
> The syntax part of it, `(set! (what-ever ...) new-value)`, however, I don't 
> mind: `set!` is a special form/macro after all, not a procedure. No one would 
> demand the procedural clarity from `let` or `define`. The question is rather 
> if it worth having yet another special form.
The syntax part of it is what srfi/17 does, and anyone who requires srfi/17 
hopefully understands that it’s another special form, and that the (what-ever 
…) is not actually an expression, and hopes that people reading the code will 
also understand that. Because of the first point, it’s best that it’s in a 
separate library like srfi/17, not available by default, because that avoids 
confusion unless you require srfi/17 on purpose. 

> Summarising the points above, what if instead of `set!` there is a more 
> general abstraction 'location’:

Side note: Such a `location` abstraction doesn’t have to be all about 
mutability.

There is a purely functional version of this concept in Jack Firth's `lenses` 
package, which says that
lenses are functions that take a data structure and returns two values;
 the first being the “view,” or the value at that location,
 and the second being the “context” of that value, represented as a function 
that acts as a functional “setter,”
and these lenses are functional and compose-able.

http://pkg-build.racket-lang.org/doc/lenses@lenses/index.html
https://github.com/jackfirth/lenses

Also, because lenses return two values, they don't have to allocate a new 
structure every time, which (I think) means slightly better performance.

-- 
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.

Reply via email to