2D 'matrix' .NET arrays - HELP syntax !!!

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Hi Robert, Chris, any guy who knows,

Please help me get the correct syntax for declaring and initializing a 2D 'rectangular' array of the .NET variety.

So far in my research on Arrays I have been doing okay - until I hit the wall just now trying to convert the attached C# code.
RvdH_helpArrays_01.jpg
RvdH_helpArrays_01.jpg (21.03 KiB) Viewed 712 times
TIA,
Phil.

P.S. here is some syntax which I got to work for me :-
RvdH_helpArrays_02.jpg
RvdH_helpArrays_02.jpg (52.43 KiB) Viewed 712 times
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Frank Maraite »

Hi Phil, Chris,

this works

Code: Select all

	LOCAL numbersOne  AS INT[]
	numbersOne := <INT>{1,2,3,4,5,6}
but this

Code: Select all

	LOCAL numbersTwo AS INT[,]
	numbersTwo := {{1,2},{3,4},{5,6}}
gives XS9008 Untyped arrays are not available in the selected dialect 'Core'
Here

Code: Select all

	numbersTwo := <INT>,<INT>{{1,2},{3,4},{5,6}}
XS9002: Parser: unexpected input 'numbersTwo'
The same with

Code: Select all

	numbersTwo := <<INT>,<INT>>{{1,2},{3,4},{5,6}}
Sorry, I'm not the guy who knows

Frank
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Yep! - Frank,

Now you see how I was getting into a mess - I think I tried just about every sensible (and desperate) combination of syntaxes - I got a lot of .... selected dialect 'Core' error messages.

Its the 2D, 3D, .... XD which is giving me issues.

Hopefully Robert, Chris, Nikkos may be able to shed some light :unsure:

HELP still required !
Phil.
Wales, UK.
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Frank Maraite »

Hi Phil,

look what I found in old code:

LOCAL avals AS Double[][]
avals := <Double[]>{<Double>{1.0, 4.0, 7.0, 10.0}, <Double>{2.0, 5.0, 8.0, 11.0}, <Double>{3.0, 6.0, 9.0, 12.0}}

But realise: Double[][] is not the same as Double[,]. It is an one dimensional array of one dimensional arrays.

With that construction we can get a complete column of values by

local oneColumn as Double[]
oneColumn := avals[0] // One dimensional access to the first column.
oneColumn:Length is 4 now.

This lets us sort rows or rearrange arrays a little bit easier.
Frank
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Hi Frank,

Yes, and thanks ;-0) for the tip and sharing.

This is called a 'jagged array' I believe, and as you can see in the image of my eNotes sections the one I want is a 'multi-dimensional array' :-
ArrayBase_03.jpg
ArrayBase_03.jpg (86.25 KiB) Viewed 712 times
And I will do 'Mixed' arrays as well.

Your previous help with __ARRAYBASE__ has worked out very well this afternoon - THANKS!
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Hi Frank,

Following your syntax 'format' and others similar, the following seems the most likely to be correct I feel. But it does not work for me in X#.
ArrayBase_04.jpg
ArrayBase_04.jpg (17.32 KiB) Viewed 712 times
I have a gut feeling that the compiler may not be 100% on the topic of multi-dimensional arrays.

We need to wait for Robert and his TEAM ;-)

Cheers,
Phil.
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Chris »

Hi guys,

Sorry for the delay, I was also trying to find out if it's a bug or feature that this is not working currently :)
I think it's a mixup, the compiler confuses the VO-style ARRAY syntax with the .Net style array initialization here. I'll log this as a bug so it will be taken care off, for now you'll need to initialize the array elements the old-fashioned way (a[1,1] := 1 etc).

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Thanks Chris,

I had a feeling something not quite right was up ! Thanks for getting back to us.

For now I will do as you say and get on with researching and writing the rest of my session material and eNotes for Cologne 2018.

If I find anything else 'odd' I will get back to you.

Best wishes,
Phil.
Wales, UK.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

2D 'matrix' .NET arrays - HELP syntax !!!

Post by Phil Hepburn »

Hi Frank,

Thanks for the jagged array sample reminder.

I used it this afternoon to research and add detail to the sub-section in my ClickStart eNotes on Arrays in X# code syntax.

I attach a small sample image.
FMjaggedArrays_01.jpg
FMjaggedArrays_01.jpg (94.43 KiB) Viewed 712 times
My brain now dead, and time for tea ;-0)

Cheers,
Phil.
Post Reply