On 28/06/2017 15:27, Paul Dupuis via use-livecode wrote:

Your solution illustrate more so than mine how easy it is to make handler
and functions that use name/value pairs if someone prefers that model.
The xtalk language really doesn't need any extensions or enhancements to
enable this.

I completely disagree; to me, this discussion shows how much LC would benefit from named parameters.

Clearly the examples so far look pretty nice -

(a) myHandler "type=blue","name=fred","something=234"
(b) myhandler "type=blue,name=fred,something=234"

but that's largely an illusion due to the fact that these are very simple examples, using constant strings as actual parameters. Try to use variables instead, and it doesn't look so pretty.

(a) myHandler "type=" & kConstant,"name=" & myName,"something="& the rect of grp 
"abc"
(b) myhandler "type=" & kConstant,"name=" & myName,"something="& the rect of grp 
"abc"

And in fact, that last one reminds us - as soon as you use a variable or property, you need to be concerned about the current value in it; it night contain the delimiter characters, in this case comma. So the 'single parameter string' version fails - you actually need to do

(b) myhandler "type=" & urlencode(kConstant),"name=" & urlencode(myName), \
              "something="& urlencode(the rect of grp "abc")

(you can use a simpler encoding than urlencode - but this is built into the engine, so it's probably faster).

And even then, you still have problems ....
- you can't pass arrays as parameters (I'm not going down the 'arrayencode() route :-)
 - you can't have 'pass by reference' parameters

Richard mentioned a third alternative - but it is basically just using whitespace instead of comma to delimit individual key/value pairs in a single-string parameter, and so retains all the above problems.

He also mention a fourth method - using arrays - which he describes as "more with the grain" which is more appealing, since it solves all the above problems except the limitation on not using 'pass-by-reference' parameters. But I'll split that off to a separate response, with a changed subject/thread header.

-- Alex.


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to