array.["property"]

R

Richard Cornford

Matt said:
An associative array can have its keys be unknown until runtime.
An object (in the java sense) cannot.

Not true; java.lang.reflect - allows the assigning of values to object
properties without the need to know the names until runtime.
Therefore, to be an associative array, the method must allow
the keys to be uknown until runtime.

Unknown until runtime implies that the keys be arbitrary. However,
insisting that an associative array be capable of handing all arbitrary
keys equally excludes the Java objects in question (and the javascript
object), while insisting on the keys being unknown until runtime does
not exclude those Java objects.
The "baggage" is not consistent between people, since there is
no one definition of "associative array".

It doesn't matter if there expectations are not consistent if it is
extremely rare that they are helpful to them when trying to understand
javascript objects.
You are deciding what others' expectations are, but I don't
think that everyone shares the same expectations.

I don't think they share the same expectations, but I have observed how
expectations relating to associative arrays have stood in the way of
people understanding what a javascript object is. Virtually any
expectation can do that.

Richard.
 
R

Randy Webb

Richard Cornford said the following on 11/27/2006 6:36 PM:

Specifically; it no longer has the quality that all possible (therefor
arbitrary) keys are treated equally. The end result very simply is not
an associative array (good, bad or otherwise).

Can you quote a reference that says an Associative Array has to be able
to have arbitrary keys?
 
R

Richard Cornford

Randy Webb said:
Richard Cornford said the following on 11/27/2006 6:36 PM:

Can you quote a reference that says an Associative Array has
to be able to have arbitrary keys?

Why do I need to? Can you cite an example of something that
unambiguously is an associative array that would treat keys of the same
type differently depending on the value of those keys?

Richard.
 
R

Randy Webb

Richard Cornford said the following on 11/27/2006 8:21 PM:
Why do I need to?

Because it would lend credence to your belief of what one is. But I
didn't expect you to quote a reference.
Can you cite an example of something that unambiguously is an
associative array that would treat keys of the same type differently
depending on the value of those keys?

I am not going to disprove your argument, I asked you to back it up and
you wouldn't. That alone speaks in and of itself Richard.
 
M

Matt Kruse

Richard said:
Not true; java.lang.reflect - allows the assigning of values to object
properties without the need to know the names until runtime.

"Unknown" was perhaps not the best word for me to choose, if you choose to
be obtuse about it.
How about "An associative array can have its keys be determined and defined
at runtime"?
A Java object cannot have its properties defined at runtime. Reflection has
nothing to do with it.
Unknown until runtime implies that the keys be arbitrary.

No, it does not. That is just a leap of logic used to support your position.
However,
insisting that an associative array be capable of handing all
arbitrary keys

You are the only one insisting this. Once you give up on this point, things
will be easier for you.
I have observed
how expectations relating to associative arrays have stood in the way
of people understanding what a javascript object is.

That's a whole different argument. Certainly, if your goal is to understand
javascript objects, then calling them associative arrays is misleading. But
if your goal is to implement a simple associative array, insisting that
javascript does not have an AA is misleading as well.
 
M

Matt Kruse

Richard said:
Why do I need to? Can you cite an example of something that
unambiguously is an associative array ...

Circular logic, no?

There is no way to cite an example of something that is "unambiguously" an
associative array, because no definition or requirements exist. And citing
an example that doesn't meet your criteria would certainly make it ambiguous
in your opinion.

I believe that a javascript object is unambiguously an associative array.
Therefore, that's my example.

The fact is, you can look around the web and in programming books all you
want and you won't find many definitions of an associative array that are as
restrictive as yours. Certainly there are many that would include the
javascript Object. So if myself and others are wrong in your eyes, we're
definitely not alone. ;)
 
B

Bart Van der Donck

Richard said:
[...] Can you cite an example of something that unambiguously
is an associative array that would treat keys of the same type
differently depending on the value of those keys?

Sure.

#!/usr/bin/perl
use strict;
use warnings;

$ENV{"aKey"} = "aValue"; # (like js' ENV["aKey"] = "aValue")
print "(1) " . $ENV{"aKey"} . "\n";
print "(2) " . $ENV{"SYSTEMROOT"} . "\n";

$INC{"aSecondKey"} = "aSecondValue";
print "(3) " . $INC{"aSecondKey"} . "\n";
print "(4) " . $INC{"strict.pm"} . "\n";

It says:

(1) aValue
(2) C:\WINDOWS
(3) aSecondValue
(4) c:/Perl/lib/strict.pm

I know Perl is not a fair game here, but this is what's going on:
hashes (=associative arrays) %INC, %ENV and %SIG hold special
pre-defined values for certain keys. Other keys are free to be filled
by the programmer.

Does this mean that there are no associative arrays in Perl ? Not at
all. It means that a Perl programmer must be aware of how associative
arrays work in Perl, and that some keys are not available for those
hashes.

