On Nov 18, 2019, at 10:27, Random832 <random...@fastmail.com> wrote:
> 
> On Mon, Nov 18, 2019, at 13:00, Andrew Barnert via Python-ideas wrote:
>>    def f(a, b): return a**(b+1)
>>    g = partial(f, b==2)
>>    h = lambda x: f(x, 2)
>> 
>> Python can’t tell the difference between f, g, and h; they’re all 
>> variables. An IDE could keep track of the fact that f was bound by a 
>> def statement, and g and h by assignment. But I’m not sure why you’d 
>> want it to. After all, they’re all variables with callable values. Why 
>> should f(2,3) be colored differently from g(4)?
> 
> I think, more or less, "a function" can be regarded as "a *constant* whose 
> value is callable and is not type-like" [where type-like includes types, 
> abstract base classes, and type hint objects], regardless of how it was 
> obtained.

Well, none of f, g, and h are immutable values, or constant names.

But I take your point. An IDE that could actually understand all of these 
things as “functions” as distinct from other kinds of names, that would be 
pretty cool, if very difficult.

Still, is it really the “probably not mutated or rebound” that’s the important 
distinction here, or just the “callable like a function” part? (Or maybe even 
“called like a function in this code”? I’m not sure what coloring you’d ideally 
want inside the body of higher-order functions, to be honest… Maybe the answer 
is to look at what highlighters for F#, Scala, or Haskell do, and whether 
anyone ever wishes for more?)

While we’re at it, int is literally a type, and yet we normally think of int(s, 
base=16) as a function call rather than a type call. On second thought, maybe 
that “we” only includes people who’ve been using Python since 2.2 or longer… 
But the larger point that you can’t easily distinguish between types and 
functions is important to Python. When a function wants a “factory” you often 
just pass a type T rather than lambda *a, **kw: T(*a, **kw), but for less 
trivial cases you pass a function (or, for that matter, a classmethod intended 
to act as an alternate constructor). There are things in the stdlib that look 
like type constructors but aren’t. And so on.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NEHSMDF46TPC43U2IRKNZPY3DCPWDKEQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to