This is the mail archive of the
mailing list for the Guile project.
Re: Syntatic sugar and identifier permissivity
- To: Lalo Martins <lalo at hackandroll dot org>
- Subject: Re: Syntatic sugar and identifier permissivity
- From: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Date: 04 Apr 2000 10:43:53 +0200
- Cc: guile at sourceware dot cygnus dot com
- Cc: djurfeldt at nada dot kth dot se
- References: <20000403213207.E4496@hackandroll.org>
Lalo Martins <email@example.com> writes:
> Like it or not, syntatic sugar is a fundamental part of what
> makes a language good for day-to-day use. As I like to say, 95%
> of Python (the language) is syntatic sugar.
> === GOOPS ===
> And slot-ref/slot-set is really bad on this aspect.
And they will be removed.
> Even accessors are bad because when you're coding you don't want to
> think you're running a function with your object as an argument
> (which is what an accessor looks like, and it's more or less what it
> actually is, but that is off the point).
I think this is a question of getting used to it. It seems to me to
be a rather optimal way of using Scheme syntax to express accessing an
object. It's also nice that there are no other operations on objects
than calls to generic functions.
(BTW, when someone has improved the method compiler, accessing slots
through accessors will, in most cases, be translated to a static
reference to an offset within the object. I say this to point out
that regarding slot access as a call to a generic function imposes no
restrictions on the implementation.)
> (print foo,bar)
> is equivalent to
> (print (slot-ref foo 'bar))
(We're not just going to remove the procedure `slot-ref'. We're going
to remove *names* from GOOPS. Names are only going to be handled by
the name space handler (aka module system). So the above syntax
would have to be translated into
(print (bar foo))
This may not be at all how you arrived at this syntax, but maybe
you're influenced by class-centered object systems. In an
operation-centered object system, like GOOPS, I think (bar foo) is a
more natural way of accessing a component of an object.
Also, there should be very strong reasons before we introduce new
syntax into the language. Firstly, I don't think foo,bar is better
enough than (bar foo) to motivate new syntax. Secondly, we will soon
have `with-slots' and `with-accessors' so that you can write:
(with-slots (bar) foo
(set! bar (* bar bar))
(I include an incomplete implementation below.)
> However, this is currently not possible because Guile accepts
> _anything_ (as far as I've tested) in symbols, as long as the
> first character is valid. I don't know about r4rs, but r5rs
> tells me this is wrong.
> So IMHO Guile should be a little more strict about this
Here's the (incorrect) with-slots implementation. It works as long as
you don't use slot names in lexical bindings.
(lambda (x e)
(let ((names (cadr x))
(obj (caddr x))
(body (cdddr x)))
,@(wslots-transform-application body e names obj))))))
(define (wslots-transform x e names obj)
(cond ((symbol? x)
(if (memq x names)
`(slot-ref ,obj ',x)
((not (pair? x)) x)
((eq? (car x) 'quote) x)
((eq? (car x) 'set!)
(if (memq (cadr x) names)
,(wslots-transform (caddr x) e names obj))
(cons 'set! (wslots-transform-application (cdr x) e names obj))))
(wslots-transform-application x e names obj))
(define (wslots-transform-application x e names obj)
(map (lambda (x) (wslots-transform x e names obj))