[Top][All Lists]

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

Re: I'd like to marry while and mapcar...

From: Robert Thorpe
Subject: Re: I'd like to marry while and mapcar...
Date: Sat, 07 Feb 2015 21:09:38 +0000

Drew Adams <address@hidden> 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?

Robert Thorpe

reply via email to

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