From: Chris Gehlker
Subject: Newbie array construction question
Date: 
Message-ID: <BA0DB260.23DCA%gehlker@fastq.com>
Given:

(setf three 3)
And
(setf four 4)

This works:
(setf my-array (make-array '(3 4)))

As does this:
(setf my-array (make-array (list three four)))

But not:
(setf my-array (make-array '(three four)))

Furthermore, two implementations complain that 'three' is not of type real,
but (type-of three) == (type-of 3) = FIXNUM which would seem to be what one
would want for an array dimension.

Would someone please explain what's going on here?



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

From: Richard Krush
Subject: Re: Newbie array construction question
Date: 
Message-ID: <87hedz8pex.fsf@olimp.localnet>
Chris Gehlker <·······@fastq.com> writes:

> Given:
>
> (setf three 3)
> And
> (setf four 4)
>
> This works:
> (setf my-array (make-array '(3 4)))
>
> As does this:
> (setf my-array (make-array (list three four)))
>
> But not:
> (setf my-array (make-array '(three four)))
>
> Furthermore, two implementations complain that 'three' is not of type real,
> but (type-of three) == (type-of 3) = FIXNUM which would seem to be what one
> would want for an array dimension.
>
> Would someone please explain what's going on here?
>

I'm probably not the best person to teach anyone, so you might want to wait
for others to respond, but I will put my two cents anyway.

The reason this happens is that '(THREE FOUR) is not the same as (LIST THREE
FOUR).  In the latter case, LIST is a function, so it follows the rules of
evaluation for function calls [1], which states that the arguments must be
evaluated before the call occurs.  So, in practice, when you enter (LIST THREE
FOUR), what is happening is that the CL evaluator looks up the bindings of
THREE and FOUR before calling LIST, so in effect what actually happens is as
if you entered (LIST 3 4).  However, in the case of '(THREE FOUR), which is
actually an abbreviation of (QUOTE THREE FOUR).  The important thing to note
here is that QUOTE is _NOT_ a function, but rather a so-called "special
form".  The difference between functions and special forms is that the latter
can have special syntax, special evaluation, or both [2].  In particular, the
special form QUOTE _does not evaluate its argument_, which means that whatever
you pass to QUOTE is returned without checking if it's a variable, list,
vector, etc.  This can be best demonstrated with a little example (lines
starting with an asterisk [*] denote my input, lines without the asterisk
denote what Lisp returns):

  * (setq foo 5)              ; note that SETQ is a special form too
  FOO
  * FOO
  5
  * (+ 5 foo)                 ; + is a function, so FOO is evaluated
  10
  * (type-of foo)             ; TYPE-OF is also a function
  FIXNUM                      ; FOO is FIXNUM because it's bound to 5
  * (type-of 'foo)
  SYMBOL                      ; since FOO is not evaluated, it's a symbol
  *

Returning to your example, when you say '(THREE FOUR), what is actually
returned is not a list of two numbers, 3 and 4, but a list of two symbols,
THREE and FOUR.  If you would like a more detailed explanation, check out
section 3.1 of CLHS [*].

  [1] Section 3.1.2.1.2.3 in the Common Lisp Hyperspec [*]
  [2] Section 3.1.2.1.2.1 of CLHS
  [*] http://www.lispworks.com/reference/HyperSpec/Front/index.htm

Hope I was of any help!

Richard

-- 
"I know not with what weapons World War III will be fought, but World War
IV will be fought with sticks and stones." -- Albert Einstein
From: Geoffrey Summerhayes
Subject: Re: Newbie array construction question
Date: 
Message-ID: <B5_F9.6569$Nm.1068113@news20.bellglobal.com>
"Chris Gehlker" <·······@fastq.com> wrote in message
···························@fastq.com...
> This works:
> (setf my-array (make-array '(3 4)))
>
> As does this:
> (setf my-array (make-array (list three four)))
>
> But not:
> (setf my-array (make-array '(three four)))

(QUOTE object) returns object without evaluating it.
You are passing a list of the symbols three and four, not the numbers.

> '(three four)
(THREE FOUR)
> (list 'three 'four)
(THREE FOUR)
> (list three four)
(3 4)

--
Geoff
From: Barry Margolin
Subject: Re: Newbie array construction question
Date: 
Message-ID: <STZF9.17$9N6.1641@paloalto-snr1.gtei.net>
In article <······················@fastq.com>,
Chris Gehlker  <·······@fastq.com> wrote:
>Given:
>
>(setf three 3)
>And
>(setf four 4)
>
>This works:
>(setf my-array (make-array '(3 4)))
>
>As does this:
>(setf my-array (make-array (list three four)))
>
>But not:
>(setf my-array (make-array '(three four)))

MAKE-ARRAY requires a list of numbers as the size.  You gave it a list of
symbols (quoting the list prevents the symbols from being evaluated as
variables).

>Furthermore, two implementations complain that 'three' is not of type real,
>but (type-of three) == (type-of 3) = FIXNUM which would seem to be what one
>would want for an array dimension.

What is (type-of 'three)?

>Would someone please explain what's going on here?

It seems like you don't understand the evaluation model of Lisp, it has
nothing to do with MAKE-ARRAY.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Steven M. Haflich
Subject: Re: Newbie array construction question
Date: 
Message-ID: <3DE86BCB.9080704@alum.mit.edu>
Chris Gehlker wrote:
> (setf three 3)
> And
> (setf four 4)
> 
> This works:
> (setf my-array (make-array '(3 4)))
> 
> As does this:
> (setf my-array (make-array (list three four)))
> 
> But not:
> (setf my-array (make-array '(three four)))
> 
> Furthermore, two implementations complain that 'three' is not of type real,
> but (type-of three) == (type-of 3) = FIXNUM which would seem to be what one
> would want for an array dimension.
> 
> Would someone please explain what's going on here?

<1> (setf three 3)
3
<2> (type-of 'three)
symbol
<3> (type-of three)
fixnum

The token "three" denotes a symbol.  In Common Lisp, variables
of various types are named by symbols, but that symbol is not
the same thing as that variable.

list is a function, and functions evaluate their arguments.
So is make-array, but the first argument to make-array in

   (make-array '(three four) ...

is a list of two symbols.  In

   (make-array (list three four) ...

it is a list of two integers.
From: Chris Gehlker
Subject: Re: Newbie array construction question
Date: 
Message-ID: <BA0E0514.23DDA%gehlker@fastq.com>
On 11/30/02 1:00 AM, in article ················@alum.mit.edu, "Steven M.
Haflich" <·················@alum.mit.edu> wrote:

> Chris Gehlker wrote:

>> Would someone please explain what's going on here?

Thanks Barry, Geoffrey, Richard and Steven. It's clear now.

<whine> If only the implementations had said "'THREE is not of type REAL"
rather than "THREE is not of type REAL" it would have been clear from the
first. </whine>.

Anyway, you were all very good at explaining what was going on. Thanks
again.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Coby Beck
Subject: Re: Newbie array construction question
Date: 
Message-ID: <asae3u$2apk$1@otis.netspace.net.au>
"Chris Gehlker" <·······@fastq.com> wrote in message
···························@fastq.com...
> On 11/30/02 1:00 AM, in article ················@alum.mit.edu, "Steven M.
> Haflich" <·················@alum.mit.edu> wrote:
>
> > Chris Gehlker wrote:
>
> >> Would someone please explain what's going on here?
>
> Thanks Barry, Geoffrey, Richard and Steven. It's clear now.
>
> <whine> If only the implementations had said "'THREE is not of type REAL"
> rather than "THREE is not of type REAL" it would have been clear from the
> first. </whine>.

That would not be the right thing at all, you don't understand what you are
asking for.  But now you know what to look for, you won't make that mistake
again.

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Chris Gehlker
Subject: Re: Newbie array construction question
Date: 
Message-ID: <BA0E2B04.23DE4%gehlker@fastq.com>
On 11/30/02 6:25 AM, in article ·············@otis.netspace.net.au, "Coby
Beck" <·····@mercury.bc.ca> wrote:

> 
> "Chris Gehlker" <·······@fastq.com> wrote in message
> ···························@fastq.com...
>> On 11/30/02 1:00 AM, in article ················@alum.mit.edu, "Steven M.
>> Haflich" <·················@alum.mit.edu> wrote:
>> 
>>> Chris Gehlker wrote:
>> 
>>>> Would someone please explain what's going on here?
>> 
>> Thanks Barry, Geoffrey, Richard and Steven. It's clear now.
>> 
>> <whine> If only the implementations had said "'THREE is not of type REAL"
>> rather than "THREE is not of type REAL" it would have been clear from the
>> first. </whine>.
> 
> That would not be the right thing at all, you don't understand what you are
> asking for.  But now you know what to look for, you won't make that mistake
> again.

Too right. After I posted that whine,  I took my dog for a walk and somehow,
by the time I got back, I understood why the current behavior is actually
the right thing. What I want is magic-quote which returns either it's
argument literally or evaluated depending on what I meant. Is that too much
to ask for in an AI language?



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Joost Kremers
Subject: Re: Newbie array construction question
Date: 
Message-ID: <slrnauhnmq.alo.joostkremers@catv0149.extern.kun.nl>
Chris Gehlker wrote:
> Too right. After I posted that whine,  I took my dog for a walk and somehow,
> by the time I got back, I understood why the current behavior is actually
> the right thing. What I want is magic-quote which returns either it's
> argument literally or evaluated depending on what I meant. Is that too much
> to ask for in an AI language?

since even entities that exhibit natural intelligence (or something
like it) still have trouble mind-reading, i think the answer to that
question is 'yes'... ;-)

-- 
Joost Kremers		http://baserv.uci.kun.nl/~jkremers
lrwxrwxrwx  1 root  root       11 nov  2 21:37 vi -> emacsclient*
From: Chris Gehlker
Subject: Re: Newbie array construction question
Date: 
Message-ID: <BA0E52E3.23DE9%gehlker@fastq.com>
On 11/30/02 8:57 AM, in article
···························@catv0149.extern.kun.nl, "Joost Kremers"
<············@yahoo.com> wrote:

> Chris Gehlker wrote:
>> Too right. After I posted that whine,  I took my dog for a walk and somehow,
>> by the time I got back, I understood why the current behavior is actually
>> the right thing. What I want is magic-quote which returns either it's
>> argument literally or evaluated depending on what I meant. Is that too much
>> to ask for in an AI language?
> 
> since even entities that exhibit natural intelligence (or something
> like it) still have trouble mind-reading, i think the answer to that
> question is 'yes'... ;-)

Too bad. I was thinking of !' for an abbreviation. The "!" sort of looks
like a magic wand.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Pascal Costanza
Subject: Re: Newbie array construction question
Date: 
Message-ID: <asbcs9$3a6$1@newsreader2.netcologne.de>
Chris Gehlker wrote:

> Too right. After I posted that whine,  I took my dog for a walk and somehow,
> by the time I got back, I understood why the current behavior is actually
> the right thing. What I want is magic-quote which returns either it's
> argument literally or evaluated depending on what I meant. Is that too much
> to ask for in an AI language?
> 

Perhaps backquote is what you are looking for. `(one two ,three) is 
roughly the same as (list 'one 'two three).


Pascal

-- 
Given any rule, however �fundamental� or �necessary� for science, there 
are always circumstances when it is advisable not only to ignore the 
rule, but to adopt its opposite. - Paul Feyerabend
From: sv0f
Subject: Re: Newbie array construction question
Date: 
Message-ID: <none-0112021336500001@129.59.212.53>
In article <······················@fastq.com>, Chris Gehlker
<·······@fastq.com> wrote:

>Too right. After I posted that whine,  I took my dog for a walk and somehow,
>by the time I got back, I understood why the current behavior is actually
>the right thing.

Can I borrow your dog?

I'm currently beating my head against several recalcitrant programming
problems and my cat's not being particularly helpful.

;-)