[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 <monnier@iro.umontreal.ca> 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:
(with-my-syntax
(let ((h «k1 v1 k2 v2 k3 v3»))
h.k4:=44
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»))
h.k4:=44
print (list h.k1 h.k2))))
--> (with-my-syntax let h «k1 v1 k2 v2 k3 v3» h\.k4:=44 print list h\.k1
h\.k2)
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»))
h.k4:=44
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,
etc).
--
__Pascal Bourguignon__ http://www.informatimago.com/
“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
- Re: plists, alists, and hashtables, (continued)
- Re: plists, alists, and hashtables, Robert Thorpe, 2015/08/05
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/05
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/06
- RE: plists, alists, and hashtables, Drew Adams, 2015/08/06
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/06
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/06
- RE: plists, alists, and hashtables, Drew Adams, 2015/08/05
Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/06
Message not available
- Re: plists, alists, and hashtables,
Pascal J. Bourguignon <=
Message not available
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/06
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/07
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/07
- Message not available
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/07
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/08
- Re: plists, alists, and hashtables, Rusi, 2015/08/08