November 25, 2009
On Wed, 25 Nov 2009 21:11:48 +0300, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> On 11/25/2009 10:46 AM, Don wrote:
>> Denis Koroskin wrote:
>>>>> I recall that Visual Basic has UBound function that returns upper
>>>>> bound of a multi-dimensional array:
>>>>> Dim a(100, 5, 4) As Byte
>>>>> UBound(a, 1) -> 100
>>>>> UBound(a, 2) -> 5
>>>>> UBound(a, 3) -> 4
>>>>> Works for single-dimensional arrays, too:
>>>>> Dim b(8) As Byte
>>>>> UBound(b) -> 8
>>
>>> I brought a point that VB has a UBound function that does exactly what
>>> opDollar is supposed to do, so something like opUpperBound() might fit.
>>
>> Finally, a viable alternative to opDollar! I could live with
>> opUpperBound.
>
> <nitpick>
>
> VB's ubound doesn't do exactly the same thing as $; in your code snippet
>
> b(0)
> b(8)
>
> are both valid elements.
>

IIRC lower bound is 1 by default in VB and therefore b(0) is illegal.

> Does opUpperBound imply an opLowerBound?
>
> In VB you can declare things like
>
> dim a(20 to 100, 5, 1 to 4) as Byte
>
> LBound(a,1) -> 20
>
> Yep. Visual Basic. Awesome language. *Cough*


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
November 25, 2009
Denis Koroskin wrote:
> On Wed, 25 Nov 2009 21:11:48 +0300, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> 
>> On 11/25/2009 10:46 AM, Don wrote:
>>> Denis Koroskin wrote:
>>>>>> I recall that Visual Basic has UBound function that returns upper
>>>>>> bound of a multi-dimensional array:
>>>>>> Dim a(100, 5, 4) As Byte
>>>>>> UBound(a, 1) -> 100
>>>>>> UBound(a, 2) -> 5
>>>>>> UBound(a, 3) -> 4
>>>>>> Works for single-dimensional arrays, too:
>>>>>> Dim b(8) As Byte
>>>>>> UBound(b) -> 8
>>>
>>>> I brought a point that VB has a UBound function that does exactly what
>>>> opDollar is supposed to do, so something like opUpperBound() might fit.
>>>
>>> Finally, a viable alternative to opDollar! I could live with
>>> opUpperBound.
>>
>> <nitpick>
>>
>> VB's ubound doesn't do exactly the same thing as $; in your code snippet
>>
>> b(0)
>> b(8)
>>
>> are both valid elements.
>>
>> Does opUpperBound imply an opLowerBound?
>>
>> In VB you can declare things like
>>
>> dim a(20 to 100, 5, 1 to 4) as Byte
>>
>> LBound(a,1) -> 20
>>
>> Yep. Visual Basic. Awesome language. *Cough*
> 
> Lower bound is always 0 in D, unlike VB where is can take an arbitrary value. As such, there is no need for opLowerBound in D.
Why does it make any sense that the lower bound of any arbitrary class needs to be 0?

I'd say opUpperBound is as wrong as opEnd.
November 25, 2009
On 11/25/2009 01:40 PM, Denis Koroskin wrote:
>
> IIRC lower bound is 1 by default in VB and therefore b(0) is illegal.
>

Nope.

Dim b(8) as String

is equivalent to

Dim b(0 to 8) as String

and therefore b(0) is very legal.
November 28, 2009
Denis Koroskin wrote:
<snip>
> Lower bound is always 0 in D, unlike VB where is can take an arbitrary value. As such, there is no need for opLowerBound in D.

Only for built-in linear arrays.  Half the point is: What if somebody creates a type for which the lower bound is something different?

Thinking about it, maybe we need some symbol like ^ to denote the lower bound, and opLowerBound to implement it.  (I've picked ^ along the lines of regexps, from which $ is presumably derived.  I *think* this doesn't lead to any ambiguity....)

Stewart.
November 28, 2009
Stewart Gordon:
> Only for built-in linear arrays.  Half the point is: What if somebody creates a type for which the lower bound is something different?

This can be useful. For example an array with indices in a .. z+1 :-)


