Newsgroups: comp.lang.lisp,comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!gatech!rutgers!news.cs.indiana.edu!mhankins@mango.ucs.indiana.edu
From: "M. /Einstein/ Hankins" <mhankins@mango.ucs.indiana.edu>
Subject: Re: Purpose of vectors?
Message-ID: <1995May9.134336.14998@news.cs.indiana.edu>
Organization: Computer Science, Indiana University
References: <D872KL.Dyo@emi.net>
Date: Tue, 9 May 1995 13:43:30 -0500
Lines: 40
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:17760 comp.lang.scheme:12643

In article <D872KL.Dyo@emi.net>, Mark Grosberg <markg@athens.emi.net> wrote:
>Hello all,
>
>I was wondering about the origin of vectors. Was the reason for them a 
>bow to efficiency or was there some other logic behind them? 
>
>I am curious because I am implementing the internals to a small 
>list-processing language and am wondering how to keep the code (lists or 
>vectors?).
>
>L8r,
>Mark G.
>  - Thanks In Advance to all who reply :-)

From my understanding, lists in Scheme are usually represented
internally as linked list data structures.  This means that they're
very fast for a collection of things that varies in size, but they're
slow for indexing into (i.e., getting the Nth element) because the
machine has to scan each element (well, almost) in order to get to the
one you want.

Vectors are just about the opposite -- from my understanding, they are
internally represented as arrays.  This means that a whole chunk of
space is dedicated to the vector (instead of lots of little chunks in
the case of lists).  The machine has to allocate this memory to the
program; this is why you have to give the size of the vector in order
to create one.  Vectors are somewhat inefficient for containing
collections of things that vary in size, but they're very, VERY fast
for indexing into (getting a certain element #).


Hope this helps,
Ein

-- 
--
Milton "Einstein" Hankins >>>>>>>>>>> http://copper.ucs.indiana.edu/~mhankins
GAT H- s:+ !g p.5 !au>au a-- w+ v(-)(*) C++@$ UOLSUX++>++++ P+ L++ 3-
E++@ N++ K- W--- M+ V-- po+++ t+ 5+ G++ b- D+ B-- e+ u++(*) h(!) f*
r++ n++ z?
