John Brock wrote in a message he forwarded:
[...]
My suggestion is that by using a different syntax you can always
look at any array as a hash.
[and vice versa, by mapping a hash to a sequential list as key1, value1, key2, value2, ...]

A hash datatype requires a new operator to access the hash keys (so afaics it's possible to avoid different braces per Axel's preference, but /something/ new has to be added). John's idea of two indexing bracing styles achieves this, but interspersing the hash values with the keys as part of a get-keys operator is redundant.

Another possible get-keys operator is a modified prefix, e.g. @ rather than $ - so @hash[1] would return the first key and @hash[count $hash] would return the last. This has the advantage of being able to access the entire key list using @hash, which can be passed as an argument to a for loop or to echo or printf. The alternative indexing operator could achieve this through something like {*} for all values and [EMAIL PROTECTED] for all keys, but this is less intuitive and not backward-compatible with existing syntax, since $hash unadorned would return keys as well as values.

IME the mapping that John describes is rarely used. So supporting it in the get-keys operator doesn't warrant the inconvenience of having only odd-index access to the list of hash keys, and losing backward compatibility with the meaning of unadorned $array.

[...]
The advantage to all this is that you don't have to introduce a
new data type for hashes,

PHP supports a similar data type to that previously discussed on this list - an array that may be indexed traditionally (numeric keys) or as a hash aka map (string keys) using the same indexing operators []. This seems to be compatible with the model John suggests for the hash indexing operators {}.

array_keys($hash) in PHP corresponds to @hash as described above. There's no direct counterpart to @hash[index] in PHP - it can be achieved through: $keys = array_keys($hash); $keys[index].

[...]
--
http://members.dodo.com.au/~netocrat


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to