From: Weiguang Shi
Subject: array boundary check in common lisp?
Date: 
Message-ID: <slrn96gp56.gip.wgshi@nordegg.cs.ualberta.ca>
Hi there,

I am quite new to Lisp and in the stage of wondering why some people sing high
songs about it. So please forgive me if my question seems naive.

One particular question I have is that in C, there is no run-time checking for
array boundaries. If a program runs wild and pumps more to the array than it
can contain, the data simply over-rides adjacent space, no matter what is
already there. 

How will Lisp address that problem and how is the effect on the program runtime
efficiency?

Thanks.
Weiguang

From: Thomas A. Russ
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <ymipuhjtn75.fsf@sevak.isi.edu>
·····@nordegg.cs.ualberta.ca (Weiguang Shi) writes:

> How will Lisp address that problem and how is the effect on the program runtime
> efficiency?

It depends on the compiler settings.  In general Common Lisp will check
bounds on array access (both read and write).  This can be usually
suppressed with declarations like (optimize (speed 3) (safety 0)) if you
are really desparate for execution speed and can tolerate the increased
risk of program crashing.

What is the effect on program runtime efficiency of overwriting random
parts of memory?

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Tim Bradshaw
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <ey33defcktr.fsf@cley.com>
* Thomas A Russ wrote:
> What is the effect on program runtime efficiency of overwriting random
> parts of memory?

Oh, it's enormously more efficient not to do bounds checks -- it
avoids having to remember all those boring root passwords and allows
your program to run on huge numbers of machines all over the net as
well.  

--tim
From: Lieven Marchand
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <m3vgrbo5vt.fsf@localhost.localdomain>
·····@nordegg.cs.ualberta.ca (Weiguang Shi) writes:

> I am quite new to Lisp and in the stage of wondering why some people sing high
> songs about it. So please forgive me if my question seems naive.
> 
> One particular question I have is that in C, there is no run-time checking for
> array boundaries. If a program runs wild and pumps more to the array than it
> can contain, the data simply over-rides adjacent space, no matter what is
> already there. 
> 
> How will Lisp address that problem and how is the effect on the program runtime
> efficiency?

Lisp has by default array boundary checking. It deals with the runtime
efficiency by letting programmers decide when not to do array boundary
checking through declarations.

-- 
Lieven Marchand <···@village.uunet.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: glauber
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <94a116$rlm$1@nnrp1.deja.com>
In article <····················@nordegg.cs.ualberta.ca>,
  ·····@nordegg.cs.ualberta.ca (Weiguang Shi) wrote:
> Hi there,
>
> I am quite new to Lisp and in the stage of wondering why some people sing high
> songs about it.

Its probably  because they have high voices! :-)



> So please forgive me if my question seems naive.
>
> One particular question I have is that in C, there is no run-time checking for
> array boundaries. If a program runs wild and pumps more to the array than it
> can contain, the data simply over-rides adjacent space, no matter what is
> already there.
>
> How will Lisp address that problem and how is the effect on the program runtime
> efficiency?


It's easy to find out. Start your Lisp environment and run something like
this (the stuff before the > is CLisp's prompt):

CL-USER[5]> (defvar test-array (make-array 5))

TEST-ARRAY


OK, i defined an array of 5 elements without initializing them.
Now i'll try to store something after the end of the array:

CL-USER[6]> (setf (elt test-array 10) 'bomb)

*** - SYSTEM::STORE: index 10 for #(NIL NIL NIL NIL NIL) is out of range
1. Break CL-USER[7]>


I got an error message, and the system entered the debugger (the prompt
changed to "Break".


As far as runtime efficiency impact, i think it's negligible for most
programs.

g
--
Glauber Ribeiro
··········@my-deja.com    http://www.myvehiclehistoryreport.com
"Opinions stated are my own and not representative of Experian"


Sent via Deja.com
http://www.deja.com/
From: Colin Walters
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <87n1cnqs97.church.of.emacs@meta.verbum.org>
glauber <··········@my-deja.com> writes:

> OK, i defined an array of 5 elements without initializing them.

Well, they are initialized to something by default.

> Now i'll try to store something after the end of the array:
> 
> CL-USER[6]> (setf (elt test-array 10) 'bomb)
> 
> *** - SYSTEM::STORE: index 10 for #(NIL NIL NIL NIL NIL) is out of range
> 1. Break CL-USER[7]>

Note the cool thing here is that most implementations allow one to
simply declare

(declare (optimize (speed 3) (safety 0)))

and then all the run-time checks should be gone.  In Common Lisp, you
have the choice between speed and safety.  Languages like C and C++
don't give that to you.

Of course, if the compiler can prove the array indices will be within
bounds, then the checks probably won't be added in any case.
From: Weiguang Shi
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <slrn96hack.ha6.wgshi@nordegg.cs.ualberta.ca>
Thanks a lot for your input.
I start to feel like CLisp is good to learn&use. 
You will see more of my questions in the future :-)

Regards,
Weiguang
From: Martti Halminen
Subject: Re: array boundary check in common lisp?
Date: 
Message-ID: <3A6BFD42.C6991D5B@solibri.com>
Weiguang Shi wrote:
> 
> Thanks a lot for your input.
> I start to feel like CLisp is good to learn&use.

A style point: there is a specific Common Lisp implementation named
"clisp" (whatever the correct capitalization), so your usage might cause
confusion. If you are referring to the language Common Lisp, the usual
abbreviation for it in this newsgroup is CL.

--