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
remove the first element from a vector
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
  8 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
 
Cristina Ghirlanda  
View profile  
 More options Dec 27 2002, 2:28 pm
Newsgroups: comp.lang.lisp
From: Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it>
Date: 27 Dec 2002 20:31:52 +0100
Local: Fri, Dec 27 2002 2:31 pm
Subject: remove the first element from a vector
Hi,

  I wrote a function that removes the first element from a vector, but
  I think it's not the typical way people write in lisp.

(defun remove-first-from-vector (vector)
  (let (new-vector)
    (do ((index (1- (array-dimension vector 0)) (1- index)))
        ((= index 0) (concatenate 'vector new-vector))
      (push (aref vector index) new-vector))))  

  I would like to hear some advice on how I can write it in a
  more lispy way. Thanks.

Cristina


 
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.
Peter Seibel  
View profile  
 More options Dec 27 2002, 2:47 pm
Newsgroups: comp.lang.lisp
From: Peter Seibel <pe...@javamonkey.com>
Date: Fri, 27 Dec 2002 19:46:57 GMT
Local: Fri, Dec 27 2002 2:46 pm
Subject: Re: remove the first element from a vector

Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it> writes:
> Hi,

>   I wrote a function that removes the first element from a vector, but
>   I think it's not the typical way people write in lisp.

> (defun remove-first-from-vector (vector)
>   (let (new-vector)
>     (do ((index (1- (array-dimension vector 0)) (1- index)))
>         ((= index 0) (concatenate 'vector new-vector))
>       (push (aref vector index) new-vector))))  

>   I would like to hear some advice on how I can write it in a
>   more lispy way. Thanks.

I'm no expert but it seems like you can just do:

  (defun remove-first-from-vector (vector)
    (subseq vector 1))

-Peter

--
Peter Seibel
pe...@javamonkey.com


 
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.
Cristina Ghirlanda  
View profile  
 More options Dec 27 2002, 2:55 pm
Newsgroups: comp.lang.lisp
From: Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it>
Date: 27 Dec 2002 20:58:41 +0100
Local: Fri, Dec 27 2002 2:58 pm
Subject: Re: remove the first element from a vector

> I'm no expert but it seems like you can just do:
>   (defun remove-first-from-vector (vector)
>     (subseq vector 1))
> -Peter

Thanks, I didn't remember at all that vector is a sequence.

Cristina


 
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.
Barry Margolin  
View profile  
 More options Dec 27 2002, 3:02 pm
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@genuity.net>
Date: Fri, 27 Dec 2002 20:02:10 GMT
Local: Fri, Dec 27 2002 3:02 pm
Subject: Re: remove the first element from a vector
In article <aui9kv$kv...@newsreader.mailgate.org>,
Cristina Ghirlanda  <cri...@NOSPAM.interfree-DOT-it> wrote:

>Hi,

>  I wrote a function that removes the first element from a vector, but
>  I think it's not the typical way people write in lisp.

>(defun remove-first-from-vector (vector)
>  (let (new-vector)
>    (do ((index (1- (array-dimension vector 0)) (1- index)))
>        ((= index 0) (concatenate 'vector new-vector))
>      (push (aref vector index) new-vector))))  

>  I would like to hear some advice on how I can write it in a
>  more lispy way. Thanks.

Here are a couple of obvious ways.

(defun remove-first-from-vector (vector)
  (subseq vector 1))

(defun remove-first-from-vector (vector)
  (let ((new-size (1- (array-dimension vector 0)))
        (new-vector (make-array new-size
                                :element-type (array-element-type vector))))
    (dotimes (i new-size)
      (setf (aref new-vector i) (aref vector (1+ i))))
    new-vector))

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
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.
Gabe Garza  
View profile  
 More options Dec 27 2002, 3:17 pm
Newsgroups: comp.lang.lisp
From: Gabe Garza <g_ga...@ix.netcom.com>
Date: Fri, 27 Dec 2002 20:17:27 GMT
Local: Fri, Dec 27 2002 3:17 pm
Subject: Re: remove the first element from a vector

Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it> writes:
> Hi,

>   I wrote a function that removes the first element from a vector, but
>   I think it's not the typical way people write in lisp.

> (defun remove-first-from-vector (vector)
>   (let (new-vector)
>     (do ((index (1- (array-dimension vector 0)) (1- index)))
>         ((= index 0) (concatenate 'vector new-vector))
>       (push (aref vector index) new-vector))))  

>   I would like to hear some advice on how I can write it in a
>   more lispy way. Thanks.

I'd write it like this:

(defun remove-first-from-vector (vector)
  (subseq vector 1))

And if SUBSEQ didn't exist, I'd write it like this:

(defun remove-first-from-vector (vector)
  (let ((new-vector (make-array
                     (list (1- (length vector)))
                     :element-type (array-element-type vector))))
    (loop for index from 1 below (length vector)
      do (setf (aref new-vector (1- index)) (aref vector index)))
    new-vector))

Gabe Garza      


 
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.
Pascal Costanza  
View profile  
 More options Dec 27 2002, 3:58 pm
Newsgroups: comp.lang.lisp
From: Pascal Costanza <costa...@web.de>
Date: Fri, 27 Dec 2002 21:58:49 +0100
Local: Fri, Dec 27 2002 3:58 pm
Subject: Re: remove the first element from a vector
Hi Cristina,

Try the function subseq - it can be found in chapter 17 on sequences in
the HyperSpec, or chapter 14 in cltl2.

All the best,
Pascal

Cristina Ghirlanda wrote:
> Hi,

>   I wrote a function that removes the first element from a vector, but
>   I think it's not the typical way people write in lisp.

[...]

--
Given any rule, however ‘fundamental’ or ‘necessary’ for science, there
are always circumstances when it is advisable not only to ignore the
rule, but to adopt its opposite. - Paul Feyerabend


 
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.
Pascal Bourguignon  
View profile  
 More options Dec 27 2002, 10:13 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: 28 Dec 2002 04:13:52 +0100
Local: Fri, Dec 27 2002 10:13 pm
Subject: Re: remove the first element from a vector

Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it> writes:
> Hi,

>   I wrote a function that removes the first element from a vector, but
>   I think it's not the typical way people write in lisp.

> (defun remove-first-from-vector (vector)

And remember that  if you have to remove a lot  of first elements from
vector, it may be more efficient to use a list instead and use CDR.

--
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. do not adjust your minds. -- Salman Rushdie


 
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.
Daniel Barlow  
View profile  
 More options Dec 30 2002, 1:34 pm
Newsgroups: comp.lang.lisp
From: Daniel Barlow <d...@telent.net>
Date: Mon, 30 Dec 2002 02:30:14 +0000
Local: Sun, Dec 29 2002 9:30 pm
Subject: Re: remove the first element from a vector

Gabe Garza <g_ga...@ix.netcom.com> writes:
> Cristina Ghirlanda <cri...@NOSPAM.interfree-DOT-it> writes:
>>   I wrote a function that removes the first element from a vector, but
>>   I think it's not the typical way people write in lisp.
[...]
> I'd write it like this:

> (defun remove-first-from-vector (vector)
>   (subseq vector 1))

> And if SUBSEQ didn't exist, I'd write it like this:

[...]

You don't specify whether a destructive implementation is allowed (or
desired).  If so, you could also use REPLACE

(defun remove-first-from-vector (vector)
  (replace vector vector :start2 1))

-dan

--

   http://www.cliki.net/ - Link farm for free CL-on-Unix resources


 
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 »