I have been following Scott's advice and looking at the LibURL stack script. Very
interesting, if a bit complex to understand at times.
put x into tUrl[nIP]
if tPort is not empty then put tPort into tPort[tUrl[nIP]]
There are several interesting things about this line of code.
Empty does not work in the way you would expect with an array:
get empty(tPort) --> true if tPort is an array or is empty
This is correct in the sense that empty returns whether or not a variable contains a
string. However some users may think it means tPort contains no data - which isn't
necessarily correct. Perhaps it would be better if empty() returned a syntax error if
used with an array. Comments?
get empty(tPort) --> false if tPort contains a string/integer/floating number etc
So:
if tPort is not empty then put tPort into tPort[tUrl[nIP]]
... is saying if tPort is a string then turn it into an array and store the value in
the key named (value returned by tUrl[nIP]).
Now consider the second part of the line (somewhat simplified):
put "testing" into tPort[tUrl[nIP]]
This is not saying what I would have hoped - store the "testing" in the element nIp of
array tUrl of array tPort. It is actually saying, evaluate tUrl[nIP] and store
"testing" in that element of tPort.
Where this falls down is that if tUrl[nIP] resolves to empty, it will still store the
value.
Consider this:
put 1 into bob[]
put bob[] -->1
Thus if you mistakenly think MC supports arrays within arrays and build something like
this:
put "red" into car[interior[color]]
put "2 door" into car[interior[model]]
... there won't be any errors. But car[interior[color]] will return "2 door" because
both interior[color] and interior[model] return empty which is an allowed key.
I don't think it's a good idea to allow put 1 into anArray[]. I think this should
return an error "no key supplied" or something like that.
How I would like to see arrays work:
I think things which need to be evaluated should be surrounded in brackets:
put x into a1[(a2[ele])]
I would like to see multidimensional arrays in Metacard. Therefore:
put x into a1[a2[ele]]
should mean put x into element ele of sub-array a2 of array a1.
I would be interested in what others think about this.
Rodney
--
--
Rodney Tamblyn
Educational Media group
Higher Education Development Centre, 75 Union Place
University of Otago, PO Box 56, Dunedin, New Zealand
ph +64 3 479 7580 Fax +64 3 479 8362
http://hedc.otago.ac.nz ~ http://rodney.weblogs.com
Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.