From: Andy Reiter
Subject: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <d4b78695.0207111403.53611afe@posting.google.com>
CMU Common Lisp release x86-linux 2.4.19  8 February 2000 build 455,
running on genine
Send bug reports and questions to your local CMU CL maintainer, 
or to ········@debian.org
or to ··········@cons.org. (prefered)

type (help) for help, (quit) to exit, and (demo) to see the demos

Loaded subsystems:
    Python 1.0, target Intel x86
    CLOS based on PCL version:  September 16 92 PCL (f)
    CLX X Library MIT R5.02
    Hemlock 3.5
    Defsystem Mar 13 1995

* (defun count-down (count)
    (if (zerop count)
	nil
      (cons count (count-down (- count 1)))))

COUNT-DOWN
* (count-down 5)

(5 4 3 2 1)
* (defun flatten-list (lst)
    (values (car lst) (flatten-list (cdr lst))))

FLATTEN-LIST
* (flatten-list (count-down 5))
[GC threshold exceeded with 2,001,624 bytes in use.  Commencing GC.]
[GC completed with 1,885,104 bytes retained and 116,520 bytes freed.]
[GC will next occur when at least 3,885,104 bytes are in use.]
.
[snip lots of similar lines]
.
[GC threshold exceeded with 32,287,904 bytes in use.  Commencing GC.]
[GC completed with 32,298,184 bytes retained and -10,280 bytes freed.]
[GC will next occur when at least 34,298,184 bytes are in use.]

Process inferior-lisp segmentation fault

---------------------

What is wrong with my toy code? I have just finished reading Graham's
CL, and
wanted to do a refresh before I started reading OnLisp. Then
everything I
write starts crashing.

From: Joel Ray Holveck
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <y7chej5byh4.fsf@sindri.juniper.net>
> * (defun flatten-list (lst)
>     (values (car lst) (flatten-list (cdr lst))))

This looks like a homework exercise.  If you're learning Lisp, you may
benefit from learning about a few of the debugging facilities in
Lisp.

You may want to
  (dribble "/tmp/foo")
  (trace flatten-list)

Let it run for a second, break it (control C), type "(dribble)" to
close /tmp/foo, and look at the start of /tmp/foo.

DRIBBLE is handy if you're not using Emacs's ILisp.  TRACE is
extremely useful for all sorts of problems.

A well-placed DESCRIBE can be useful if you're not sure what a
variable holds, or INSPECT if you need to traverse a complex data
structure.

The CMUCL debugger is intimidating, but very useful.  Once you've
gotten the hang of it, then you can start using BREAK, STEP, and
ASSERT usefully.

All the functions I've mentioned above are described in both Common
Lisp: The Language (2nd ed), and the Common Lisp HyperSpec.  I'd
recommend keeping both readily available, at least bookmarked in a web
browser.

Once you've gotten more advanced (say, six months to a year) and are
trying to tune the speed of your programs in the real world, then look
at the profiling capabilities that CMUCL provides.  (They should be in
the CMUCL docs, but the functions are all in the PROFILE package:
PROFILE, PROFILE-ALL, UNPROFILE, and REPORT-TIME.)  If you're really
up for a challenge, you may find the output of DISASSEMBLE
interesting, but it's infrequently terribly useful for debugging Lisp
programs.

Hope this helps,
joelh
From: Thaddeus L Olczyk
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <hnhsiuo2b0dicjnanffo937pui6gvbpqi3@4ax.com>
On 11 Jul 2002 17:07:19 -0700, Joel Ray Holveck <·····@juniper.net>
wrote:

>The CMUCL debugger is intimidating, but very useful.  Once you've
>gotten the hang of it, then you can start using BREAK, STEP, and
>ASSERT usefully.
Thus LispDebug.
From: ······@panix.com
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <lhrlm8h28q7.fsf@panix2.panix.com>
·······@flop.co.uk (Andy Reiter) writes:
> What is wrong with my toy code?

   Your flatten-list is wrong.

(defun flatten-list (lst)
  (cond 
   ((atom lst) (list lst))
   ((listp lst) 
    (let ((flist nil))
      (dolist (l lst)
        (setf flist (append flist (flatten-list l))))
      flist))))

   This could be better by keeping the list reversed and
then finishing with an nreverse. Left as an exercise.

