Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sel with variable cases
#1
Would it be possible to get a "sel" function that accepts variables as cases?
e.g.
Code:
Copy      Help
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"
#2
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
Code:
Copy      Help
;/
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


Forum Jump:


Users browsing this thread: 1 Guest(s)