Posts: 81
Threads: 37
Joined: Jun 2008
Would it be possible to get a "sel" function that accepts variables as cases?
e.g.
int x y z result
sel result
,case x: out "result equals value in variable x"
,case y: out "result equals value in variable y"
,case z: out "result equals value in variable z"
Posts: 12,073
Threads: 140
Joined: Dec 2002
No. It is rarely used in programming, and can be replaced to if...else if...else.
You can create functions to map variable values to 1 2 3..., and use with sel.
Function
SelInt
;/
function# x [v1] [v2] [v3] [v4] [v5] [v6] [v7] [v8] [v9] [v10] [v11] [v12] [v13] [v14] [v15] [v16] [v17] [v18] [v19] [v20] [v21] [v22] [v23] [v24] [v25] [v26] [v27] [v28] [v29] [v30]
;If x = v1, returns 1. If x = v2, returns 2. And so on.
;Returns 0 if x is not equal to one of them.
;EXAMPLE
;int x(5) a(4) b(5)
;sel SelInt(x a b)
,;case 1 out "x=a"
,;case 2 out "x=b"
,;case else out "none"
int i
int* p=&x
for i 1 getopt(nargs)
,if(p[i]=x) ret i