Also, Perl hashes know other particularities: no sorting possibilities,
multi-dimensional hashes, (de)referencing to other vars in hash values,
additional forbidden keys from modules, etc.
 
J

John G Harris

In the implementation language the object employed for the javascript
object may be an associative array (or a hash table, or a list, or
whatever facilitates what is necessary for a javascript object)

Let's be a bit technical here. 'Associative Array' is an abstract data
type that can be implemented in any way that works.

A 'Hash Table' is a programming construct that could be used in
implementing an associative array. So is a linked list; so is an
ordinary array; so are a variety of tree structures; so is a database if
one is handy (using AJAX perhaps ?). There is evidence that linked lists
are used in javascript objects.

but once
that underlying object has been used to manufacture a javascript object
a series of irreversible changes in the object have transformed it into
something that no longer has the qualities of an associative array.
Specifically; it no longer has the quality that all possible (therefor
arbitrary) keys are treated equally. The end result very simply is not
an associative array (good, bad or otherwise).
<snip>

Very true. But I still say that
"There are NO associative arrays in javascript"
needs a few extra words to distinguish between the internals of
javascript and the facilities that are available to programmers.


John
 
R

Richard Cornford

Bart said:
Richard said:
[...] Can you cite an example of something that unambiguously
is an associative array that would treat keys of the same type
differently depending on the value of those keys?

Sure.

#!/usr/bin/perl
use strict;
use warnings;

$ENV{"aKey"} = "aValue"; # (like js' ENV["aKey"] = "aValue")
print "(1) " . $ENV{"aKey"} . "\n";
print "(2) " . $ENV{"SYSTEMROOT"} . "\n";

$INC{"aSecondKey"} = "aSecondValue";
print "(3) " . $INC{"aSecondKey"} . "\n";
print "(4) " . $INC{"strict.pm"} . "\n";

It says:

(1) aValue
(2) C:\WINDOWS
(3) aSecondValue
(4) c:/Perl/lib/strict.pm

If I am reading this correctly we can see two assignments using string
keys which appear to both be successful, and four retrievals using
string keys, which all appear to be equally successful. This does not
demonstrate any treating of keys differently based upon the value of the
key.

I suppose you are suggesting that the second of each pair of retrievals
is treating the keys differently as they have (supposedly) not been
assigned. But that is not reasonable as your code does not show the
instantiation of the objects, or the intervening treatments of them.

What is really needed is a demonstration that writing to a 'significant'
key can fail to assign a value (or that the value will be modified in
the process).
I know Perl is not a fair game here, but this is what's going on:
hashes (=associative arrays) %INC, %ENV and %SIG hold special
pre-defined values for certain keys.

These 'associative arrays' are part of the execution environment, aren't
they? That may be used to argue that they are no longer associative
arrays, but more interfaces to the environment. But I would be more
interested in seeing them reject/modify an assignment before rejecting
the claim that they are associative arrays. As it is I don't see any
evidence of them treating keys differently depending on the actual value
of the key, only evidence that some key/value pairs have been assigned
prior to the object being exposed. And as a result these are not exempts
of associative arrays that would treat keys of the same type differently
depending on the value of those keys.
Other keys are free to be filled
by the programmer.

But can the programmer assign to the system defined keys (without
modification of the value or side effects)?
Does this mean that there are no associative arrays in
Perl ? Not at all.

I have not seen that these objects are unambiguously associative arrays,
though the code you posted does not contradict that, but even if they
were not that could not be extended to saying that Perl had no
associative arrays. But javascript only has one object type, either that
object is an associative array or javascript has no associative arrays,
it is that black and white.
It means that a Perl programmer must be aware of how
associative arrays work in Perl,

Surely it means that Pearl programmers have to be aware that these
particular associative arrays are partly pre-populated with significant
keys?
and that some keys are not available for those
hashes.

Yes, does it have any implications for when they create a new hash from
scratch?
Also, Perl hashes know other particularities: no sorting
possibilities, multi-dimensional hashes, (de)referencing
to other vars in hash values,

None of which help the decision either way.
additional forbidden keys from modules, etc.

But that may be very significant. Can you say more? Or does this only
apply to the special pre-populated hashes you started with?

Richard.
 
B

Bart Van der Donck

Richard said:
Bart said:
Richard said:
[...] Can you cite an example of something that unambiguously
is an associative array that would treat keys of the same type
differently depending on the value of those keys?

Sure.

#!/usr/bin/perl
use strict;
use warnings;

$ENV{"aKey"} = "aValue"; # (like js' ENV["aKey"] = "aValue")
print "(1) " . $ENV{"aKey"} . "\n";
print "(2) " . $ENV{"SYSTEMROOT"} . "\n";

$INC{"aSecondKey"} = "aSecondValue";
print "(3) " . $INC{"aSecondKey"} . "\n";
print "(4) " . $INC{"strict.pm"} . "\n";

It says:

(1) aValue
(2) C:\WINDOWS
(3) aSecondValue
(4) c:/Perl/lib/strict.pm

