Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!spool.mu.edu!howland.reston.ans.net!zaphod.mps.ohio-state.edu!wupost!uunet!s5!hui
From: hui@fid.morgan.com (Roger Hui)
Subject: Re: efficient J programs (shellsort)
Message-ID: <1993May1.224113.29876@fid.morgan.com>
Organization: Morgan Stanley & Co., New York, NY
References: <abalje47.735855110@ursa> <1993Apr27.061401.27676@csus.edu> <abalje47.735948061@ursa>
Date: Sat, 1 May 1993 22:41:13 GMT
Lines: 46

Alan Baljeu wrote on 1993-04-27:

>>    7!:2 'a =. i. 300 300'
>> 720420
>>    7!:2 '<a'
>> 360184
>>    7!:2 'b=. <a'
>> 360272
>
> Add a few tests:
>    7!:2 'a'
> 120
>    7!:2 'b =. a'
> 220
>   7!:2 '1 + a'
> 1080268
>
>  From what I see, I can say this.  An integer is 4 bytes long.  300*300
> integers yields 360000.  So yes, boxing does recopy the entire array.
> Hence it is obvious the first test creates a 2d array, and copies it.
> (why copy??).  The boxing operation apparently creates a new copy as well.
> In fact, it seems that doing any operation on the array generates extra
> space.  Adding a variable seems ok.  
> Adding 1 to the array is atrocious!  
> 
> It seems to me the implementors would do well to work this overhead out 
> of the system.

Ask not what the implementor can do for the language; ask what you 
can do for it :-) 

Regarding the "atrocity" of adding one to an array:  The function is 
plus() in file ve.c.  The specifications are as follows:

- compute the sum
- when adding internal integers, switch into internal real 
  numbers as appropriate
- if the arguments are internal integers and the result can be
  internal integers, then the result should be internal integers
- the code must be portable

Good luck.

Regarding the space required for boxing, I'd caution against
drawing general conclusions from just a few tests.  For example,
try:  7!:2 '1000$<i.300 300'
