Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3345 > unrolled thread

Equivalent code to the bool() built-in function

Started bycandide <candide@free.invalid>
First post2011-04-16 22:24 +0200
Last post2011-04-18 11:19 +0200
Articles 6 on this page of 46 — 18 participants

Back to article view | Back to comp.lang.python


Contents

  Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-16 22:24 +0200
    Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 13:58 -0700
      Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:38 +1000
        Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
          Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 17:16 -0700
          Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 12:39 +1000
            Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 10:38 +0200
              Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-17 18:46 +1000
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:12 +1200
                  Re: Equivalent code to the bool() built-in function John Nagle <nagle@animats.com> - 2011-04-18 12:58 -0700
                    Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:18 +1200
                    Re: Equivalent code to the bool() built-in function Christian Heimes <lists@cheimes.de> - 2011-04-19 03:39 +0200
                    Re: Equivalent code to the bool() built-in function Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-04-19 11:53 +0530
                      Re: Equivalent code to the bool() built-in function Grant Edwards <invalid@invalid.invalid> - 2011-04-19 14:23 +0000
                        Re: Equivalent code to the bool() built-in function Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-04-19 08:43 -0700
                          Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-20 11:59 +1200
                        Re: Equivalent code to the bool() built-in function Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-04-28 16:45 +0000
                          Re: Equivalent code to the bool() built-in function Duncan Booth <duncan.booth@invalid.invalid> - 2011-04-28 17:18 +0000
                    Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 16:26 +1000
                      Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-19 08:43 +0000
                        Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 19:00 +1000
                        Re: Equivalent code to the bool() built-in function Westley Martínez <anikom15@gmail.com> - 2011-04-19 06:43 -0700
              Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 19:46 +1000
                Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 01:22 +0200
                  Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 09:46 +1000
                  Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:08 +1200
                  Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 00:22 +0000
                    Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 10:52 +1000
                    Re: Equivalent code to the bool() built-in function Duncan Booth <duncan.booth@invalid.invalid> - 2011-04-18 10:01 +0000
              Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-17 21:11 +1100
        Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 10:45 +1100
          Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 10:36 +1000
        Re: Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 11:52 +1000
        Re: Re: Equivalent code to the bool() built-in function Dave Angel <davea@ieee.org> - 2011-04-17 21:46 -0400
        Re: Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 14:16 +1100
        Re: Equivalent code to the bool() built-in function Ned Deily <nad@acm.org> - 2011-04-17 21:40 -0700
        Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 14:53 +1000
          Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:22 +1200
            Re: Equivalent code to the bool() built-in function Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-04-28 16:55 +0000
        Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-17 22:49 -0700
          Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 06:14 +0000
        Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 16:03 +1000
    Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:13 +1000
      Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
    Re: Equivalent code to the bool() built-in function Raymond Hettinger <python@rcn.com> - 2011-04-18 01:33 -0700
      Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 11:19 +0200

Page 3 of 3 — ← Prev page 1 2 [3]


#3461

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-04-18 06:14 +0000
Message-ID<4dabd6c2$0$29991$c3e8da3$5496439d@news.astraweb.com>
In reply to#3457
On Sun, 17 Apr 2011 22:49:41 -0700, Chris Rebert wrote:

>> Pro: You can do anything.
>> Con: You can do anything.
> 
> I think someone already beat you to it. They call their invention
> "Lisp". :-P

Also Forth.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#3459

FromChris Angelico <rosuav@gmail.com>
Date2011-04-18 16:03 +1000
Message-ID<mailman.498.1303106594.9059.python-list@python.org>
In reply to#3349
On Mon, Apr 18, 2011 at 3:49 PM, Chris Rebert <clp2@rebertia.com> wrote:
>> Pro: You can do anything.
>> Con: You can do anything.
>
> I think someone already beat you to it. They call their invention "Lisp". :-P

Bah! Lisp comes, out of the box, with far too many features! No no no.
If you want the + operator to add two numbers, you have to say so!
(Obviously there'll be extensive use of #include or equivalent.)

It started out as a serious idea - a really clean language that would,
like Lua or Python, be nicely embeddable in larger programs - and
specifically, I wanted an expression evaluator that could have
d-notation added to it. But the realisation that such a language
consisted of a foot, a machine gun, and a belt of ammunition kinda led
to it being dropped.

ChrisA

[toc] | [prev] | [next] | [standalone]


#3348

FromBen Finney <ben+python@benfinney.id.au>
Date2011-04-17 07:13 +1000
Message-ID<87oc45hpc7.fsf@benfinney.id.au>
In reply to#3345
candide <candide@free.invalid> writes:

> Is the bool_equivalent() function really equivalent to the bool()
> built-in function ?

The ‘bool’ built-in is not a function.

    >>> type(bool)
    <type 'type'>

-- 
 \          “Generally speaking, the errors in religion are dangerous; |
  `\    those in philosophy only ridiculous.” —David Hume, _A Treatise |
_o__)                                           of Human Nature_, 1739 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#3359

Fromcandide <candide@free.invalid>
Date2011-04-17 01:51 +0200
Message-ID<4daa2b8d$0$32037$426a74cc@news.free.fr>
In reply to#3348
Le 16/04/2011 23:13, Ben Finney a écrit :

> The ‘bool’ built-in is not a function.
>
>      >>>  type(bool)
>      <type 'type'>
>


Oops, unfortunate confusion!! but built-in types and built-in functions 
are sometimes so similar from the user's point of view ;)

All the same, you can notice that the official documentation describes 
bool() as a built-in function, cf. 
http://docs.python.org/library/functions.html

[toc] | [prev] | [next] | [standalone]


#3473

FromRaymond Hettinger <python@rcn.com>
Date2011-04-18 01:33 -0700
Message-ID<206407e0-4e33-4b11-a8ae-b130f915ebbb@a19g2000prj.googlegroups.com>
In reply to#3345
On Apr 16, 1:24 pm, candide <cand...@free.invalid> wrote:
> Consider the following code :
>
> # --------------------------------------
> def bool_equivalent(x):
>      return True if x else False

It's faster to write:

def bool_equivalent(x):
    return not not x


Raymond

[toc] | [prev] | [next] | [standalone]


#3477

Fromcandide <candide@free.invalid>
Date2011-04-18 11:19 +0200
Message-ID<4dac0220$0$16749$426a34cc@news.free.fr>
In reply to#3473
Le 18/04/2011 10:33, Raymond Hettinger a écrit :

>> # --------------------------------------
>> def bool_equivalent(x):
>>       return True if x else False
>
> It's faster to write:
>
> def bool_equivalent(x):
>      return not not x
>


faster and ... smarter ;)

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.python


csiph-web