Array Declaration in Mercury

Declaration of an array in microsoft visual basic is achieved by specifying the upperbound of the array ::
dim arr(4) as Integer
Console.WriteLine($“Length of the array = {arr.Length}”)
The length is returned as 5.

In mercury, declaration of an array is achieved by specifying the array length :
dim arr(4) as Integer
Console.WriteLine($“Length of the array = {arr.Length}”)
The length is returned as 4.

Is this a bug or by design?

Thanks for supporting VB.

George

1 Like

Sounds like a bug! I’ll log an issue for the compiler team, thanx!

:pray:t3:

Logged as bugs://E26450.

bugs://E26450 was closed as fixed.

1 Like

It appears to be rectified. :nerd_face:

Module Program
  dim arr(4) as Integer  //4 indicates upper bound so (0,1,2,3,4) or 5 elements total vs C-based languages in which 4 indicates 4 elements
  Sub Main(args as String()) 
    Console.WriteLine($“Length of the array = {arr.Length}”) // returns 4 in version .2813, returns 5 as of version .2821
  End Sub
End Module

Happy to hear! thanx for confirming.

1 Like

Thanks for sorting that.
Having issues with initialising arrays still as in the code below

Dim januaryInquiries(30)() As String
jagged array januaryInquiries is nil after this statement

If a jagged array is initialised at time of declaration, it works as in :
Dim values()() As Integer = {

  • New Integer() {1,2,3},*
    
  • New Integer() {1,2},*
    
  • New Integer() {1,2,3},*
    
  • New Integer() {1,2,3, 4}*
    
  • }*

Dim intArray() As Integer = New Integer(4) {}
intArray(0) = 25
intArray is not nil, but any attempt to assign a value to the array element results in a IndexOut OfRange exception.

Equivalent c# statements work fine.

George

Do you haoppen to have a complete test case for this handy?

thanx,
marc

Example included.

ArrayTest.zip (98.8 KB)

Thanks for superb software and support.

George

Thanx!

Logged as bugs://E26462.

Thanks for the testcase, very helpful. Jagged arrays are fixed now

1 Like

bugs://E26462 was closed as fixed.

Many thanks

George

2 Likes