pdpinheiro at gmail.com
Wed Jun 17 13:05:24 EDT 2009
On Jun 17, 5:37 pm, Lie Ryan <lie.1... at gmail.com> wrote:
> Steven D'Aprano wrote:
> > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
> >> I was staring at a logic table the other day, and I asked myself, "what
> >> if one wanted to play with exotic logics; how might one do it?"
> > This might be useful for you, and if not useful, at least it might blow
> > your mind like it did mine.
> > (This is not original to me -- I didn't create it. However, I can't find
> > the original source.)
> > Imagine for a moment that there are no boolean values.
> > There are no numbers. They were never invented.
> > There are no classes.
> > There are no objects.
> > There are only functions.
> > Could you define functions that act like boolean values? And could you
> > define other functions to operate on them?
> > def true(x, y):
> > return x
> > def false(x, y):
> > return y
> > def print_bool(b):
> > print b("true", "false")
> String isn't considered object?
> Also, b/true()/false() is a function object, isn't it? Unless function
> is first-class, you can't pass them around like that, since you need a
> function pointer (a.k.a number); but if function is first-class then
> there it is an object.
What Steven was doing was implementing some of the more basic stuff
from Lambda calculus in python. If you're implementing a different
system in an existing language, you'll need to use _some_ facilities
of the original language to interface with the outside world. Anyway,
here's a sample interactive session I just tried:
>>> def a(stuff):
... print stuff
>>> def b(stuff):
functions are first-class citizens in python.
More information about the Python-list