> maybe we need some symbol like ^ to denote the lower bound, and opLowerBound to implement it.  (I've picked ^ along the lines of regexps, from which $ is presumably derived.  I *think* this doesn't lead to any ambiguity....)

In Python you usually just omit the value:
a[:5] === a[0 .. 5]
a[5:] === a[5 .. $]
Or you can also use None, this can useful because you can put None inside a variable, etc (while in D you can't put $ inside a variable to represent "the end of that array"):
a[None:5] === a[0 .. 5]
a[5:None] === a[5 .. $]

Bye,
bearophile
December 08, 2009
bearophile wrote:
<snip>
> In Python you usually just omit the value:
> a[:5] === a[0 .. 5]
> a[5:] === a[5 .. $]

Which doesn't accommodate anything equivalent to a[$-4 .. $-2].

> Or you can also use None, this can useful because you can put None inside a variable, etc (while in D you can't put $ inside a variable to represent "the end of that array"):
<snip>

I don't understand this statement at all.

Stewart.
December 08, 2009
On 12/07/2009 08:33 PM, Stewart Gordon wrote:
> bearophile wrote:
> <snip>
>> In Python you usually just omit the value:
>> a[:5] === a[0 .. 5]
>> a[5:] === a[5 .. $]
>
> Which doesn't accommodate anything equivalent to a[$-4 .. $-2].

you mean this?

a[-4:-2]

>
>> Or you can also use None, this can useful because you can put None
>> inside a variable, etc (while in D you can't put $ inside a variable
>> to represent "the end of that array"):
> <snip>
>
> I don't understand this statement at all.

neither can I.

I'll posit a guess though.

c = None;
assert a[1:c] == a[1:]

not seeing any advantage over

c = len(a)

>
> Stewart.

December 08, 2009
Stewart Gordon:

>Which doesn't accommodate anything equivalent to a[$-4 .. $-2].<

In Python:

>>> a = "abcdefgh"
>>> a[-4 : -2]
'ef'


> Or you can also use None, this can useful because you can put None inside a variable, etc (while in D you can't put $ inside a variable to represent "the end of that array"):
<snip>

>I don't understand this statement at all.<

You are right and I am sorry, let's try again.

In Python slices using None is the same as omitting the value:

a[:5] === a[None : 5]
a[5:] === a[5 : None]

Omitting a value is handy, but nothing is not a value you can pass around and store in a variable, while None allows you to do that, so it gives more flexibility. This is a little example:

def foo(start, stop):
  a = "abcdefgh"
  print a[start : stop]

foo(1, 2)
foo(None, 2)
foo(2, None)
foo(None, None)


Output:
b
ab
cdefgh
abcdefgh

You can't do that with omitted values, and $ too can't be moved around in a variable, so None is more flexible. (I know you can't do that in D, you need nullable integers, for example).

I hope this explanation was a little more clear.

Bye,
bearophile
December 08, 2009
On Tue, 08 Dec 2009 04:02:21 +0100, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> On 12/07/2009 08:33 PM, Stewart Gordon wrote:
>> bearophile wrote:
>> <snip>
>>> In Python you usually just omit the value:
>>> a[:5] === a[0 .. 5]
>>> a[5:] === a[5 .. $]
>>
>> Which doesn't accommodate anything equivalent to a[$-4 .. $-2].
>
> you mean this?
>
> a[-4:-2]

That, however (like D) does not support arrays with negative indices.

-- 
Simen
December 11, 2009
Simen kjaeraas wrote:
> On Tue, 08 Dec 2009 04:02:21 +0100, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> 
>> On 12/07/2009 08:33 PM, Stewart Gordon wrote:
>>> bearophile wrote:
>>> <snip>
>>>> In Python you usually just omit the value:
>>>> a[:5] === a[0 .. 5]
>>>> a[5:] === a[5 .. $]
>>>
>>> Which doesn't accommodate anything equivalent to a[$-4 .. $-2].
>>
>> you mean this?
>>
>> a[-4:-2]
> 
> That, however (like D) does not support arrays with negative indices.

But in D, you can use a negative index/key in an AA or custom array type.

And is there any equivalent in Python to a[$/2] or anything fancy like that?

Stewart.