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
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
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
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
"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?
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
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?
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/
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!
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)
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/