Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
arguments and if/sel
#1
i guess i forgot something.

why is this working (both times a2 has value 'context'):
ff2qm2
Code:
Copy      Help
/
function [$a1] [$a2]

sel a2
,case "context"
,,mes a2
,case else
,,mes a1

and this not ?
ff2qm
Code:
Copy      Help
/
function [$a1] [$a2]

if(a2=="context")
,mes a2
else
,mes a1
pi
#2
== compares strings if left operand is str. If it is lpstr, compares pointers. Use sel or matchw or strcmp or q_strcimp.
#3
i thought $a2 makes it str.
pi
#4
Using lpstr for function arguments is better than str because:

1. Better performance. str would allocate and copy string.
2. Error when accidentally trying to pass a number.

Use str if:

1. Performance is not important, or the string would be copied to str variable inside the function anyway.
2. To be able to pass strings and numbers. When you assign a number to a str variable, it is automatically converted to string.
#5
thanks for the lesson !
pi


Forum Jump:


Users browsing this thread: 1 Guest(s)