From: synthespian
Subject: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <87d6yp109l.fsf@uol.com.br>
Hi-

	I want to declare a 4 X 4 array of the German definite articles, for the four cases: Nominativ, Akkusativ, Dativ, Genitiv.
	So, it has to be like this:
	der - die - das - die
	den - die - das - die
	dem - der - dem - den
	des - der - des - der

	So I head forward and:

* (setq a1 (make-array '(4 4)))
#2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
* (setf (aref a1 0 0) (list 'der))
(DER)
* a1
#2A(((DER) 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
* 

	And so on:
	(setf (aref a1 0 1) (list 'die))
	(setf (aref a1 0 2) (list 'das))
	(setf (aref a1 0 3) (list 'die)) ;; done with the first Casus!!

	Is there another way by which I could declare the first line of the array?
	I mean, in a less tedious way? E.g., declaring the whole list of the Nominativ at once: (list 'der 'die 'das 'die) and fit it into the array?
	Thanks in advance,

	Henry
	···········@uol.com.br
	




-- 
--------------------------------------------------------
_________   1001101010    | _________   Blah, blah,
| ^   ^ |  /1111100110    | | ^   ^ |  /blah, blah.
| O   O | / 0010100111    | | _   _ | /
|   ^   |/                | |   ^   |/
| ----- |                 | |  ---  |
\_______/                 | \_______/
                          |
________________________________________________________
Micro$oft-Free Human         100% Debian GNU/Linux
      KMFMS              "Bring the genome to the people!"

From: Thomas F. Burdick
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <xcvk7sw7ud2.fsf@apocalypse.OCF.Berkeley.EDU>
synthespian <···········@uol.com.br> writes:

> Hi-
> 
> 	I want to declare a 4 X 4 array of the German definite articles, for the four cases: Nominativ, Akkusativ, Dativ, Genitiv.
> 	So, it has to be like this:
> 	der - die - das - die
> 	den - die - das - die
> 	dem - der - dem - den
> 	des - der - des - der

 [snip]

> 	Is there another way by which I could declare the first line of the array?
> 	I mean, in a less tedious way?

Why don't you just use the read syntax:

  #2A((der die das die) ...)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Kenny Tilton
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <3C7F56AB.CD83A423@nyc.rr.com>
synthespian wrote:
> 
> Hi-
> 
>         I want to declare a 4 X 4 array of the German definite articles, for the four cases: Nominativ, Akkusativ, Dativ, Genitiv.
>         So, it has to be like this:
>         der - die - das - die
>         den - die - das - die
>         dem - der - dem - den
>         des - der - des - der
> 
>         So I head forward and:
> 
> * (setq a1 (make-array '(4 4)))
> #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
> * (setf (aref a1 0 0) (list 'der))

I am not addressing your question of how to initialize a whole row in
one shot, but I did notice:

  Why are you intializng the array element to (list 'der) instead of
just 'der?

You said you wanted "der - die - das - die", but you are headed for
((der)(die)(das)(die)) when I /think/ you want (der die das die).

-- 

 kenny tilton
 clinisys, inc
 ---------------------------------------------------------------
 "Be the ball...be the ball...you're not being the ball, Danny."
                                               - Ty, Caddy Shack
From: Erik Naggum
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <3223989282671407@naggum.net>
* synthespian <···········@uol.com.br>
| I want to declare a 4 X 4 array

  "Declare"?  You seem to want to construct it.

| Is there another way by which I could declare the first line of the array?

  Is there some word in your native tongue that looks a lot like "declare",
  but which has a sensible meaning in your context?  I find it very odd,
  even when I try to interpret this is in "Java/C++ mode", because even in
  those languages, a declaration cannot initialize anything; a definition
  might, and a call to a run-time constructor

| mean, in a less tedious way? E.g., declaring the whole list of the
| Nominativ at once: (list 'der 'die 'das 'die) and fit it into the array?

  See the specification of make-array and look for the :initial-contents
  argument in particular.  You might notice something quite interesting
  about how the syntax for arrays work with how you initialize them.

///
-- 
  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: Mean Gene
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <87vgcdepns.fsf@localhost.i-did-not-set--mail-host-address--so-tickle-me>
Erik Naggum <····@naggum.net> writes:

>   Is there some word in your native tongue that looks a lot like "declare",
>   but which has a sensible meaning in your context?  I find it very odd,
>   even when I try to interpret this is in "Java/C++ mode", because even in
>   those languages, a declaration cannot initialize anything; a definition
>   might, and a call to a run-time constructor

It seems the original poster wanted an expression that can be fed to
defparameter.  Don't know Java, but in "C/C++ mode" declaration and
construction are synonymous for "const" objects.

-- 
"Markets can remain irrational longer than 
you can remain solvent."   -- J. M. Keynes
From: Jochen Schmidt
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <a5u5m8$ffa$1@rznews2.rrze.uni-erlangen.de>
Mean Gene wrote:

> Erik Naggum <····@naggum.net> writes:
> 
>>   Is there some word in your native tongue that looks a lot like
>>   "declare",
>>   but which has a sensible meaning in your context?  I find it very odd,
>>   even when I try to interpret this is in "Java/C++ mode", because even
>>   in those languages, a declaration cannot initialize anything; a
>>   definition might, and a call to a run-time constructor
> 
> It seems the original poster wanted an expression that can be fed to
> defparameter.  Don't know Java, but in "C/C++ mode" declaration and
> construction are synonymous for "const" objects.
> 

Not really. A definition in "C/C++" mode also brings with a declaration but 
not vice versa.

ciao,
Jochen

--
http://www.dataheaven.de
From: lin8080
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <3C82BD8F.107AC4B3@freenet.de>
synthespian schrieb:
> 
> Hi-
> 
>         I want to declare a 4 X 4 array of the German definite articles, for the four cases: Nominativ, Akkusativ, Dativ, Genitiv.
>         So, it has to be like this:
>         der - die - das - die
>         den - die - das - die
>         dem - der - dem - den
>         des - der - des - der

>         So I head forward and:

> * (setq a1 (make-array '(4 4)))
> #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
> * (setf (aref a1 0 0) (list 'der))
> (DER)
> * a1
> #2A(((DER) 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
> *

>         And so on:
>         (setf (aref a1 0 1) (list 'die))
>         (setf (aref a1 0 2) (list 'das))
>         (setf (aref a1 0 3) (list 'die)) ;; done with the first Casus!!

>         Is there another way by which I could declare the first line of the array?
>         I mean, in a less tedious way? E.g., declaring the whole list of the Nominativ at once: (list 'der 'die 'das 'die) and fit it into the array?
>         Thanks in advance,


just copy&paste it:

(setq a1 (make-array '(4 4) :adjustable t :initial-contents '((der die
das die) (den die das die) (dem der dem den) (des der des der))))
a1
#2A((der die das die) (den die das die) (dem der dem den) (des der des
der))

(setq a2 (make-array '(1) :adjustable t :initial-element '(der die das
die den die das die dem der dem den des der des der)))
a2
#((der die das die den die der des der dem der dem den des der des der))

(setq a3 '(der die das die den die das die dem der dem den des der des
der))
a3
(der die das die den die das die dem der dem den des der des der)

(setq a4 (list a1))
a4
(#2A((der die das die) (den die das die) (dem der dem den) (des der des
der))

stefan
From: Kent M Pitman
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <sfwn0xpw36z.fsf@shell01.TheWorld.com>
lin8080 <·······@freenet.de> writes:

> synthespian schrieb:
>
> >         I want to declare a 4 X 4 array of the German definite articles, 
> >         for the four cases: Nominativ, Akkusativ, Dativ, Genitiv.
> >         So, it has to be like this:
> >         der - die - das - die
> >         den - die - das - die
> >         dem - der - dem - den
> >         des - der - des - der
> 
> >         So I head forward and:
> 
> > * (setq a1 (make-array '(4 4)))
> > #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))

Ick.  (Not to be confused with Ich.)  What Lisp does that??
[choose 0 as an initial element]

ANSI CL doesn't specify an initial value for array elements, 
so this is conforming.  But...

It seems to me that NIL is the obvious and widespread choice for an
initial element.  For arbitrary choices like th is, it would seem to
me to be good if implementations didn't deviate from common practice
without some good reason.  Whose Lisp is it and why do they do it?

I think the main reason the language doesn't specify an initial value,
btw, is that implementations might contain type-constrained arrays
other than the ones we have, and we might not know how to predict the
right element.  e.g., there could be a string array that has no
obviously specificable choice of character.  But for the "normal"
types, I think NIL for type T, 0 for integer arrays, 0.0 for floats
are what most people expect.
From: Carl Shapiro
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <ouy7kotyunt.fsf@panix3.panix.com>
Kent M Pitman <······@world.std.com> writes:

> Ick.  (Not to be confused with Ich.)  What Lisp does that??
> [choose 0 as an initial element]

CMUCL

* (describe (make-array '(4 4)))

#2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0)) is an array of rank 2.
Its dimensions are (4 4).
Its element type is T.
* 
From: Kenny Tilton
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <3C832CE9.A3C63A51@nyc.rr.com>
Carl Shapiro wrote:
> 
> Kent M Pitman <······@world.std.com> writes:
> 
> > Ick.  (Not to be confused with Ich.)  What Lisp does that??
> > [choose 0 as an initial element]
> 
> CMUCL
> 
> * (describe (make-array '(4 4)))
> 
> #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0)) is an array of rank 2.
> Its dimensions are (4 4).
> Its element type is T.
> *

T??? I'm sorry, either you default element type t to nil or you default
element type number to...hell, not even sure I can think of a default
number, but if you are defaulting to zero you sure as hell better have
number as the type to which you are defaulting.

I thought CMUCL was half-decent...?

:)

-- 

 kenny tilton
 clinisys, inc
 ---------------------------------------------------------------
 "Be the ball...be the ball...you're not being the ball, Danny."
                                               - Ty, Caddy Shack
From: Raymond Wiker
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <863czgu3x0.fsf@raw.grenland.fast.no>
Kenny Tilton <·······@nyc.rr.com> writes:

> Carl Shapiro wrote:
> > 
> > Kent M Pitman <······@world.std.com> writes:
> > 
> > > Ick.  (Not to be confused with Ich.)  What Lisp does that??
> > > [choose 0 as an initial element]
> > 
> > CMUCL
> > 
> > * (describe (make-array '(4 4)))
> > 
> > #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0)) is an array of rank 2.
> > Its dimensions are (4 4).
> > Its element type is T.
> > *
> 
> T??? I'm sorry, either you default element type t to nil or you default
> element type number to...hell, not even sure I can think of a default
> number, but if you are defaulting to zero you sure as hell better have
> number as the type to which you are defaulting.
> 
> I thought CMUCL was half-decent...?

        t is the mother of all types, so 0 is of type t. So is nil :-)

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/
From: Kenny Tilton
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <3C837B32.D0CF3C6F@nyc.rr.com>
Raymond Wiker wrote:
>         t is the mother of all types, so 0 is of type t. So is nil :-)

Buddha (Lisp): In the beginning was the One (1), and from the One came
Yin and Yang (nil and t), and from Yin and Yang came the Multitude.

So I'm thinking #2((1 1 1 1)(1 1 1 1)(1 1 1 1)(1 1 1 1))

:)

-- 

 kenny tilton
 clinisys, inc
 ---------------------------------------------------------------
 "Be the ball...be the ball...you're not being the ball, Danny."
                                               - Ty, Caddy Shack
From: Dorai Sitaram
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <a5vuog$p6$1@news.gte.com>
In article <·················@nyc.rr.com>,
Kenny Tilton  <·······@nyc.rr.com> wrote:
>
>
>Raymond Wiker wrote:
>>         t is the mother of all types, so 0 is of type t. So is nil :-)
>
>Buddha (Lisp): In the beginning was the One (1), and from the One came
>Yin and Yang (nil and t), and from Yin and Yang came the Multitude.
>
>So I'm thinking #2((1 1 1 1)(1 1 1 1)(1 1 1 1)(1 1 1 1))

I think you're confusing "Make me one with everything"
(the Hotdog sutra) with "Make me everything with
one".

--d
From: Marco Antoniotti
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <y6chenwcqw5.fsf@octagon.mrl.nyu.edu>
Kenny Tilton <·······@nyc.rr.com> writes:

> Carl Shapiro wrote:
> > 
> > Kent M Pitman <······@world.std.com> writes:
> > 
> > > Ick.  (Not to be confused with Ich.)  What Lisp does that??
> > > [choose 0 as an initial element]
> > 
> > CMUCL
> > 
> > * (describe (make-array '(4 4)))
> > 
> > #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0)) is an array of rank 2.
> > Its dimensions are (4 4).
> > Its element type is T.
> > *
> 
> T??? I'm sorry, either you default element type t to nil or you default
> element type number to...hell, not even sure I can think of a default
> number,

CMUCL is inconsistent in this case.  It uses the correct numerical
default in other occasions.

	42

:)

Cheers


-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Christophe Rhodes
Subject: Re: newbie asks: is there a better way to declare arrays?
Date: 
Message-ID: <sqg03gln4w.fsf@cam.ac.uk>
Kent M Pitman <······@world.std.com> writes:

> > synthespian schrieb:
> >
> > > * (setq a1 (make-array '(4 4)))
> > > #2A((0 0 0 0) (0 0 0 0) (0 0 0 0) (0 0 0 0))
> 
> Ick.  (Not to be confused with Ich.)  What Lisp does that??
> [choose 0 as an initial element]

CMUCL, and SBCL also.

> ANSI CL doesn't specify an initial value for array elements, 
> so this is conforming.  But...
> 
> It seems to me that NIL is the obvious and widespread choice for an
> initial element.  For arbitrary choices like th is, it would seem to
> me to be good if implementations didn't deviate from common practice
> without some good reason.  Whose Lisp is it and why do they do it?

Without wishing to retrofit motivation into the developers' actions,
it looks like not wishing to initialize as well as allocating a
zero-filled space of memory.
 
> I think the main reason the language doesn't specify an initial value,
> btw, is that implementations might contain type-constrained arrays
> other than the ones we have, and we might not know how to predict the
> right element.  e.g., there could be a string array that has no
> obviously specificable choice of character.  But for the "normal"
> types, I think NIL for type T, 0 for integer arrays, 0.0 for floats
> are what most people expect.

Well, maybe, but since conforming code has to initialize the array
contents itself, nothing is lost by being lazy. What would you expect
for strings in ASCII-land, by the way? #\Null, #\Space, or something
else?

Just to be very clear on this one: if you are writing code to run on
an implementation of Common Lisp, you can of course follow
implementation-defined defaults; so if you use clisp, for instance,
you can depend on the fact that :ELEMENT-TYPE T arrays will be
initialized to NIL[1]. If, however, you are writing code that is to be
runnable in conforming implementations, you have to write to the
standard, not what you wish the standard to be[2]. 

Christophe

[1] Though I don't think this is actually documented anywhere, so you
could lose if the clisp implementors decide to change their minds...
[2] Kent, I know you know this :-) But sometimes it's useful to have
slightly perverse decisions made by implementors so that you can catch
your hidden assumptions.
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/                  (defun pling-dollar 
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)