cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
msharp
Super User (Alumni)

Data Binding Associative Arrays

I recently had need to create some slightly complex data structures and started to play with associative arrays a little more.  These are similar to dictionaries in other languages.  Where they differ is that most languages to improve speed, when assigning an object in a dictionary to a variable it does a data binding.  Essentially it makes it so both the dictionary and the variable refer to the same block of memory and any edits to one affects the other.  However, JMP doesn't do this.  Below is some example code to help explain what I'm talking about.

 

testAA = Associative Array(
	{
		{"test1", Associative Array(
			{{"data", {"data1", "data2"}}}
		)},
		{"test2", Associative Array(
			{{"data", {"data1", "data2"}}}
		)}
	}
);
//create new object
AA = testAA["test1"];
//adding data to AA doesn't add data to testAA
AA["newData"] = "newData";
//you can see AA is a new object
print(AA, testAA);
//Work around to ensure data structures are in sync
testAA["test1"] = AA;
print(AA, testAA);

I don't think JSL as a language would want this behavior as a default.  I say that, b/c this can be confusing to many new programmers and JSL especially has many non-programmers enthuists.  However, this logic is applied to Data Tables.  AKA:

 

test = New Table("Hello");
test2 = test;
test << New Column("NewColumn");
print(test2 << Get Column Names);

I think it would be really nice if there was another assignment operator that would make references to data objects if needed.  This way I could choose if I want a new object or a reference to the other one.  I would be interested in others thoughts on the subject.  Also, I could be completely wrong and there may be a way to hack the associative arrays to do this that I haven't found yet. 

 

Thanks!

0 REPLIES 0