unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: plists, alists, and hashtables
Date: Fri, 07 Aug 2015 02:23:40 +0200	[thread overview]
Message-ID: <87d1z0lzeb.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 871tfgt99k.fsf@lifelogs.com

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Thu, 06 Aug 2015 20:46:09 +0200 "Pascal J. Bourguignon" <pjb@informatimago.com> wrote: 
>
> PJB> Ted Zlatanov <tzz@lifelogs.com> writes:
>
>>> OK, it's possible, but that's a terrible syntax. Maps should *look*
>>> different from lists and their keys and values, in particular, should be
>>> easily distinguished from each other.
>
> PJB> Why?
>
> Because I don't want to look at (a b c d e f g h) and count until I find
> that g is a key and h is a value.  That's dumb and leads to mistakes.

But you never have  (a b c d e f g h).
You either have:    (:a b :c d :e f :g h)
or you have:        (a b
                     c d
                     e f
                     g h)

Really, it is quite rare that the form and type of the keys be the same
as for the values, so even when written on one line, there's no
confusion.

The only case where you would have the same form, is for an actual
dictionary to translate words, or a map used to represent a discrete
numeric function.

(defvar *increment[4]* (dictionary 0 1 1 2 2 3 3 0))
(defvar *localize* (dictionary "hello" "bonjour" "bus" "car" "car" "voiture" "hide" "cache" "cache" "cachette"))

could be confusing, but not:

(defvar *increment[4]* (dictionary 0 1
                                   1 2
                                   2 3
                                   3 0))

(defvar *localize* (dictionary "hello" "bonjour"
                               "bus" "car"
                               "car" "voiture"
                               "hide" "cache"
                               "cache" "cachette"))

 
> PJB> Additionnal syntaxes can be useful, and should only be used, for end
> PJB> users and DSL implementing a domain with pre-existing _extensive_ use of
> PJB> that syntax.
>
> My claim, I guess, is that general ELisp programming involves an
> extensive use of maps, so it could use a syntax for it.
>
> I am not making any philosophical claims about the essence of Lisp.

Well, as mentionned before, if you abstract away a given type of maps:

- you may hide the costs, and that would lead to bad results,

- you would impose one kind of data structure usage (mutable hash or
  immutable a-list or mutable a-lists or llrb-trees? etc)

