From: arnuld
Subject: from source-code CLISP-2.38
Date: 
Message-ID: <1151603206.802339.198290@j72g2000cwa.googlegroups.com>
hai folks

i was browsing through the source-code of CLISP 2.38, in the file named
"LOOP.lisp" i came across the following function:

(defun destructure-vars (pattern)
  (let ((vars '()))
    (labels ((accumulate (pattern)
               (cond ((null pattern))
                     ((atom pattern) (push pattern vars))
                     (t
                       (accumulate (car pattern))
                       (accumulate (cdr pattern))))))
      (accumulate pattern))
    (nreverse vars)))

;; OUTPUT
(destructure-vars '(1 2 3 4))                ==>       '(1 2 3 4)
(destructure-vars '(1 (((2))) (((3)) 4))) ==>        '(1 2 3 4)

ok i got it this function destructures the elements of a tree into a
single list, BUT, then i took out "accumulate" from the "labels" and
tried it as a stand-alone function.


(defun accumulate (pattern)
  (let ((vars '()))
    (cond ((null pattern))
	  ((atom pattern) (push pattern vars))
	  (t (accumulate (car pattern))
	     (accumulate (cdr pattern))))
    (nreverse vars)))


;; OUTPUT

(accumulate '(1 2 3 4))                    ==>   NIL
(accumulate '(1 (((2))) (((3)) 4)))     ==>   NIL

why it does not produce '(1 2 3 4) even though it's same (only "labels"
is not here)

why two same functions are producing different outputs?

how can i make 2nd one to produce same output as 1st one. i have Debian
"Sarge" running with CLISP - 2.33.2. (i also have SBCL 0.9.11)

thanks

-- arnuld

From: micromoog
Subject: Re: from source-code CLISP-2.38
Date: 
Message-ID: <1151605229.006880.287740@d56g2000cwd.googlegroups.com>
arnuld wrote:
> hai folks
>
> i was browsing through the source-code of CLISP 2.38, in the file named
> "LOOP.lisp" i came across the following function:
>
> (defun destructure-vars (pattern)
>   (let ((vars '()))
>     (labels ((accumulate (pattern)
>                (cond ((null pattern))
>                      ((atom pattern) (push pattern vars))
>                      (t
>                        (accumulate (car pattern))
>                        (accumulate (cdr pattern))))))
>       (accumulate pattern))
>     (nreverse vars)))
>
> ;; OUTPUT
> (destructure-vars '(1 2 3 4))                ==>       '(1 2 3 4)
> (destructure-vars '(1 (((2))) (((3)) 4))) ==>        '(1 2 3 4)
>
> ok i got it this function destructures the elements of a tree into a
> single list, BUT, then i took out "accumulate" from the "labels" and
> tried it as a stand-alone function.
>
>
> (defun accumulate (pattern)
>   (let ((vars '()))
>     (cond ((null pattern))
> 	  ((atom pattern) (push pattern vars))
> 	  (t (accumulate (car pattern))
> 	     (accumulate (cdr pattern))))
>     (nreverse vars)))
>
>
> ;; OUTPUT
>
> (accumulate '(1 2 3 4))                    ==>   NIL
> (accumulate '(1 (((2))) (((3)) 4)))     ==>   NIL
>
> why it does not produce '(1 2 3 4) even though it's same (only "labels"
> is not here)
>
> why two same functions are producing different outputs?
>
> how can i make 2nd one to produce same output as 1st one. i have Debian
> "Sarge" running with CLISP - 2.33.2. (i also have SBCL 0.9.11)
>
> thanks
>
> -- arnuld


In the first case, when accumulate recursively calls itself, it's still
all within the context of the same let.  In the 2nd case, the let
occurs within accumulate, so with each recursive call you're defining a
new instance of vars.

This is why the CLISP code is written that way; the outer function
destructive-vars is called once, so the let environment is only created
once, but the inner function accumulate is called many times inside the
same environment.
From: arnuld
Subject: Re: from source-code CLISP-2.38
Date: 
Message-ID: <1151605905.173631.29260@d56g2000cwd.googlegroups.com>
micromoog wrote:

> In the first case, when accumulate recursively calls itself, it's still
> all within the context of the same let.  In the 2nd case, the let
> occurs within accumulate, so with each recursive call you're defining a
> new instance of vars.
>
> This is why the CLISP code is written that way; the outer function
> destructive-vars is called once, so the let environment is only created
> once, but the inner function accumulate is called many times inside the
> same environment.

WOW!, i always thought "labels" is worthless. i am wrong.

anyway, after all this do you think i carry the ability to contribute
to Common Lisp  community (by doing *coding* for some Open Source
software).

any views?

thanks for your time

--arnuld
From: Fred Gilham
Subject: Re: from source-code CLISP-2.38
Date: 
Message-ID: <u7lkrfa640.fsf@snapdragon.csl.sri.com>
"arnuld" <·······@gmail.com> writes:

>
> WOW!, i always thought "labels" is worthless. i am wrong.
>
> anyway, after all this do you think i carry the ability to contribute
> to Common Lisp  community (by doing *coding* for some Open Source
> software).
>
> any views?
>
> thanks for your time

You seem to be able to read code, experiment, ask questions about
things you don't understand, and profit from the whole experience.

You seem eminently qualified to benefit some open-source community.
Just find a project that interests you and pitch in!

-- 
Fred Gilham                                  ······@csl.sri.com
"Come to me, all who labor and are heavy laden, and I will give you
rest.  Take my yoke upon you, and learn from me, for I am gentle and
lowly in heart, and you will find rest for your souls.  For my yoke
is easy, and my burden is light."               --Jesus of Nazareth
From: arnuld
Subject: Re: from source-code CLISP-2.38
Date: 
Message-ID: <1151648484.074924.153710@m73g2000cwd.googlegroups.com>
Fred Gilham wrote:
> You seem to be able to read code, experiment, ask questions about
> things you don't understand, and profit from the whole experience.
>
> You seem eminently qualified to benefit some open-source community.
> Just find a project that interests you and pitch in!

thanks Fred, i will start my journy into "real-life programming" now
:-)


thank you

-- arnuld