RosettaCodeData/Task/Named-parameters/Bracmat/named-parameters.bracmat
2023-07-01 13:44:08 -04:00

20 lines
836 B
Text

( ( 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))
);