Re: I love ternary ifs, don't you?

2008-11-19 Thread Ricardo Aráoz
Ed Leafe wrote:
 On Nov 18, 2008, at 4:43 PM, Paul McNett wrote:

   
 But yes, I love iif(), and wish Python had it.
 


 def iif(comp, trueVal, falseVal):
   return {True: trueVal, False: falseVal}[bool(comp)]

   I think that was one of the first Python scripts I ever wrote!
   

Python DOES have it built in (at least as of 2.5), check 2.5 docs under
What's New - Pep 308 :

 x = true_value if condition else false_value


And if you wish a one liner do case then you can do :

x = {'one possibility': 1
, 'another one':2
, 'the next one is numeric':3
, 125: 4}.get(test_expression, 'Not found')

(yup smarties, it is a one liner even if I choose to span it through
multiple lines ;c)  )







___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


I love ternary ifs, don't you?

2008-11-18 Thread Matt Slay
I just love this:

 

  llNonCust=iif(alltrim(QuoteInf.cust_num)=='NONE', .t., .f.)

 

 

 

Rather than:

 

   If alltrim(QuoteInf.cust_num)=='NONE'

llNonCust=.t.

   else

llNonCust=.f.

   endif 

  

 

 

 

 



--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


RE: I love ternary ifs, don't you?

2008-11-18 Thread Tracy Pearson
Or

llNonCust = ( alltrim(QuoteInf.cust_num)=='NONE' )

-Original Message-
From: Matt Slay
Sent: Tuesday, November 18, 2008 5:03 PM

I just love this:

 

  llNonCust=iif(alltrim(QuoteInf.cust_num)=='NONE', .t., .f.)

 

 

 

Rather than:

 

   If alltrim(QuoteInf.cust_num)=='NONE'

llNonCust=.t.

   else

llNonCust=.f.

   endif 




___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: I love ternary ifs, don't you?

2008-11-18 Thread Ed Leafe
On Nov 18, 2008, at 4:02 PM, Matt Slay wrote:

  llNonCust=iif(alltrim(QuoteInf.cust_num)=='NONE', .t., .f.)

You like that better than:

llNonCust = (ALLTRIM(QuoteInf.cust_num) == NONE)



-- Ed Leafe





___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: I love ternary ifs, don't you?

2008-11-18 Thread Paul McNett
Ed Leafe wrote:
 On Nov 18, 2008, at 4:43 PM, Paul McNett wrote:
 
 But yes, I love iif(), and wish Python had it.
 
 
 def iif(comp, trueVal, falseVal):
   return {True: trueVal, False: falseVal}[bool(comp)]
 
   I think that was one of the first Python scripts I ever wrote!

I know I could write it; I wish it were built-in.

Paul



___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: I love ternary ifs, don't you?

2008-11-18 Thread Ed Leafe
On Nov 18, 2008, at 6:42 PM, Paul McNett wrote:

 I know I could write it; I wish it were built-in.


I know you could write it, too; I was just pointing out that my first  
instinct in Python was to mimic the way Fox worked. Since then I've  
come to appreciate that it isn't built-in. What if instead of choosing  
between two states, you wanted to choose between 3? Or 4? Or 16?  
Having a single idiom for accomplishing that need is cleaner IMO, and  
I no longer miss iif().


-- Ed Leafe





___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: I love ternary ifs, don't you?

2008-11-18 Thread Paul McNett
Ed Leafe wrote:
 On Nov 18, 2008, at 6:42 PM, Paul McNett wrote:
 
 I know I could write it; I wish it were built-in.
 
 
   I know you could write it, too; I was just pointing out that my first  
 instinct in Python was to mimic the way Fox worked. Since then I've  
 come to appreciate that it isn't built-in. What if instead of choosing  
 between two states, you wanted to choose between 3? Or 4? Or 16?  
 Having a single idiom for accomplishing that need is cleaner IMO, and  
 I no longer miss iif().

I guess you are right: using the dict approach would work as a one-liner of any 
length, which was the whole point of the iif(). And I guess you are right on 
another 
thing too: I don't really miss iif() either. I was just trying to contribute to 
the 
conversation. :)

Paul



___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: I love ternary ifs, don't you?

2008-11-18 Thread Jeff Johnson
Kind of like play-doh, huh?  That was a great article, by the way.

Jeff

Jeff Johnson
[EMAIL PROTECTED]
SanDC, Inc.
623-582-0323
Fax 623-869-0675

Phoenix Python User Group - [EMAIL PROTECTED]

Ed Leafe wrote:
 On Nov 18, 2008, at 4:43 PM, Paul McNett wrote:
 
 But yes, I love iif(), and wish Python had it.
 
 
 def iif(comp, trueVal, falseVal):
   return {True: trueVal, False: falseVal}[bool(comp)]
 
   I think that was one of the first Python scripts I ever wrote!
 
 
 -- Ed Leafe
 
 
 
 
 
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.