emacs-devel
[Top][All Lists]
Advanced

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

Re: RFC: make maphash return a list


From: Klaus-Dieter Bauer
Subject: Re: RFC: make maphash return a list
Date: Tue, 18 Jun 2013 22:06:35 +0200

What is easier to read... that would probably be a matter of taste. Granted, it was a bad example. If find the "nested mapcar" approach easier to read (though probably not with unmodified indentation rules) when single-element functions with mapcar and functions operating on lists alternate, e.g.

  (append 
    (mapcar 'function-that-returns-list 
      (function-taking-and-returning-lists 
        (mapcar 'something-else input-list))))

Basically I find emacs lisp that contains mostly of such "diagonals" the easiest to read in terms of structure (but this goes beyond the original topic and to some degree more into indentation conventions). 

But subjectively the actually important point is the avoidance of variables, whose value changes after declaration (preserving a 1-on-1 relation between name and value during execution of the function). Then I have to find only the let form that declared the variable in order to know its intended contents rather than scan through the whole function. With maphash and similiar that style (would that be functional style?) is not possible.

That said, I have just written a little private-use library for such things. Bottomline, if I want to program more functionally it doesn't even take much bending of elisp to do so. 

kind regards, Klaus


2013/6/18 Davis Herring <address@hidden>
>   (let (mapped-hash) (maphash (lambda (k v) (push (return-something k
>     v) mapped-hash))) (mapcar 'modification-2 (mapcar 'modification-1
>     mapped-hash)))

For what it's worth, you can at least here write

(let (mapped-hash)
  (maphash
   (lambda (k v)
     (push (modification-2 (modification-1 (return-something k v)))
           mapped-hash))
   hash)
  mapped-hash)

(so long as the various functions are pure enough to allow the
reordering).  Indentation makes it longer than

(let (mapped-hash)
  (maphash (lambda (k v) (push (return-something k v) mapped-hash))
           hash)
  (mapcar 'modification-2 (mapcar 'modification-1 mapped-hash)))

(which in 80 columns can even have the tiny line appended to the
previous), but I think it is conceptually simpler.

Davis

--
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.


reply via email to

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