Control Functions.pfunc

Overloads a callable by a condition and a body.

Arguments

conditionBody
to evaluate on each call.
body
is the code to overload a callable with.

Return values

The resulting

callable
. If the
condition
evaluates to FALSE or leads to an error, the error will be suppressed, and an old overload will be called. If the
condition
evaluates to TRUE, the new overload will be called. In particular,
pfunc
can be used for pattern matching, where possible variants will be checked starting from the last one.

Example

"sl/control" useFile a: [1 +] func; a: [ sqrt TRUE ] [1.0 + ] pfunc; b: [.op 0 =] [v:; v.x v.y *] pfunc; b: [.op 1 =] [v:; v.x v.y /] pfunc; b: [.op 2 =] [v:; v.x v.y +] pfunc; b: [.op 3 =] [v:; v.x v.y -] pfunc; b: [v:; v.op 1 = v.y 0 = and] [v:; 0] pfunc; 2 a print LF print 2.0 a print LF print "b test:" print LF print { op: 0; x: 58; y: 6; } b print LF print { op: 1; x: 58; y: 6; } b print LF print { op: 2; x: 58; y: 6; } b print LF print { op: 3; x: 58; y: 6; } b print LF print { op: 0; x: 58; y: 0; } b print LF print { op: 1; x: 58; y: 0; } b print LF print { op: 2; x: 58; y: 0; } b print LF print { op: 3; x: 58; y: 0; } b print
Output:
3 3.000000 b test: 348 9 64 52 0 0 58 58