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

creating an arry(more than one dimension) with a variable.

2 views
Skip to first unread message

Rainer Joswig

unread,
Feb 20, 2000, 3:00:00 AM2/20/00
to
In article <MyKr4.101613$A5.19...@news1.rdc1.bc.home.com>, "Kee"
<k...@unforgettable.com> wrote:

> Creating array is done by using make-array function.
>
> I am having trouble using a variable to set dimensions.
> for example
> (setf *test* 3)
> (setf *test-array* (make-array *test*)) ==> creates array with one
> dimension
> (setf *test-array* (make-array '(*test* *test*)) ==>> gives me an error
> saying that *test* is an illegal dimension.
>
> is there a way to get around this problem?

Sure.

(setf *test-array* (make-array (list *test* *test*)))

You need to understand the basic evaluation rules.
Consult your nearest Common Lisp manual.

Rainer Joswig, ISION Internet AG, Harburger Schlossstraße 1,
21079 Hamburg, Germany, Tel: +49 40 77175 226
Email: rainer...@ision.de , WWW: http://www.ision.de/

Barry Margolin

unread,
Feb 21, 2000, 3:00:00 AM2/21/00
to
Someone else asked the same exact question on Friday in the "help with
arrays of variable size" thread. While I can understand not searching back
in the entire archives for an answer, when the question is asked TWO DAYS
earlier, I would expect a reader of this newsgroup to have seen it.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, 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.

Janos Blazi

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to
I think,
if you call make-array (list *test* *test*) then
(1) *test* is evaluated (probably twice, I am not sure)
(2) the function list is called with two arguments and returns a list;
this list is not evaluated
(3) the function make-array is called; the argument is the list returned
by list.

But if you issue make-array '(*test* *test*) then the quoted list ist not
evaluated and make-array receives as its arguments a list consisting of two
symbols instead of a list consisting of two numbers. Of course make-list
will not like that.

But be warned: I am learning Lisp myself and I am not sure that I am right.

Janos Blazi


Kee <k...@unforgettable.com> schrieb in im Newsbeitrag:
MyKr4.101613$A5.19...@news1.rdc1.bc.home.com...


> Creating array is done by using make-array function.
>
> I am having trouble using a variable to set dimensions.
> for example
> (setf *test* 3)
> (setf *test-array* (make-array *test*)) ==> creates array with one
> dimension
> (setf *test-array* (make-array '(*test* *test*)) ==>> gives me an error
> saying that *test* is an illegal dimension.
>
> is there a way to get around this problem?
>

> --
> Kee Nam.
> kn...@home.com
>
> --- Knowledge is Power -- Francis Bacon.
> --- Always Two There are... A Master and an Apprentice -- Yoda from Star
> Wars Episode I
>
>


-----= 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! =-----

Joe Marshall

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to

Janos Blazi <jbl...@netsurf.de> wrote in message
news:38b22...@goliath.newsfeeds.com...

> I think,
> if you call make-array (list *test* *test*) then
> (1) *test* is evaluated (probably twice, I am not sure)

Yes, twice. Fortunately it is a variable, so can evaluate it a million
times if you want.

> (2) the function list is called with two arguments and returns a list;
> this list is not evaluated

Correct. Lists are not passed to EVAL unless you explicitly ask.

> (3) the function make-array is called; the argument is the list returned
> by list.
>

> But if you issue make-array '(*test* *test*) then the quoted list is not


> evaluated and make-array receives as its arguments a list consisting of
two
> symbols instead of a list consisting of two numbers. Of course make-list
> will not like that.

I'd phrase it like this: If you call (make-array '(*test* *test*) ...),
remember
that '(*test* *test*) is simply shorthand for (quote (*test* *test*)). When
a quoted form is evaluated, the interpreter simply returns the object
quoted, i.e., the list with two references to the symbol *test*.

> But be warned: I am learning Lisp myself and I am not sure that I am
right.

Great so far!

0 new messages