If I am reading this correctly we can see two assignments using string
keys which appear to both be successful, and four retrievals using
string keys, which all appear to be equally successful. This does not
demonstrate any treating of keys differently based upon the value of the
key.

I suppose you are suggesting that the second of each pair of retrievals
is treating the keys differently as they have (supposedly) not been
assigned. But that is not reasonable as your code does not show the
instantiation of the objects, or the intervening treatments of them.

What is really needed is a demonstration that writing to a 'significant'
key can fail to assign a value (or that the value will be modified in
the process).

#!/usr/bin/perl
use strict;
use warnings;
$SIG{"ABRT"} = "something";
print $SIG{"ABRT"};

It prints "main::something" and not "something".
These 'associative arrays' are part of the execution environment,
aren't they?

Yes, they are. You can somewhat compare %ENV to the 'navigator'-object
in javascript until a certain level.
That may be used to argue that they are no longer associative
arrays, but more interfaces to the environment.

I would say they are both. %ENV is definitely an environmental
informant (hence its name), but %INC or %SIG are not, they hold other
kinds of information that the programmer might be interested in.
But I would be more interested in seeing them reject/modify an
assignment before rejecting the claim that they are associative arrays.

See example above with $SIG{"ABRT"}.
[...] As it is I don't see any
evidence of them treating keys differently depending on the actual value
of the key, only evidence that some key/value pairs have been assigned
prior to the object being exposed. And as a result these are not exempts
of associative arrays that would treat keys of the same type differently
depending on the value of those keys.

I would logically say that those associative arrays treat certain keys
differently simply because they are pre-defined.
But can the programmer assign to the system defined keys (without
modification of the value or side effects)?

He can overwrite the keys in question, only in his own program/scope,
but that's not recommended for obvious reasons.

#!/usr/bin/perl
use strict;
use warnings;
print $ENV{"SYSTEMROOT"} . "\n";
$ENV{"SYSTEMROOT"} = "somethingelse";
print $ENV{"SYSTEMROOT"};

says:

C:\WINDOWS
somethingelse
I have not seen that these objects are unambiguously associative arrays,
though the code you posted does not contradict that, but even if they
were not that could not be extended to saying that Perl had no
associative arrays. But javascript only has one object type, either that
object is an associative array or javascript has no associative arrays,
it is that black and white.


Surely it means that Pearl programmers have to be aware that these
particular associative arrays are partly pre-populated with significant
keys?

That is correct. And the general rule is to not modify them unless you
have a (very) good reason. I haven't seen any such case where that
would be desired though.
Yes, does it have any implications for when they create a new hash from
scratch?

Well, the hashes in question are pre-existing and have a number of
pre-defined keys. You might reset the hash or do what you like with it.
But you should really try to avoid that, the purpose for their
existence is to read them out for whatever reason.

#!/usr/bin/perl
use strict;
use warnings;
while (my ($key, $value) = each %ENV) {
print "$key = $value \n";
}

prints (for me):

USERPROFILE = C:\Documents and Settings\DOT
HOMEDRIVE = C:
TEMP = C:\DOCUME~1\DOT\LOCALS~1\Temp
SYSTEMDRIVE = C:
PROCESSOR_REVISION = 0304
SYSTEMROOT = C:\WINDOWS
CLIENTNAME = Console
COMMONPROGRAMFILES = C:\Program Files\Common Files
COMSPEC = C:\WINDOWS\system32\cmd.exe
SESSIONNAME = Console
LOGONSERVER = \\BART
APPDATA = C:\Documents and Settings\DOT\Application Data
WINDIR = C:\WINDOWS
PROGRAMFILES = C:\Program Files
OS = Windows_NT
PROCESSOR_LEVEL = 15
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
USERNAME = DOT
PROMPT = $P$G
NUMBER_OF_PROCESSORS = 1
FP_NO_HOST_CHECK = NO
HOMEPATH = \Documents and Settings\DOT
PROCESSOR_IDENTIFIER = x86 Family 15 Model 3 Stepping 4, GenuineIntel
PATH = c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS
USERDOMAIN = BART
COMPUTERNAME = BART
ALLUSERSPROFILE = C:\Documents and Settings\All Users
PROCESSOR_ARCHITECTURE = x86
CLASSPATH = .;
TMP = C:\DOCUME~1\DOT\LOCALS~1\Temp

I can change every key and/or value, but that only effects %ENV as a
variable and not the 'real' environmental information that I got at the
start. Next time, or even next scope, %ENV will have the same
prepopulated key/values again. It differs from javascript where one
cannot change such predefined values. Instructions like, say,
navigator.appName = '1234' are not accepted in javascript.
None of which help the decision either way.


But that may be very significant. Can you say more? Or does this only
apply to the special pre-populated hashes you started with?

No, it applies to all variables - it's a simple mechanism. Perl modules
might behave the same as an external .js file in this regard. Variables
originating from external code can be exported to the main programme.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top