- or if you don't and make it adaptative, we observe that there's
  actually very little gain obtained, (because it takes time to convert
  the data structures, and therefore it's hard to amortize that cost).


And therefore the general conclusion is that it's not such a good idea
to abstract away a higher level notion.

Ie. the programmers must have the choice between hash-table and a-list
or something else.

If you don't believe that, you can always implement a library to provide
a common API over various dictionaries. I did just that in CL:

https://gitlab.com/com-informatimago/com-informatimago/blob/master/common-lisp/cesarum/dictionary.lisp
(sorry, I've not written the automatic adaptative code yet).

Let me just say that this is not the API I reach first when I write lisp
code.  Just use a-lists or hash-tables directly, depending on the
circumstances determined at program-writting time.



> PJB> But maps are not something out of this lisp world.  They existed from
> PJB> the start as a-list, then p-list and then hash-tables.  They are a basic
> PJB> data structure perfectly integrated to an algorithmic programming
> PJB> language, and don't constitute a different, Domain Specific Language.
>
> I've given examples of why lists, in my opinion, don't make a good read
> syntax for maps.  If that's not enough to convince people, then it's not
> a good idea.

Notice that as mentionned before, the question here is whether that
should be included into the emacs lisp language, or whether that should
be defined as a user library.

As a user library nobody will say that it's a bad idea and that it
cannot have its usage in some program.

What we reject, is the idea that it should be included in the emacs lisp
language.

And this is why we feel the lack of reader macros, since that would
clearly allow you to write a new syntax in a user library, instead of
having to beg it from the emacs lisp language itself.



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


  reply	other threads:[~2015-08-07  0:23 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 21:42 How to iterate over properties in a plist? Marcin Borkowski
2015-07-31 22:18 ` Stefan Monnier
2015-07-31 22:29   ` Marcin Borkowski
2015-07-31 22:42     ` Dmitry Gutov
2015-08-01 13:34       ` Michael Heerdegen
     [not found]   ` <mailman.7705.1438381807.904.help-gnu-emacs@gnu.org>
2015-07-31 23:33     ` Pascal J. Bourguignon
2015-08-01 22:49       ` Stefan Monnier
     [not found]       ` <mailman.7750.1438469396.904.help-gnu-emacs@gnu.org>
2015-08-04 10:15         ` plists, alists, and hashtables (was: How to iterate over properties in a plist?) Ted Zlatanov
2015-08-04 10:29           ` Nicolas Petton
     [not found]           ` <mailman.7809.1438684158.904.help-gnu-emacs@gnu.org>
2015-08-04 11:23             ` plists, alists, and hashtables Ted Zlatanov
2015-08-05  4:36           ` plists, alists, and hashtables (was: How to iterate over properties in a plist?) Rusi
2015-08-05  6:12             ` plists, alists, and hashtables Pascal J. Bourguignon
2015-08-05  9:47               ` Ted Zlatanov
2015-08-05 12:20                 ` Rusi
2015-08-06 19:16                   ` Stefan Monnier
     [not found]                   ` <mailman.7892.1438888819.904.help-gnu-emacs@gnu.org>
2015-08-07 16:33                     ` Rusi
2015-08-05 17:24                 ` Pascal J. Bourguignon
2015-08-05 18:31                   ` Ted Zlatanov
2015-08-05 19:30                     ` Barry Margolin
2015-08-05 19:40                     ` Robert Thorpe
2015-08-05 21:11                     ` Pascal J. Bourguignon
2015-08-06 15:17                       ` Ted Zlatanov
2015-08-06 18:46                         ` Pascal J. Bourguignon
2015-08-06 20:19                           ` Drew Adams
2015-08-06 21:08                           ` Ted Zlatanov
2015-08-07  0:23                             ` Pascal J. Bourguignon [this message]
2015-08-06 19:35                         ` Stefan Monnier
2015-08-05 13:48               ` Drew Adams
2015-08-06 19:12           ` Stefan Monnier
     [not found]           ` <mailman.7890.1438888393.904.help-gnu-emacs@gnu.org>
2015-08-06 20:00             ` Pascal J. Bourguignon
2015-08-06 20:57             ` Ted Zlatanov
2015-08-06 21:10               ` Drew Adams
     [not found]               ` <mailman.7902.1438895429.904.help-gnu-emacs@gnu.org>
2015-08-06 21:15                 ` Ted Zlatanov
2015-08-06 21:31               ` Stefan Monnier
2015-08-07  1:53                 ` Ted Zlatanov
2015-08-07  7:34                   ` Pascal J. Bourguignon
2015-08-07 16:32                   ` Stefan Monnier
     [not found]                   ` <mailman.7941.1438965165.904.help-gnu-emacs@gnu.org>
2015-08-08  3:48                     ` Pascal J. Bourguignon
2015-08-08 13:42                       ` Stefan Monnier
2015-08-08 14:51                         ` Rusi
2015-08-07  0:08               ` Pascal J. Bourguignon
2015-08-07  2:14                 ` Ted Zlatanov
2015-08-07  7:53                   ` Pascal J. Bourguignon
2015-08-07 11:21                     ` Ted Zlatanov
2015-08-07 11:47                       ` Pascal J. Bourguignon
2015-08-07 17:21                         ` Ted Zlatanov
2015-08-07 19:21                           ` Stefan Monnier
     [not found]                           ` <mailman.7952.1438975314.904.help-gnu-emacs@gnu.org>
2015-08-08  3:52                             ` Pascal J. Bourguignon
2015-08-07 16:35                       ` Stefan Monnier
     [not found] <mailman.7856.1438803631.904.help-gnu-emacs@gnu.org>
2015-08-05 20:08 ` Ted Zlatanov
2015-08-05 20:45   ` Stefan Monnier
2015-08-05 21:36   ` Drew Adams
2015-08-05 21:41   ` Pascal J. Bourguignon
     [not found]   ` <mailman.7860.1438807554.904.help-gnu-emacs@gnu.org>
2015-08-06  1:32     ` Ted Zlatanov
     [not found]   ` <mailman.7862.1438810623.904.help-gnu-emacs@gnu.org>
2015-08-06  1:36     ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d1z0lzeb.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).