Re: newbie exploring better ways



On Jan 30, 12:46 am, Kent M Pitman <pit...@xxxxxxxxxxx> wrote:
The reason I mention all of this is that Griff's remarks here might lead
you into a recursive solution, and I'm not sure that's a good idea in CL
for this particular problem.

I do not see anything wrong with Griff's suggestion, or with the
recursion entailed (pun not intended). And at least when I look at it
implemented, it is clearly tail recursive (or rather tail recursive,
modulo cons, which for any decent compiler is tail recursive), any
compiler worth it's salt will clean that up nicely. Further, I think
Griff's suggestion is one of the cleanest solutions to this problem
(presuming it's a pedagogical exercise which outlaws the use of the
REMOVE, etc.)

Presuming this is a pedagogical exercise, I would assume that it's
being used to illustrate potential lisp iteration mechanisms, like CDR-
ing down a list, or a DO loop, etc. to the OP, a PUSH nested in a
DOLIST is almost never what is needed/wanted.

And as Ken acknowledges, Griff's suggestion is even cleaner than the
LOOP version (and if there's a clean LOOP solution I trust Ken to find
it), in my implementation of Griff's suggestion, it uses fewer
symbols, is easier to see what's going on, and as I said, any good
compiler should have those performing at that same efficiency,
possibly even faster with the recursive solution, because it doesn't
require a flag to signal done.

As others have pointed out, to the OP, it would be good to contrast,
the various solutions, the original (DOLIST PUSH) is pure side effect
plus a reverse, a DO with a REVERSE at the end has no side effects,
but the disadvantage of the extra traversal for the REVERSE, the LOOP
is single iteration, but has a flag, and so it's quite as functional
in style as Griff's suggestion, which is also single iteration.
.



Relevant Pages

  • Re: Problems with differences between system and exec functions
    ... Just to be sure I didn't overlook your suggestion given that I've tried ... If xulrunner-bin examines its argv, ... xulrunner-bin *starts* (and by that time execl has done its job ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.internals)
  • Re: malloc blocked on Linux
    ... "Shuqing Wu" writes: ... > Any suggestion? ... type 'thread apply all bt' at the gdb prompt and post the result! ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.questions)
  • Re: Spaces in file names
    ... The suggestion shown below won't work. ... As I said in theoriginal post, ... I'm not just adding an extension or something like ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.apps)
  • Re: Response to Karen and to Willem on recursive proofs
    ... >) int nFactorial ... The bits with 'max' are because the loop is a bit ... I agree that this does not need recursion and it is an elegant ... language proofs can be used, and I need to keep the language informal ...
    (comp.programming)
  • Re: StackOverflowException with attribute
    ... I figured that the recursion wasn't infinite. ... it would seem that the call to GetProperties on the ... You need to find some way to break this loop. ...
    (microsoft.public.dotnet.languages.csharp)