all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Thorpe <rt@robertthorpeconsulting.com>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>
Cc: help-gnu-emacs@gnu.org
Subject: Re: I'd like to marry while and mapcar...
Date: Sat, 07 Feb 2015 21:09:38 +0000	[thread overview]
Message-ID: <87a90pfmy5.fsf@robertthorpeconsulting.com> (raw)
In-Reply-To: <bbd9d428-1385-4b4a-bc44-a32516e2f0b6@default> (message from Drew Adams on Fri, 6 Feb 2015 14:49:18 -0800 (PST))

Drew Adams <drew.adams@oracle.com> writes:

> FWIW, what you wrote in the first place, Marcin, is pretty
> much what I would do.  Call it Fortranesque, if you like.
> But it's classic Lispiness, IMO.  Lisp is not Haskell.

I agree.  I wrote a message yesterday saying many of the things Drew
said here, but I accidentally deleted the buffer.

Small loops of this sort are unlikely to be sources of error.
"Improving" them by phrasing them as map operations has little benefit.

I see two things wrong with the original code:
> (let (current-include (list-of-includes ()))
>   (while (setq current-include (get-TeX-macro-arguments "include"))
>     (setq list-of-includes (append list-of-includes current-include)))
>   list-of-includes)

Firstly, "push" is preferable for the 2nd setq as Drew mentions.

More importantly, the function get-TeX-macro-arguments is badly named.
It both gets arguments and it moves point across the buffer.  It's name
doesn't announce that it changes point.  It's a long name already, but
in my view it should announce that it changes point in the name.  It may
be best to have get-TeX-macro-arguments leave point unchanged and to
move point explicitly separately.  To do that, get-TeX-macro-arguments
could return the buffer position after the last macro it found.

From your comment about the loop being "un-lispy", I expect your absorbed
the idea that functional operations such as maps and reduces are
preferable to loops.  This is because loops often involve complex
mutation of state, and that's error prone.  It's most important to
improve situations where there's complex or hidden mutation of state.
In my view, simple loops are not really a problem.

In Drew's code he nreverse's the list at the end.  It would be best to
avoid that.  Does the subsequent code really need the list reversed?  Or
should that code really process the list in the opposite order?  If that
code is doing things the right way then what about
get-TeX-macro-arguments?  Should it move through the buffer from the
beginning to the end or from end to beginning?

BR,
Robert Thorpe



  reply	other threads:[~2015-02-07 21:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-06 12:56 I'd like to marry while and mapcar Marcin Borkowski
2015-02-06 13:18 ` Rasmus
2015-02-06 13:53   ` Marcin Borkowski
2015-02-06 14:14     ` Rasmus
2015-02-06 13:36 ` Eli Zaretskii
2015-02-06 13:50   ` Marcin Borkowski
2015-02-06 13:44 ` Doug Lewan
     [not found] ` <mailman.19396.1423229779.1147.help-gnu-emacs@gnu.org>
2015-02-06 16:25   ` Barry Margolin
2015-02-06 16:52     ` Pascal J. Bourguignon
2015-02-06 22:49 ` Drew Adams
2015-02-07 21:09   ` Robert Thorpe [this message]
2015-02-07 23:37 ` Thien-Thi Nguyen
     [not found] ` <mailman.19494.1423352465.1147.help-gnu-emacs@gnu.org>
2015-02-08  0:28   ` Emanuel Berg
     [not found] <mailman.19392.1423227427.1147.help-gnu-emacs@gnu.org>
2015-02-06 14:13 ` Pascal J. Bourguignon
2015-02-06 14:54 ` Joost Kremers
2015-02-06 17:47   ` Joost Kremers

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

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

  git send-email \
    --in-reply-to=87a90pfmy5.fsf@robertthorpeconsulting.com \
    --to=rt@robertthorpeconsulting.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.