Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31988

Re: [JLS] new long[0][ -1 ]

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: [JLS] new long[0][ -1 ]
Date Fri, 10 Jul 2015 22:24:21 +0000 (UTC)
Organization A noiseless patient Spider
Lines 83
Message-ID <mnpgml$h0u$1@dont-email.me> (permalink)
References <slrnmpvci8.uoi.avl@login.logic.tuwien.ac.at> <mnoc71$jah$1@dont-email.me> <slrnmpvgdg.uoi.avl@login.logic.tuwien.ac.at> <mnoi74$8pm$1@dont-email.me> <slrnmpvl62.uoi.avl@login.logic.tuwien.ac.at> <mnp9cb$134$1@dont-email.me> <mnpamb$8ap$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Fri, 10 Jul 2015 22:24:21 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="17438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OcjAnWpZLj2cUpln+cSQ0k+eS+E0midg="
User-Agent Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
Cancel-Lock sha1:rhxsfB/0vY+BvHpIy42DtYM9f6I=
Xref csiph.com comp.lang.java.programmer:31988

Show key headers only | View raw


On Fri, 10 Jul 2015 16:43:06 -0400, Eric Sosman wrote:

> On 7/10/2015 4:19 PM, Martin Gregorie wrote:
>>
>> Two features I'd have liked to see in Java are non-zero based arrays,
>> e.g.
>>   int temperatureOcurrences[-40:55] and flexible array bounds, e.g int
>>   samples[0:flex]
> 
>      Would you mind elaborating on the latter?  Java already has
> 
> 	int flex = ...;
> 	int[] samples = new int[flex+1];
> 
> ... but do you mean something different?  Do you mean, perhaps,
> that a subsequent assignment to `flex' would grow or shrink the array? 
>
Brief pause while I found my Algol68R User Guide (I haven't used the 
language since 1977. I mean the latter, for instance the declaration

[1:0 flex] real a;  declares an array with flexible bounds and initially 
no elements. So I can do the following:

a := (1.0, 2.0, 3.0);   and somewhat later, I might do this:
a := (0.0, 1.1, 2.2, 3.1415926, 22.0/7.0, 0.95);

Given that there are operators associated with arrays (to extract the 
lower and upper bounds (you specify which dimension for a 
multidimensional array, flexible (returns true if its a flexible array) 
and clear (sets all elements to the 'empty value' (0 if numeric, space if 
char, false of boolean) if you think of a flexible array as being similar 
to the String class you'd not be wrong.

A68 was a sort of half-way house between 'classical' and OO languages: 
you could overload any operator, define new operators and do the same 
with data types (known as modes). For instance, you could declare a 
sketch mode to hold a set of plottable modes, derive things like 
rectangles, circles and scalable text from the sketch and overload the 
'+' operator so it could be used to add and these to another sketch, so 
you could write

circle [] c = ( list of circles );
sketch s := frame + text("My Sketch");
for i from lwb c to upb c do s += c[i];

But A68 was NOT an OO language because there was no concept of a class 
and its instances. The most you could do was declare a program segment 
which would normally contain a set of mode definitions and the operators 
and/or procedures needed to use them. A segment was more like a C source 
module than a class declaration.
 
as NOT an OO language
> What output would
> 
> 	int flex = 5;
> 	int[] samples = new int[flex+1]; System.out.println
(samples.length);
> 	flex = 20; System.out.println(samples.length);
> 	flex = -42;  // NegativeArraySizeException?
> 	System.out.println(samples.length);
> 
You can't do that: once a flexible array is declared, you change its size 
by assigning stuff to it. IIRC you could do something like:

int [] source = (1,2,3,4,5,6,7,8,9,0);
[1:0 flex] a;  // an empty flexible array;
for i from lwb source to upb source do a[i] = source[i];

IOW a flexible array doesn't do much that an ArrayList can't do;
It can be very useful when you're parsing lines of text and want split it 
into an array of words.

Depending on what you want to do, though getting away from zero-based 
arrays is rather more useful, if only because it gets you away from 
continually calculating the base offset.

HTH


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 11:52 +0000
  Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 08:02 -0400
    Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 12:58 +0000
      Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 09:45 -0400
        Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 14:19 +0000
          Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 20:19 +0000
            Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 16:43 -0400
              Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 22:24 +0000
                Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-11 07:33 -0400
            Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 21:17 +0000
              Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 22:29 +0000
            Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-27 22:10 -0400
              Re: [JLS] new long[0][ -1 ] leif.roar@dimnakorr.com - 2015-07-28 01:53 -0500
                Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-28 19:13 -0400
                Re: [JLS] new long[0][ -1 ] leif.roar@dimnakorr.com - 2015-07-28 21:50 -0500
              Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-28 11:13 +0000
                Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-31 19:41 -0400
                Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-08-01 10:23 +0000
  Re: [JLS] new long[0][ -1 ] Joerg Meier <joergmmeier@arcor.de> - 2015-07-10 17:07 +0200
    Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 18:10 +0000

csiph-web