From: Jason
Subject: aref with N dimension arrays
Date: 
Message-ID: <1141795864.186312.318940@z34g2000cwc.googlegroups.com>
I am trying to do something like this:

(setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))

My compiler is complaining, rightfully so, that I am passing a single
item (a list) as subscript arguments, when three items were expected. I
need to convert the above to something the compiler will understand,
such as:

(setq (aref array-1 0 0 0) (aref array-2 0 0 0))

I am thinking that the answer lies in the use of eval, or perhaps
within a macro, but I'm at a loss as to how this might work. Any
suggestions?

-Jason

From: Rob Warnock
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <SqKdncIuJ7pc8JPZRVn-uQ@speakeasy.net>
Jason <·······@gmail.com> wrote:
+---------------
| I am trying to do something like this:
| (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
| 
| My compiler is complaining, rightfully so, that I am passing a single
| item (a list) as subscript arguments, when three items were expected. I
| need to convert the above to something the compiler will understand...
+---------------

Try this:

    (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))

It works fine on CMUCL, though I'm not sure it's required to...


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Christophe Rhodes
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <sq1wxdflk1.fsf@cam.ac.uk>
····@rpw3.org (Rob Warnock) writes:

> Jason <·······@gmail.com> wrote:
> +---------------
> | I am trying to do something like this:
> | (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
> | 
> | My compiler is complaining, rightfully so, that I am passing a single
> | item (a list) as subscript arguments, when three items were expected. I
> | need to convert the above to something the compiler will understand...
> +---------------
>
> Try this:
>
>     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
>
> It works fine on CMUCL, though I'm not sure it's required to...

The main thrust of your solution (the use of (SETF APPLY)) is required
to work on AREF; I assume the SETQ (both here and in the OP) is a
typo.  See CLHS 5.1.2.5.

Christophe
From: Rob Warnock
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <YYCdnRjKMv7nP5PZRVn-rw@speakeasy.net>
Christophe Rhodes  <·····@cam.ac.uk> wrote:
+---------------
| ····@rpw3.org (Rob Warnock) writes:
| > Try this:
| >     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
| > It works fine on CMUCL, though I'm not sure it's required to...
| 
| The main thrust of your solution (the use of (SETF APPLY)) is required
| to work on AREF ...  See CLHS 5.1.2.5.
+---------------

Ahhh, thanks 1d6! I am continually learning more bits of CL here.
I had previously read most of 5.1.2 "Kinds of Places", but not
5.1.2.5 "APPLY Forms as Places" until just now.

+---------------
| I assume the SETQ (both here and in the OP) is a typo.
+---------------

I'll let OP speak for himself, but mine certainly was. (*blush*)
After going to all of the trouble of verifying a working example
in another window [using SETF, of course], I copy&pasted the OP's
original text and then just added in the "apply #'" prefixes,
unfortunately failing to notice the SETQ. Mea culpa.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Jason
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <1141884406.752151.297020@i39g2000cwa.googlegroups.com>
Christophe Rhodes wrote:
> ····@rpw3.org (Rob Warnock) writes:
>
> > Jason <·······@gmail.com> wrote:
> > +---------------
> > | I am trying to do something like this:
> > | (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
> > |
> > | My compiler is complaining, rightfully so, that I am passing a single
> > | item (a list) as subscript arguments, when three items were expected. I
> > | need to convert the above to something the compiler will understand...
> > +---------------
> >
> > Try this:
> >
> >     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
> >
> > It works fine on CMUCL, though I'm not sure it's required to...
>
> The main thrust of your solution (the use of (SETF APPLY)) is required
> to work on AREF; I assume the SETQ (both here and in the OP) is a
> typo.  See CLHS 5.1.2.5.
>

In this context, setq merely means that I'm testing my code using
elisp. ;P
From: Pascal Bourguignon
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <87mzg0uly0.fsf@thalassa.informatimago.com>
"Jason" <·······@gmail.com> writes:

> Christophe Rhodes wrote:
>> ····@rpw3.org (Rob Warnock) writes:
>>
>> > Jason <·······@gmail.com> wrote:
>> > +---------------
>> > | I am trying to do something like this:
>> > | (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
>> > |
>> > | My compiler is complaining, rightfully so, that I am passing a single
>> > | item (a list) as subscript arguments, when three items were expected. I
>> > | need to convert the above to something the compiler will understand...
>> > +---------------
>> >
>> > Try this:
>> >
>> >     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
>> >
>> > It works fine on CMUCL, though I'm not sure it's required to...
>>
>> The main thrust of your solution (the use of (SETF APPLY)) is required
>> to work on AREF; I assume the SETQ (both here and in the OP) is a
>> typo.  See CLHS 5.1.2.5.
>>
>
> In this context, setq merely means that I'm testing my code using
> elisp. ;P

Then put: (require 'cl) in your ~/.emacs, forget about setq and use only setf.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

In a World without Walls and Fences, 
who needs Windows and Gates?
From: Jason
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <1141941070.001506.252200@i39g2000cwa.googlegroups.com>
Pascal Bourguignon wrote:
> "Jason" <·······@gmail.com> writes:
>
> > Christophe Rhodes wrote:
> >> ····@rpw3.org (Rob Warnock) writes:
> >>
> >> > Jason <·······@gmail.com> wrote:
> >> > +---------------
> >> > | I am trying to do something like this:
> >> > | (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
> >> > |
> >> > | My compiler is complaining, rightfully so, that I am passing a single
> >> > | item (a list) as subscript arguments, when three items were expected. I
> >> > | need to convert the above to something the compiler will understand...
> >> > +---------------
> >> >
> >> > Try this:
> >> >
> >> >     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
> >> >
> >> > It works fine on CMUCL, though I'm not sure it's required to...
> >>
> >> The main thrust of your solution (the use of (SETF APPLY)) is required
> >> to work on AREF; I assume the SETQ (both here and in the OP) is a
> >> typo.  See CLHS 5.1.2.5.
> >>
> >
> > In this context, setq merely means that I'm testing my code using
> > elisp. ;P
>
> Then put: (require 'cl) in your ~/.emacs, forget about setq and use only setf.

Excellent. I did not know there was a cl package. I'll need to
investigate this more.. :)

-Jason
From: Michael Parker
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <080320061932478089%michaelparker@earthlink.net>
In article <··············@cam.ac.uk>, Christophe Rhodes 

> The main thrust of your solution (the use of (SETF APPLY)) is required
> to work on AREF; I assume the SETQ (both here and in the OP) is a
> typo.  See CLHS 5.1.2.5.
> 

I don't have the hyperspec in front of me, but doesn't the existence of
symbol-macros mean that setq must convert into a setf if given a
setf-able place?
From: Peter Seibel
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <m2slpsp5dw.fsf@gigamonkeys.com>
Michael Parker <·············@earthlink.net> writes:

> In article <··············@cam.ac.uk>, Christophe Rhodes 
>
>> The main thrust of your solution (the use of (SETF APPLY)) is required
>> to work on AREF; I assume the SETQ (both here and in the OP) is a
>> typo.  See CLHS 5.1.2.5.
>> 
>
> I don't have the hyperspec in front of me, but doesn't the existence of
> symbol-macros mean that setq must convert into a setf if given a
> setf-able place?

No, it means that SETQ must convert into a SETF if given a symbol
macro that expands into a setf-able place.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Jason
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <1141885610.671679.136930@e56g2000cwe.googlegroups.com>
Rob Warnock wrote:
> Jason <·······@gmail.com> wrote:
> +---------------
> | I am trying to do something like this:
> | (setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
> |
> | My compiler is complaining, rightfully so, that I am passing a single
> | item (a list) as subscript arguments, when three items were expected. I
> | need to convert the above to something the compiler will understand...
> +---------------
>
> Try this:
>
>     (setq (apply #'aref array-1 '(0 0 0)) (apply #'aref array-2 '(0 0 0)))
>
> It works fine on CMUCL, though I'm not sure it's required to...

This seems to be doing what I wanted. Thanks!
From: JP Massar
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <6p1u02t1u7pb5a5q33ecqqtio679soa52j@4ax.com>
On 7 Mar 2006 21:31:04 -0800, "Jason" <·······@gmail.com> wrote:

>I am trying to do something like this:
>
>(setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
>
>My compiler is complaining, rightfully so, that I am passing a single
>item (a list) as subscript arguments, when three items were expected. I
>need to convert the above to something the compiler will understand,
>such as:
>
>(setq (aref array-1 0 0 0) (aref array-2 0 0 0))
>
>I am thinking that the answer lies in the use of eval, or perhaps
>within a macro, but I'm at a loss as to how this might work. Any
>suggestions?
>
>-Jason

Another solution besides using APPLY is to use ROW-MAJOR-AREF
and friends (ARRAY-ROW-MAJOR-INDEX)
From: Peter Seibel
Subject: Re: aref with N dimension arrays
Date: 
Message-ID: <m24q28q1qw.fsf@gigamonkeys.com>
JP Massar <······@alum.mit.edu> writes:

> On 7 Mar 2006 21:31:04 -0800, "Jason" <·······@gmail.com> wrote:
>
>>I am trying to do something like this:
>>
>>(setq (aref array-1 '(0 0 0)) (aref array-2 '(0 0 0)))
>>
>>My compiler is complaining, rightfully so, that I am passing a single
>>item (a list) as subscript arguments, when three items were expected. I
>>need to convert the above to something the compiler will understand,
>>such as:
>>
>>(setq (aref array-1 0 0 0) (aref array-2 0 0 0))
>>
>>I am thinking that the answer lies in the use of eval, or perhaps
>>within a macro, but I'm at a loss as to how this might work. Any
>>suggestions?
>>
>>-Jason
>
> Another solution besides using APPLY is to use ROW-MAJOR-AREF
> and friends (ARRAY-ROW-MAJOR-INDEX)

Of course if he's starting from a list of indices he's still going to
need to do:

  (apply #'array-row-major-index array list-of-indices)

to get a value to pass to ROW-MAJOR-AREF.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/