Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multi-dimensional arrays question

0 views
Skip to first unread message

Paul Cochrane

unread,
Feb 9, 2002, 6:30:02 AM2/9/02
to

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

--
cochran...@physics.uq.edu.au

Quantum mechanics: the dreams stuff is made of.

Erik Naggum

unread,
Feb 9, 2002, 6:46:05 AM2/9/02
to
* Paul Cochrane <cochran...@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.

Karsten Poeck

unread,
Feb 9, 2002, 6:46:04 AM2/9/02
to
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" <cochran...@physics.uq.edu.au> wrote in message
news:qrr8nug...@term03.physics.uq.edu.au...

Siegfried Gonzi

unread,
Feb 9, 2002, 7:05:15 AM2/9/02
to

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

Frode Vatvedt Fjeld

unread,
Feb 9, 2002, 7:44:31 AM2/9/02
to
Siegfried Gonzi <siegfri...@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

Dr. Edmund Weitz

unread,
Feb 9, 2002, 10:15:45 AM2/9/02
to
Siegfried Gonzi <siegfri...@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/>

Brian P Templeton

unread,
Feb 10, 2002, 3:14:59 PM2/10/02
to
"Karsten Poeck" <vs1...@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" <cochran...@physics.uq.edu.au> wrote in message
> news:qrr8nug...@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 <b...@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

0 new messages