# Remind me

5 messages
Open this post in threaded view
|

## Remind me

 ```What's the equivalent Lua idiom for C's ? : operator(s)? Obviously I could do it with a function, but that seems a little heavy-weight. Example: Simplify the following: print("Is today Sunday? " .. (function (dow) if dow == 0 then return "yes" else return "no" end end) (0)) Thanks, Curt ```
Open this post in threaded view
|

## Re: Remind me

 ```> print("Is today Sunday? " .. (function (dow) if dow == 0 then return > "yes" else return "no" end end) (0)) print ("Is today Sunday? " .. (function (dow) return dow == 0 and "yes" or "no" end) (0)) -- http://www.mupsych.org/~rrt/ | The only person worth beating is yourself ```
Open this post in threaded view
|

## RE: Remind me

 In reply to this post by Curt Carpenter ``` > dow = true > print("Is today Sunday? ", dow and "yes" or "no") Is today Sunday? yes > dow = false > print("Is today Sunday? ", dow and "yes" or "no") Is today Sunday? no > > -----Original Message----- > From: Curt Carpenter [[hidden email]] > Sent: Friday, October 17, 2003 4:45 PM > To: Lua list > Subject: Remind me > > What's the equivalent Lua idiom for C's ? : operator(s)? Obviously I > could do it with a function, but that seems a little heavy-weight. > > Example: Simplify the following: > print("Is today Sunday? " .. (function (dow) if dow == 0 then return > "yes" else return "no" end end) (0)) > > Thanks, > > Curt ```
 In reply to this post by Curt Carpenter ```In other words C --> CONDITION ? X : Y Lua --> CONDITION and X or Y AB -----Original Message----- From: Nick Trout [[hidden email]] Sent: Friday, October 17, 2003 4:49 PM To: Lua list Subject: RE: Remind me > dow = true > print("Is today Sunday? ", dow and "yes" or "no") Is today Sunday? yes > dow = false > print("Is today Sunday? ", dow and "yes" or "no") Is today Sunday? no > > -----Original Message----- > From: Curt Carpenter [[hidden email]] > Sent: Friday, October 17, 2003 4:45 PM > To: Lua list > Subject: Remind me > > What's the equivalent Lua idiom for C's ? : operator(s)? Obviously I > could do it with a function, but that seems a little heavy-weight. > > Example: Simplify the following: > print("Is today Sunday? " .. (function (dow) if dow == 0 then return > "yes" else return "no" end end) (0)) > > Thanks, > > Curt ```
 ```Am 18.10.03 02:28 schröbte Bilyk, Alex: ```In other words ```C --> CONDITION ? X : Y Lua --> CONDITION and X or Y `````` But be careful! It doesn't work if X has a false value: local boolvar = true print( "(not boolvar) is:", boolvar and false or true ) boolvar = false print( "(not boolvar) is:", boolvar and false or true ) prints "(not boolvar) is: true" in both cases. `````` AB `````` Philipp ```