emacs-devel
[Top][All Lists]
Advanced

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

Re: map.el and naming


From: Artur Malabarba
Subject: Re: map.el and naming
Date: Mon, 2 Mar 2015 14:33:14 +0000

> But polymorphism _is_ about using the same APIs for treating different
> objects.

Yes, but associations (or maps) and sequences are not just different
objects, they're different abstractions too. There are many operations
which make sense on both, but even then Emacs has no automatic way of
deciding which version to employ (see below).

> Do any of the operations in seq.el make sense with the
> objects you meant to handle in map.el?  If so, it could make sense to
> have them treated by the same API.

Many certainly do, but the way they must be handled is different for
sequences and associations.
For instance, if you map over a list, you want the function will be
called on each element, but if you map over an association, you want
the function to be called on each key-value pair.

Now, take a plist as an example. If you call `seq-map' on a 2-element
list where the first element happens to be a keyword, `seq.el' has no
way of knowing if you intended to use that as a sequence or as an
association, therefore it just can't handle both cases.
That's why you need two libraries. If you want to map over sequences,
you call seq-map, if you want to map over an association, you call
`map-map' (or whatever it ends up being called).

This won't only happen with mapping, I think it will happen with
enough other functions to warrant a different library. Of course this
library doesn't have to reimplement everything from scratch, it can
and should fallback on seq.el whenever possible (just like seq.el
sometimes falls back on built-ins like `mapcar').



reply via email to

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