;; GNU CLISP 2.27 (released 2001-07-17)
[2]> (flatten-list '(1 2 3 4 (5 6) (((((7 8 9)))))))
(1 2 3 4 5 6 7 8 9)

harley.
From: Dan Corkill
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <3D2E0864.657C5C9C@attbi.com>
> * (defun flatten-list (lst)
>     (values (car lst) (flatten-list (cdr lst))))

Your flatten-list function does not have a terminating
(ground condition) case, so it will continue recursive
calls to flatten-list until the Lisp system runs out of
resources.  Some Lisps handle this lack of resources
more gracefully than others.  Try:

(defun flatten-list (lst)
   (when (consp lst) (values (car lst) (flatten-list cdr lst))))
From: Kaz Kylheku
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <agl8qk$rnn$2@luna.vcn.bc.ca>
In article <····························@posting.google.com>, Andy Reiter wrote:
> CMU Common Lisp release x86-linux 2.4.19  8 February 2000 build 455,
> running on genine
> Send bug reports and questions to your local CMU CL maintainer, 
> or to ········@debian.org
> or to ··········@cons.org. (prefered)
> 
> type (help) for help, (quit) to exit, and (demo) to see the demos
> 
> Loaded subsystems:
>     Python 1.0, target Intel x86
>     CLOS based on PCL version:  September 16 92 PCL (f)
>     CLX X Library MIT R5.02
>     Hemlock 3.5
>     Defsystem Mar 13 1995
> 
> * (defun count-down (count)
>     (if (zerop count)
> 	nil
>       (cons count (count-down (- count 1)))))
> 
> COUNT-DOWN
> * (count-down 5)
> 
> (5 4 3 2 1)
> * (defun flatten-list (lst)
>     (values (car lst) (flatten-list (cdr lst))))

Three remarks. Firstly, Lisp is not Scheme.  In Lisp, you can use
a symbol named ``list'' as a variable name; you don't have to invent spellings
like ``lst''. Secondly, you have no termination test in this recursion;
if lst is nil, which it eventually will be when the end of the list is
found, you end up with runaway recursion.
Lastly, note that the values function only takes the first value from
each of its multiple values arguments. So that

  (values (values 1 2) (values 3 4))

is equivalent to

  (values 1 3)

not to

  (values 1 2 3 4)

Consequently, your function will not expand the list into multiple  values.
I'm guessing that what you are looking for is:

  (apply #'values (count-down 5))

Hope this helps.
From: Marcin Tustin
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <yztbbs9be9sv.fsf@werewolf.i-did-not-set--mail-host-address--so-shoot-me>
Kaz Kylheku <···@ashi.footprints.net> writes:

> In article <····························@posting.google.com>, Andy Reiter wrote:
> > CMU Common Lisp release x86-linux 2.4.19  8 February 2000 build 455,
> > running on genine
> > Send bug reports and questions to your local CMU CL maintainer, 
> > or to ········@debian.org
> > or to ··········@cons.org. (prefered)
> > 
> > type (help) for help, (quit) to exit, and (demo) to see the demos
> > 
> > Loaded subsystems:
> >     Python 1.0, target Intel x86
> >     CLOS based on PCL version:  September 16 92 PCL (f)
> >     CLX X Library MIT R5.02
> >     Hemlock 3.5
> >     Defsystem Mar 13 1995
> > 
> > * (defun count-down (count)
> >     (if (zerop count)
> > 	nil
> >       (cons count (count-down (- count 1)))))
> > 
> > COUNT-DOWN
> > * (count-down 5)
> > 
> > (5 4 3 2 1)
> > * (defun flatten-list (lst)
> >     (values (car lst) (flatten-list (cdr lst))))
> 
> Three remarks. Firstly, Lisp is not Scheme.  In Lisp, you can use
> a symbol named ``list'' as a variable name; you don't have to invent
> spellings
> like ``lst''.

    Sure it's legal, but is it moral?
    
--
Screw you, hippy.
From: Kaz Kylheku
Subject: Re: Simple code crashes both CMUCL and CLISP.
Date: 
Message-ID: <agpul1$d5l$1@luna.vcn.bc.ca>
In article
<················@werewolf.i-did-not-set--mail-host-address--so-shoot-me>,
Marcin Tustin wrote:
> Kaz Kylheku <···@ashi.footprints.net> writes:
>> In article <····························@posting.google.com>, Andy Reiter wrote:
>> > * (defun flatten-list (lst)
>> >     (values (car lst) (flatten-list (cdr lst))))
>> 
>> Three remarks. Firstly, Lisp is not Scheme.  In Lisp, you can use
>> a symbol named ``list'' as a variable name; you don't have to invent
>> spellings
>> like ``lst''.
> 
>     Sure it's legal, but is it moral?

You mean, does it encroach on someone's rights or freedoms?