Named parameters: Difference between revisions

Added Bracmat example
(Applesoft BASIC)
(Added Bracmat example)
Line 110:
WinWaitClose, %A_ScriptFullPath%
}</lang>
 
=={{header|Bracmat}}==
In Bracmat, all functions have exactly one argument, called "arg". To split the argument and assign values to local variables, you always have to use pattern matching.
In this task, the pattern is just made a bit more complex than would have been the case without explicit parameter names in the argument.
<lang bracmat>( ( testproc
= i x y z
. out$"Calling testproc"
& (=~):(=?i:?x:?y:?z) { initialise variables to 'failure' }
& !arg
: (? (i,?i) ?|?) { if "i" found, assign value to i. Otherwise just match with no side effect. }
: (? (x,?x) ?|?) { if "x" found, assign value to x. Otherwise just match with no side effect. }
: (? (y,?y) ?|?) { likewise }
: (? (z,?z) ?|?) { likewise }
& (~!i|put$(" i:=" !i)) { if variable doesn't fail, show its value }
& (~!x|put$(" x:=" !x))
& (~!y|put$(" y:=" !y))
& (~!z|put$(" z:=" !z))
& put$\n { add new line }
)
& testproc$((x,1) (y,2) (z,3))
& testproc$((x,3) (y,1) (z,2))
& testproc$((z,4) (x,2) (y,3)) { order is not important }
& testproc$((i,1) (y,2) (z,3))
);</lang>
Output:
<pre>Calling testproc
x:= 1 y:= 2 z:= 3
Calling testproc
x:= 3 y:= 1 z:= 2
Calling testproc
x:= 2 y:= 3 z:= 4
Calling testproc
i:= 1 y:= 2 z:= 3</pre>
 
=={{header|C}}==
483

edits