From: Borkdude
Subject: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <1114597017.757781.264030@o13g2000cwo.googlegroups.com>
Hello,

Here I am again seeking help while I am working on my master thesis
project in Lisp. Although I think "Lisp is the language of loveliness",
sometimes I run into these adventures that take a lot of time. I get
lost into this microworld called MCL.

Here is a problem that has confused me a little:

Let listofnums be a list of lists of numbers. The next thing I wanted
to do was to cons another list of numbers in front of it, like this:

(let (listofnums '((1 2 3 4) (1 2 3 4)))
  (cons '(6 7 8 9) listofnums))

Now my listener begins to complain. Reducing the program to code that
generates the same error:

(let (listofnums '((1 2 3 4) (1 2 3 4)))
  listofnums)

> Error: While compiling an anonymous function :
> #1=(1 2 3 4) is not a symbol or lambda expression in the form (#1# (1
2 3 4)) .

What is wrong, how can I do what I intend to do?

Greetings,
Michiel

From: Raymond Wiker
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <86u0lsbjq2.fsf@raw.grenland.fast.no>
"Borkdude" <··············@gmail.com> writes:

> Hello,
>
> Here I am again seeking help while I am working on my master thesis
> project in Lisp. Although I think "Lisp is the language of loveliness",
> sometimes I run into these adventures that take a lot of time. I get
> lost into this microworld called MCL.
>
> Here is a problem that has confused me a little:
>
> Let listofnums be a list of lists of numbers. The next thing I wanted
> to do was to cons another list of numbers in front of it, like this:
>
> (let (listofnums '((1 2 3 4) (1 2 3 4)))
>   (cons '(6 7 8 9) listofnums))
>
> Now my listener begins to complain. Reducing the program to code that
> generates the same error:
>
> (let (listofnums '((1 2 3 4) (1 2 3 4)))
>   listofnums)

        You need an extra set of parentheses in let:

        (let ((listofnums ...))

        Further, if you are going to modify the list, you should *not*
use quote to build the list. 

>
>> Error: While compiling an anonymous function :
>> #1=(1 2 3 4) is not a symbol or lambda expression in the form (#1# (1
> 2 3 4)) .
>
> What is wrong, how can I do what I intend to do?
>
> Greetings,
> Michiel
>

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60
From: Kristian Elof Sørensen
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <426f6a6a$0$174$edfadb0f@dread11.news.tele.dk>
Borkdude wrote:
> Hello,
> 
> Here I am again seeking help while I am working on my master thesis
> project in Lisp. Although I think "Lisp is the language of loveliness",
> sometimes I run into these adventures that take a lot of time. I get
> lost into this microworld called MCL.
> 
> Here is a problem that has confused me a little:
> 
> Let listofnums be a list of lists of numbers. The next thing I wanted
> to do was to cons another list of numbers in front of it, like this:
> 
> (let (listofnums '((1 2 3 4) (1 2 3 4)))
>   (cons '(6 7 8 9) listofnums))

Try this instead:

(let (listofnums '((1 2 3 4) (1 2 3 4)))
   listofnums)

Let expects a list of symbol/value pairs or symbols. You have given it a 
list with two elements, a symbol listofnums and a list '((1 2 3 4) (1 2 
3 4))

	Krianist
From: Borkdude
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <1114601105.966468.12010@l41g2000cwc.googlegroups.com>
Ah yes of course, that is it.

Raymond, why not use a ' to construct the list? How should I be doing
it? It works the way it is supposed to do now though.
From: Raymond Wiker
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <86hdhsbe3r.fsf@raw.grenland.fast.no>
"Borkdude" <··············@gmail.com> writes:

> Ah yes of course, that is it.
>
> Raymond, why not use a ' to construct the list? How should I be doing
> it? It works the way it is supposed to do now though.

        Consider the following:

CL-USER> (defun foo ()
             '(1 2 3))
FOO
CL-USER> (foo)
(1 2 3)
CL-USER> (rplaca (foo) 1.5)
(1.5 2 3)
CL-USER> (foo)
(1.5 2 3)
CL-USER> 

        As you can see, modifying the list returned by foo has the
effect of modifying the behaviour of foo. If I use (list 1 2 3)
instead of '(1 2 3), this problem disappears.

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60
From: Pascal Bourguignon
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <87acnjn7xj.fsf@thalassa.informatimago.com>
"Borkdude" <··············@gmail.com> writes:

> Ah yes of course, that is it.
>
> Raymond, why not use a ' to construct the list? How should I be doing
> it? It works the way it is supposed to do now though.

QUOTE doesn't construct the list.

If you write (QUOTE (1 2 3))
you get the list (1 2 3) that was constructed by the _reader_ at read-time.

This list is given to the interpreter or compiler who don't have any
reason to not use it as is, so it'll be refered from the executable
code, be it interpreted or compiled.  

So at run-time, you might modify this list, that is you'll be
modifying the executable at run-time.


The functions used to _construct_ lists are CONS, LIST and LIST*.

QUOTE is to avoid _evaluation_, ie. to input _literal_ expressions.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
From: Borkdude
Subject: Re: consing a list-of-numbers to a list-of-lists-of-numbers
Date: 
Message-ID: <1114692557.900263.137210@g14g2000cwa.googlegroups.com>
Thanx. I think I was confused by some online tutorial in which (I
think) was claimed that (quote ...) is just an alternative notation for
(list ...) but apparently nil.