Jump to content

Recommended Posts

Posted (edited)

Let's move onto 

  Quote

Rule #2: You must specify the no. of elements & dimensions if you are gonna declare an array without any data

You must also declare an array's  "no. of elements & dimensions" even if you are assigning it data.

Suggestion "If you declare an array that is not created by a function, you must specify its "no. of elements & dimensions" size."

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

  • Moderators
Posted

JohnOne,

  Quote

You must also declare an array's  "no. of elements & dimensions" even if you are assigning it data

Not quite true - you must declare the number of dimensions, but not necessarily their size if you declare the data:

#include <Array.au3>

Global $aArray[][] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

_ArrayDisplay($aArray, "", Default, 8)

Obviously if the data does not fill the entire dimension you need to define the full size explicitly.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

JohnOne,

No, you only create a Map (using the Beta) when you declare with empty [ ] and no data:

Both Arrays and Maps use similar syntax, so care is required to ensure the variable is of the correct datatype - this is determined by the first declaration line for the variable:

Using empty [ ] declares a Map:

  Local $vVar[] ; A Map

Filling the [ ] with a dimension size declares an Array:

 Local $vVar[3] ; An Array

Assigning element values when declaring makes the variable an Array - these three lines are functionally equivalent:

  Local $vVar[3] = [1, 2, 3] ; An Array
  Local $vVar[] = [1, 2, 3] ; An Array
  Local $vVar = [1, 2, 3] ; An Array

There has been some internal debate as to whether there should be a different syntax for Maps (such as { }) but there is a lot of work that needs to be done to get them working correctly before we ever get to that level of detail.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

I altered Rule 2...

About Maps, Aren't they just arrays which which use strings instead of integers to access the elements?

Local $aArray[1] = ["Data"]
Local $mMap[]

$mMap['data'] = "Data"
Edited by TheDcoder
Syntax correction

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • Moderators
Posted (edited)

TheDcoder,

No, they are much more versatile then that - take a look here.

M23

Edited by Melba23
Added direct link

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

If someone smrt could explain the efficiencies of  "map -vs- scripting dictionary"  that would help.  As best I can determine its decent mimicry.

  Reveal hidden contents

Posted
  On 10/19/2015 at 11:10 AM, TheDcoder said:

Local $mMap[] = ["Data" => "Data"]

When did AutoIt become PHP?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 10/19/2015 at 1:29 PM, boththose said:

If someone smrt could explain the efficiencies of  "map -vs- scripting dictionary"  that would help.  As best I can determine its decent mimicry.

I cannot fulfill your criteria but one difference I can see is that you cannot store and use a function in a scripting dictionary.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

  • 2 months later...
Posted
  On 10/18/2015 at 9:05 AM, guinness said:

@TheDcoder, maybe you could answer this question...why does the index value start from zero and not one?

Sorry for very late reply, I didn't notice that question earlier :sweating:. I have multiple hypotheses on this question.

#1 They way the Windows Memory Manager (or Memory Allocator? Something like that :wacko:) parses a variable (with a pointer thing?) has a advantage with using 0 as the base index for arrays... Something like there is no way around to set its base to 1 without using index - 1 method to access the elements :P

#2 Some intelligent group of early programmers decided that everything should start with 0... viz. the of birth 0 based array :P

#3 Something to do with hardware.. Advantage for using 0 again... :P

#4 Maybe the least likely situation would be Binary, binary is all 0's and 1's... so why waste the 00110000 (1 byte) key of zero... (one's binary key is 00110001)

 

TD :think:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

Maybe Google it, you were close I guess.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

@guinness I tried, I found very detailed and complicated HTML documents about it... A deeper search again this time revealed this:

  Quote

Zero-based indexing actually simplifies array-related math for the programmer, and simpler math leads to fewer bugs.

Anders Kaseorg, Quora

Edited by TheDcoder
THAT LINK INSERTION BUG IN IPS'S MODIFIED WYSIWYG CK-EDITOR

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted

Yeah and also look at arrays and pointer arithmetic.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...