samifox Posted October 18, 2015 Posted October 18, 2015 hi (cond ((= s "Y") 1) ((= s "y") 1) ((= s "N") 0) ((= s "n") 0) (t nil) ) usually functions return nill when an empty value is issue, in cond returning nill is exposed to the developer...why? Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 With / without is the same return (nil). Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 So why its a common way?(according to docs) Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 I think it is just an example to beginners to know the use of t symbol with cond function and nothing's more. Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 Is there any use of t byond the self explained true? Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 Is there any use of t byond the self explained true? As far as I know , no. The use of t at the end of cond function is to pass any value you want if the arguments that passed to the function are not to equal to any value. Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 Not sure what u mean... Do you know what is the use of symbol t at the end of cond function? Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 As i understand....if t equal to t...than return nill Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 Or maybe its a defult if none is true. But why? Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 No, if the variable s is not equal to either "Y" "y" "N" "n" the t symbol at the end would give you an option to set the variable ( for example ) to any value you want or print a message to user etc... Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 So its a defualt action in case none of the expression is true? So its could be (t (prints "illegel value"). So t is just a trigger in endcof the cond? Quote
Tharwat Posted October 18, 2015 Posted October 18, 2015 Close , have a look . (cond ((= s "Y") 1) ((= s "y") 1) ((= s "N") 0) ((= s "n") 0) (t (alert "Variable (s) in not equal to any of the above check outs ")) ) Quote
samifox Posted October 18, 2015 Author Posted October 18, 2015 Close , have a look . (cond ((= s "Y") 1) ((= s "y") 1) ((= s "N") 0) ((= s "n") 0) (t (alert "Variable (s) in not equal to any of the above check outs ")) ) Its not what i meant? Quote
Lee Mac Posted October 18, 2015 Posted October 18, 2015 Put simply, a test expression of 't' will always be validated and so this represents a default condition for when all other conditions are not met; such a condition is by no means necessary, but usually provided by the documentation to help explain how to include a default condition. It looks like you understand this. Quote
hugha Posted October 19, 2015 Posted October 19, 2015 The equivalent in another syntax style could be if (s=="Y") return 1 elseif (s=="y") return 1 elseif (s=="N") return 0 elseif (s=="n") return 0 else alert( "Variable (s) in not equal to any of the above check outs ") endif Think of (t ....) as being an all-inclusive "else" or "otherwise". Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.