From: Steven D'Aprano on
On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote:

> In most functional languages you just name a function to access it and
> you do it ALL the time.
>
> for example, in if you have a function 'f' which takes two parameters to
> call the function and get the result you use:
>
> f 2 3
>
> If you want the function itself you use:
>
> f

How do you call a function of no arguments?



--
Steven
From: Steven D'Aprano on
On Sun, 31 Jan 2010 14:47:08 -0600, John Bokma wrote:

> An editor can correct the indenting of the braces example but can't with
> this one.
>
> if x:
> if y:
> foo()
> else:
> bar()
>
> While braces might be considered redundant they are not when for one
> reason or another formatting is lost or done incorrectly.

I've heard this argument before, and I don't buy it. Why should we expect
the editor to correct malformed code?

Would you expect your editor to correct this malformed code?

result = sin(x+)y

Why should broken indentation be held to a higher standard than any other
breakage in code?



--
Steven
From: Chris Rebert on
On Sun, Jan 31, 2010 at 2:36 PM, Steven D'Aprano
<steve(a)remove-this-cybersource.com.au> wrote:
> On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote:
>> In most functional languages you just name a function to access it and
>> you do it ALL the time.
>>
>> for example, in if you have a function 'f' which takes two parameters to
>> call the function and get the result you use:
>>
>>  f 2 3
>>
>> If you want the function itself you use:
>>
>>    f
>
> How do you call a function of no arguments?

It's not really a function in that case, it's just a named constant.
(Recall that functions don't/can't have side-effects.)

Cheers,
Chris
--
http://blog.rebertia.com
From: Arnaud Delobelle on
Steven D'Aprano <steve(a)REMOVE-THIS-cybersource.com.au> writes:

> On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote:
>
>> In most functional languages you just name a function to access it and
>> you do it ALL the time.
>>
>> for example, in if you have a function 'f' which takes two parameters to
>> call the function and get the result you use:
>>
>> f 2 3
>>
>> If you want the function itself you use:
>>
>> f
>
> How do you call a function of no arguments?

In a functional language, a function of no arguments will always return
the same value. So, from a non-functional point of vue, f is both the
function and its value.

--
Arnaud
From: Steven D'Aprano on
On Sun, 31 Jan 2010 15:40:36 -0800, Chris Rebert wrote:

> On Sun, Jan 31, 2010 at 2:36 PM, Steven D'Aprano
> <steve(a)remove-this-cybersource.com.au> wrote:
>> On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote:
>>> In most functional languages you just name a function to access it and
>>> you do it ALL the time.
>>>
>>> for example, in if you have a function 'f' which takes two parameters
>>> to call the function and get the result you use:
>>>
>>>  f 2 3
>>>
>>> If you want the function itself you use:
>>>
>>>    f
>>
>> How do you call a function of no arguments?
>
> It's not really a function in that case, it's just a named constant.
> (Recall that functions don't/can't have side-effects.)


>>> time.time(), random.random()
(1264983502.7505889, 0.29974255140479633)
>>> time.time(), random.random()
(1264983505.9283719, 0.74207867411026329)


They don't look terribly constant to me.


There is a difference between a function that does "give me whatever
value is specified by a fixed description" and a function that does "give
me a fixed value".



--
Steven