From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Klaus-Dieter Bauer Newsgroups: gmane.emacs.devel Subject: Re: RFC: make maphash return a list Date: Tue, 18 Jun 2013 22:06:35 +0200 Message-ID: References: <87txmjcnz5.fsf@uwakimon.sk.tsukuba.ac.jp> <51C07898.6030409@lanl.gov> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf3079babad754bf04df7341d2 X-Trace: ger.gmane.org 1371589112 23054 80.91.229.3 (18 Jun 2013 20:58:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Jun 2013 20:58:32 +0000 (UTC) Cc: emacs-devel@gnu.org To: Davis Herring Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 18 22:58:33 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Up2yz-0004IL-AC for ged-emacs-devel@m.gmane.org; Tue, 18 Jun 2013 22:58:29 +0200 Original-Received: from localhost ([::1]:58321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Up2yy-0000ct-P0 for ged-emacs-devel@m.gmane.org; Tue, 18 Jun 2013 16:58:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Up2BJ-0008Ge-HR for emacs-devel@gnu.org; Tue, 18 Jun 2013 16:07:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Up2BG-0004Jj-DE for emacs-devel@gnu.org; Tue, 18 Jun 2013 16:07:09 -0400 Original-Received: from mail-vc0-f175.google.com ([209.85.220.175]:44447) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Up2BG-0004JC-7q for emacs-devel@gnu.org; Tue, 18 Jun 2013 16:07:06 -0400 Original-Received: by mail-vc0-f175.google.com with SMTP id hr11so3214205vcb.20 for ; Tue, 18 Jun 2013 13:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Ao7vX6LgMiAqxIrP+/DOTlbVArU7EULafv8An8oLT9c=; b=AFwJNQdYswBvOGaSvTrocMoQg1qIlFjnXhLSbrEGReF/CK9CNXxn3+Y8wG2TyXaLy/ YpLR4R7hpDYLlqW4qjUWVOdBZgZqyyUIiF/N+c5JszO5gQaIHTeMsvQDcT4S5ewwrk8/ EmsvPpNhwYalKDxv0kq0BP1lLzStU+90eaL9US7K8HCUtwsibLo3tFHVHBP355HgjhjM OJhJ4AC5eaAUuXj9q8+KI2QKGj2xDonTStuZlLCgTL1eL1FBgrjZXI1BKjXdXCum/2G/ 2i4yMHtwyhlxSnvomoVUcNgka6/RNQADIl6cQnLf4pdJ7yB4Z6+jp0JgaMmPNIVm9mYs fQAw== X-Received: by 10.52.21.232 with SMTP id y8mr1945833vde.6.1371586025702; Tue, 18 Jun 2013 13:07:05 -0700 (PDT) Original-Received: by 10.220.224.73 with HTTP; Tue, 18 Jun 2013 13:06:35 -0700 (PDT) In-Reply-To: <51C07898.6030409@lanl.gov> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.175 X-Mailman-Approved-At: Tue, 18 Jun 2013 16:58:25 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160612 Archived-At: --20cf3079babad754bf04df7341d2 Content-Type: text/plain; charset=UTF-8 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 > > (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. > --20cf3079babad754bf04df7341d2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Wh= at 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 singl= e-element functions with mapcar and functions operating on lists alternate,= e.g.

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

Basically I find e= macs 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).=C2=A0

But subjectively the actually important point= is the avoidance of variables, whose value changes after declaration (pres= erving a 1-on-1 relation between name and value during execution of the fun= ction). 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 fun= ction. With maphash and similiar that style (would that be functional style= ?) is not possible.

That said, I have just written a little priva= te-use library for such things. Bottomline, if I want to program more funct= ionally it doesn't even take much bending of elisp to do so.=C2=A0

kind regards, Klaus


2013/6/18 Davis Herr= ing <herring@lanl.gov>
> =C2=A0 (let (mapped-hash) (maphash (lam= bda (k v) (push (return-something k
> =C2=A0 =C2=A0 v) mapped-hash))) (mapcar 'modification-2 (mapcar &#= 39;modification-1
> =C2=A0 =C2=A0 mapped-hash)))

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

(let (mapped-hash)
=C2=A0 (maphash
=C2=A0 =C2=A0(lambda (k v)
=C2=A0 =C2=A0 =C2=A0(push (modification-2 (modification-1 (return-something= k v)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mapped-hash))
=C2=A0 =C2=A0hash)
=C2=A0 mapped-hash)

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

(let (mapped-hash)
=C2=A0 (maphash (lambda (k v) (push (return-something k v) mapped-hash)) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0hash)
=C2=A0 (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. =C2=A0If it appears too dense = or
too sparse, it is because mass-energy conversion has occurred during
shipping.

--20cf3079babad754bf04df7341d2--