[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: plists, alists, and hashtables

From: Pascal J. Bourguignon
Subject: Re: plists, alists, and hashtables
Date: Thu, 06 Aug 2015 22:00:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Stefan Monnier <address@hidden> writes:
> More specifically, I highly doubt that a special «k1 v1 k2 v2 ...»
> syntax for hash-tables would make much difference compared to
> (hash-table k1 v1 k2 v2 ...) which you can get today with a very simple
> `hash-table' macro.  I mean, you'd still have to say (gethash k m),
> whereas you'd probably want something like m.k, etc...
> For better or for worse, Elisp is not Python.

I would like that while elisp lacks reader macros, you can still do a
lot of things (with a pinch of kludgery) with macros.

For example, you could write something like:

    (let ((h «k1 v1 k2 v2 k3 v3»))
       print (list h.k1 h.k2)))

Notice that the lisp reader will read as symbols things that you'd wish
to be separate tokens:

(flatten '(with-my-syntax
            (let ((h «k1 v1 k2 v2 k3 v3»))
               print (list h.k1 h.k2))))
--> (with-my-syntax let h «k1 v1 k2 v2 k3 v3» h\.k4:=44 print list h\.k1

Nonethelss, your with-my-syntax macro can parse those symbols, and
reconstitute a normal sexp:

(macroexpand ' (with-my-syntax
                  (let ((h «k1 v1 k2 v2 k3 v3»))
                     print (list h.k1 h.k2))))
--> (let ((h (hash-table 'k1 'v1 'k2 'v2 'k3 'v3)))
       (setf (gethash 'k4 h) 44)
       (print (list (gethash 'k1 h) (gethash 'k2 h))))

So you can still be happy.

The only constraint is that you cannot have an unbalanced sexp in the
body of your macro (parentheses, double-quote strings, vector brackets,

__Pascal Bourguignon__       
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

reply via email to

[Prev in Thread] Current Thread [Next in Thread]