Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
aref vs svref
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Bakhash  
View profile  
 More options Jan 25 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: David Bakhash <ca...@mit.edu>
Date: 1999/01/25
Subject: aref vs svref
Hi,

Let's say I define a class, `class-A', and I have an array of objects of
type class-A.  If class-A is a complex class, with lots of slots, etc,
is it better to define the (1-D) array of type T so I can use `svref',
or is it better to tell the compiler the truth, which is that the
:element-type is really class-A (in which case it may sometimes be
(or null class-A)).  Sometimes it's not so clear if telling the compiler
things is really a good idea.

dave


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Jan 25 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 1999/01/25
Subject: Re: aref vs svref
* David Bakhash <ca...@mit.edu>
| Let's say I define a class, `class-A', and I have an array of objects of
| type class-A.  If class-A is a complex class, with lots of slots, etc, is
| it better to define the (1-D) array of type T so I can use `svref', or is
| it better to tell the compiler the truth, which is that the :element-type
| is really class-A (in which case it may sometimes be (or null class-A)).
| Sometimes it's not so clear if telling the compiler things is really a
| good idea.

  I guess you're really asking whether a vector of class instances will be
  a simple vector unless you have fill pointers, displacement, or make it
  adjustable.  the answer is yes.  only a small set of types can be
  expected to specialize the array type and all of them are built-in types.
  the key is whether the object has to be referenced through a pointer or
  not, or can reasonably be allocated a fixed-width slot in a vector.  if
  it cannot be allocated a fixed-width slot, it has to use a pointer.

  you can probably find out by using UPGRADED-ARRAY-ELEMENT-TYPE on the
  type and see whether it is T.  if it is (and you do none of the other
  stuff that requires an array header), you must get a simple vector.

  of course, you know that you can find out whether a particular array is a
  simple vector with SIMPLE-VECTOR-P.

#:Erik
--
  SIGTHTBABW: a signal sent from Unix to its programmers at random
  intervals to make them remember that There Has To Be A Better Way.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lyman S. Taylor  
View profile  
 More options Jan 25 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: ly...@cc.gatech.edu (Lyman S. Taylor)
Date: 1999/01/25
Subject: Re: aref vs svref
In article <wk7lubl3u1....@mit.edu>, David Bakhash  <ca...@mit.edu> wrote:

>Hi,

>Let's say I define a class, `class-A', and I have an array of objects of
>type class-A.  If class-A is a complex class, with lots of slots, etc,
>is it better to define the (1-D) array of type T so I can use `svref',
>or is it better to tell the compiler the truth, which is that the
>:element-type is really class-A (in which case it may sometimes be
>(or null class-A)).  Sometimes it's not so clear if telling the compiler
>things is really a good idea.

     It is  probably best to have the model that everything in lisp is a
     reference.   So an vector of T elements and a vector of CLASS-A
     elements essentially both hold references.   The type information
     can be handy when Lisp wants to inference about what kind of
     reference will be produced by a call to SVREF.

     It doesn't change the "size" of a each vector "entry".
     [ For immutable databstructures, (e.g., fixnums , floats , etc.)
        the implementatoin may do this. However, that isn't required. ]

     So why can't you use SVREF? ?

(defclass class-a ()
     ( ( a :accessor slot-a ) (b) (c) (d) ))

(defconstant  my-arr (make-array 4 :element-type 'class-a
                                   :initial-element (make-instance 'class-a)))

(defun take-two ( vect )
 (declare (type (simple-vector 4) class-a ))
 (let  (  ( elem1 ( svref vect 1) )
          ( elem2 ( svref vect 2) ) )
   (setf (slot-a elem1) 23 )
   (slot-a elem2 )))

(defun run-demo ()
    (take-two my-arr ))

   RUN-DEMO should return 23.

   If you do

       (simple-vector-p my-arr)  ==> T

  You'll find that is it is a simple vector.  Hence, SVREF should work on it.

--

Lyman S. Taylor          "The Borg --  party poopers of the Galaxy. "
(ly...@cc.gatech.edu)                 EMH Doctor  Star Trek Voyager.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »