From: Paul Cochrane
Subject: multi-dimensional arrays question
Date: 
Message-ID: <qrr8nugaf9.fsf@term03.physics.uq.edu.au>
I have a question to do with (specifically) make-array.  I am trying
to create an array which is m by n where I have predefined m and n and
they are integers.  Here is a code fragment:

(setq m 11)
(setq n 11)

(setq A 
	(make-array '(m n)))

Unfortunately, the implementation of common lisp that I am using
(PowerLisp for PowerMac) keeps telling me that m and n should be
integers, i.e.

An error has occurred:
Argument is invalid -- should be an integer: m

when in fact they are, since if I do 

(typep m 'integer)

it returns true.

What is weird is that if I do this instead

(setq A
	(make-array '(11 11)))

it generates the array no worries.  What is also weird is if I make a
1D array by doing

(setq A
	(make-array m))

again, it works fine.

I'm really confused.  What am I doing wrong?  Is it my implementation
of clisp?  I must admit that I am very new to lisp as a language and
am aware that I may be doing something obviously wrong, however, I
have looked at HEAPS of documentation concerning the common lisp
language (even the "standard text" of Guy Steele) and can find no
joy.  Any help would be greatly appreciated.

TIA

Later

Paul

-- 
···············@physics.uq.edu.au

Quantum mechanics: the dreams stuff is made of.

From: Erik Naggum
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <3222243966998290@naggum.net>
* Paul Cochrane <···············@physics.uq.edu.au>
| (setq A (make-array '(m n)))

  Why do you quote the list of values?  Have you tried to evaluate that
  list by itself?  What would you normally do to get a list that contains
  the values of two variables m and n, not just the symbols?

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.
From: Karsten Poeck
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <a4326b$dps$1@news.wanadoo.es>
Try

(let ((n 10)
      (m 10))
  (make-array (list n m)))

By using the quote in '(m n) you are passing the symbol m not the variable m

Karsten

"Paul Cochrane" <···············@physics.uq.edu.au> wrote in message
···················@term03.physics.uq.edu.au...
>
> I have a question to do with (specifically) make-array.  I am trying
> to create an array which is m by n where I have predefined m and n and
> they are integers.  Here is a code fragment:
>
> (setq m 11)
> (setq n 11)
>
> (setq A
> (make-array '(m n)))
>
From: Brian P Templeton
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <87r8ntrv10.fsf@tunes.org>
"Karsten Poeck" <······@terra.es> writes:

> Try
> 
> (let ((n 10)
>       (m 10))
>   (make-array (list n m)))
> 
> By using the quote in '(m n) you are passing the symbol m not the variable m
> 
...Yes, but the explanation would be a little clearer with `the
variable m' replaced with `the value of the variable m'.

> Karsten
> 
> "Paul Cochrane" <···············@physics.uq.edu.au> wrote in message
> ···················@term03.physics.uq.edu.au...
>>
>> I have a question to do with (specifically) make-array.  I am trying
>> to create an array which is m by n where I have predefined m and n and
>> they are integers.  Here is a code fragment:
>>
>> (setq m 11)
>> (setq n 11)
>>
>> (setq A
>> (make-array '(m n)))
>>
> 
> 

-- 
BPT <···@tunes.org>	    		/"\ ASCII Ribbon Campaign
backronym for Linux:			\ / No HTML or RTF in mail
	Linux Is Not Unix			 X  No MS-Word in mail
Meme plague ;)   --------->		/ \ Respect Open Standards
From: Siegfried Gonzi
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <3C65107B.BE22A4CC@kfunigraz.ac.at>
Paul Cochrane wrote:

> I have a question to do with (specifically) make-array.  I am trying
> to create an array which is m by n where I have predefined m and n and
> they are integers.  Here is a code fragment:
>
> (setq m 11)
> (setq n 11)
>
> (setq A
>         (make-array '(m n)))
>
> Unfortunately, the implementation of common lisp that I am using
> (PowerLisp for PowerMac) keeps telling me that m and n should be
> integers, i.e.

First of all, you should try to get the student edition (the student
edition prices are really reasonably) of Lisp for the Mac from Digitool.
PowerLisp is not an example for a good and efficient Lisp implementation.

That said:

(setq m 11)
(setq n 11)

(setq a (make-array (list m n)))

will serve you. Why '(m n) actually is not applicable is out of my vision.
Sometimes Lisp is really only usable as trial-and-error.


S. Gonzi
From: Frode Vatvedt Fjeld
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <2hheoqj040.fsf@vserver.cs.uit.no>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> (setq m 11)
> (setq n 11)
>
> (setq a (make-array (list m n)))

As an example, (let ((m 11) (n 11)) (make-array (list m n))) serves
better, IMHO. Or perhaps (let (...) (make-array `(,m ,n))) gives more
visual clues as to why '(m n) doesn't work, at least to those familiar
with the backquote syntax.

> Why '(m n) actually is not applicable is out of my vision.

Perhaps if you look up the lisp concepts "variable" and "symbol", and
took the trouble to understand the basic evaluation rules, things will
become more clear.

> Sometimes Lisp is really only usable as trial-and-error.

I would attribute this feature not so much to lisp as to those who try
to use it ;)

-- 
Frode Vatvedt Fjeld
From: Dr. Edmund Weitz
Subject: Re: multi-dimensional arrays question
Date: 
Message-ID: <m3n0yiofdq.fsf@bird.agharta.de>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> That said:
> 
> (setq m 11)
> (setq n 11)
> 
> (setq a (make-array (list m n)))
> 
> will serve you. Why '(m n) actually is not applicable is out of my
> vision.  Sometimes Lisp is really only usable as trial-and-error.

The whole purpose of the QUOTE operator is _not_ to evaluate its
arguments. So, '(M N) returns (M N). If it were _evaluated_ to (11 11)
- which you seem to expect - why would you want to QUOTE it?

If you're not happy with using the LIST function you might try
something spiffy like `(,M ,N) - note that this is a backquote, not a
normal quote - which means "do not evaluate the whole form but
evaluate the subforms M and N."

-- 

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://agharta.de/cookbook/>