From: Nikon Sevast
Subject: Beginner question - designators
Date: 
Message-ID: <7h30ja$amq$1@nntp2.atl.mindspring.net>
In the process of learning Lisp, I came across the make-array function.  I
thought to make the dimensions of the array dependent on some variable
value, like:

(setq x 3)
(setq y 4)
(setq a (make-array '(x y)))

I get a "bad dimension" error.  I looked at the documentation for
make-array, and it mentions that the dimension argument is a designator for
a list of valid array dimensions.  Try as I may, I can't make sense of the
definition for a designator.  I thought the issue here might have to do with
type coercion...

Anyway, I'd appreciate any advice/help on understanding designators.

Nikon

From: R. Matthew Emerson
Subject: Re: Beginner question - designators
Date: 
Message-ID: <871zgq519e.fsf@nightfly.apk.net>
"Nikon Sevast" <···········@mindspam.com> writes:

> In the process of learning Lisp, I came across the make-array function.  I
> thought to make the dimensions of the array dependent on some variable
> value, like:
> 
> (setq x 3)
> (setq y 4)
> (setq a (make-array '(x y)))
> 
> I get a "bad dimension" error.  I looked at the documentation for
> make-array, and it mentions that the dimension argument is a designator for
> a list of valid array dimensions.

To see what is going on, experiment at the top level.
Evaluate the following and see what happens.
(setq x 3)
(setq y 4)
'(x y)
(list x y)

-matt
From: Nikon Sevast
Subject: Re: Beginner question - designators
Date: 
Message-ID: <7h34vr$8cn$1@nntp2.atl.mindspring.net>
Thank you!  Essentially, I get the same thing from '(x y) as I get from
(list 'x 'y), which is a list of symbols(?), not a list of fixnums as
make-array demands.  I hope I'm understanding that properly.  The designator
part just means that when it's evaluated, it has to come out to a list of
fixnums.  I could just as easily say
(setq r (list x y))
(setq a (make-array r))

The flow of this language is phenomenal.  If I can get past my ingrained
ideas, I'll be in good shape.  Thanks again

Nikon

>To see what is going on, experiment at the top level.
>Evaluate the following and see what happens.
>(setq x 3)
>(setq y 4)
>'(x y)
>(list x y)
>
>-matt
From: Marco Antoniotti
Subject: Re: Beginner question - designators
Date: 
Message-ID: <lwso95ic0e.fsf@copernico.parades.rm.cnr.it>
"Nikon Sevast" <···········@mindspam.com> writes:

> Thank you!  Essentially, I get the same thing from '(x y) as I get from
> (list 'x 'y), which is a list of symbols(?), not a list of fixnums as
> make-array demands.  I hope I'm understanding that properly.  The designator
> part just means that when it's evaluated, it has to come out to a list of
> fixnums.  I could just as easily say
> (setq r (list x y))
> (setq a (make-array r))

Not quite.

   (defvar a (make-array (list x y)))

Why you should use a DEFVAR *before* a SETQ/SETF is a little subtle :)
Just for the heck of it try the following APLish and quite memory
hungry FACTORIAL

(defun iota (n) (loop for i from 1 upto n collect i))

(defun factorial (n) (if (zerop n) 1 (reduce #'* (iota n))))

> The flow of this language is phenomenal.  If I can get past my ingrained
> ideas, I'll be in good shape.  Thanks again

You will be enlightened. Lisp has Buddha's Nature.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Nikon Sevast
Subject: Re: Beginner question - designators
Date: 
Message-ID: <7h31v3$5b2$1@nntp2.atl.mindspring.net>
I got this to work, like this:

(setq a (make-array (cons x (cons y nil))))

I'm still not sure I understand designators.  I'm guessing that (x y) does
not create a list at all, and the dimension argument is a list designator.
(?)

Nikon

Nikon Sevast wrote in message <············@nntp2.atl.mindspring.net>...
>In the process of learning Lisp, I came across the make-array function.  I
>thought to make the dimensions of the array dependent on some variable
>value, like:
>
From: Sunil Mishra
Subject: Re: Beginner question - designators
Date: 
Message-ID: <efy1zgqalun.fsf@whizzy.cc.gatech.edu>
"Nikon Sevast" <···········@mindspam.com> writes:

> I got this to work, like this:
> 
> (setq a (make-array (cons x (cons y nil))))
> 
> I'm still not sure I understand designators.  I'm guessing that (x y) does
> not create a list at all, and the dimension argument is a list designator.
> (?)

I'm not sure what you mean by designators, but I can tell you how
make-array works.

make-array expects you to tell it the dimensions of the array you want. If
you want a one dimensional array (vector) you can simply specify a single
number, and that will be interpreted as the length of the vector. Of
course, in the general case you want to be able to specify the size of more
than one dimension, for which you use a list of sizes. Each element of the
list specifies one of the dimensions. Here are some one and two dimensional 
arrays:

EVENT-SEARCH 41 > (make-array 10)
#(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)

EVENT-SEARCH 42 > (make-array (list 2 2))
#2A((NIL NIL) (NIL NIL))

EVENT-SEARCH 43 > (let ((x 2) (y 2))
  (make-array (list x y)))
#2A((NIL NIL) (NIL NIL))

EVENT-SEARCH 44 > (make-array '(2 2))
#2A((NIL NIL) (NIL NIL))

Note that when you say '(x y), you are specifying the list (x y), not
(2 2). Putting a quote ' in front of an object tells lisp not to evaluate
the object. So, '(x y) *is* the list (x y).

Hope that helps.

Sunil
From: Erik Naggum
Subject: Re: Beginner question - designators
Date: 
Message-ID: <3135234204518550@naggum.no>
* "Nikon Sevast" <···········@mindspam.com>
| I looked at the documentation for make-array, and it mentions that the
| dimension argument is a designator for a list of valid array dimensions.
| Try as I may, I can't make sense of the definition for a designator.

  it means that (make-array 4 ...)  and (make-array (list 4) ...) are
  functionally the same.  a designator for a list can be a single element:

list designator n. a designator for a list of objects; that is, an object
that denotes a list and that is one of: a non-nil atom (denoting a
singleton list whose element is that non-nil atom) or a proper list
(denoting itself).
  
#:Erik
From: Kent M Pitman
Subject: Re: Beginner question - designators
Date: 
Message-ID: <sfw90ayz449.fsf@world.std.com>
Erik Naggum <····@naggum.no> writes:

> * "Nikon Sevast" <···········@mindspam.com>
> | I looked at the documentation for make-array, and it mentions that the
> | dimension argument is a designator for a list of valid array dimensions.
> | Try as I may, I can't make sense of the definition for a designator.
> 
>   it means that (make-array 4 ...)  and (make-array (list 4) ...) are
>   functionally the same.  a designator for a list can be a single element:
> 
> list designator n. a designator for a list of objects; that is, an object
> that denotes a list and that is one of: a non-nil atom (denoting a
> singleton list whose element is that non-nil atom) or a proper list
> (denoting itself).

Right, so specifically:

 1      <-- designates (1)
 (1)    <-- designates (1)
 ()     <-- designates ()
 (1 2)  <-- designates (1 2)

The term "designator for a list of integers" substitutes for the phrase
"an integer or a list of integers where the integer is taken to mean the
singleton list whose car is the given integer".

The term "designator for a list of string designators" is taken as short
for "a symbol or a string or a list of symbols or a list of strings or a list
of symbols and strings where if symbols are used the symbols are really not
taken to be symbols but are rather taken to mean their own name and where
if no list is offered, the rest of this definition will use terminology
that presupposes a list was offered so it doesn't have to say
`the car of the list or the symbol or string if no list was given' and
can intead just say `the car of the list'".

Prior to the introduction of the designator terminology, describing
the accurate effect of functions involving lots of argument type
tolerance, like IMPORT, was enormously painful.

See CLHS 1.4.1.5 Designators for a thorough discussion of designators.