On 15/01/24 10:23, Chris Angelico via Python-list wrote:
On Mon, 15 Jan 2024 at 08:15, Left Right <olegsivo...@gmail.com> wrote:
Python grammar rules prevent function definition from
appearing in left-hand side of the head of the for loop.  However, a
variable declaration, which is also a statement, is allowed there.

What is a "variable declaration" in Python? Please elaborate.

We may be in danger of disappearing down an unintended 'rabbit hole' with this side-discussion (he says, with graceful under-statement).


The basic challenge came from my earlier (and blasé) repetition of the Python refrain "everything in Python is an object". Which led to:

<<<
For example, you may say "functions in Python are
objects", but you cannot put a function definition in the head of the
for loop clause.
>>>

Which is logical - to some degree, and in-isolation.

    for def a_function( etc )... in iterable/iterator:

does not make sense. The 'head' (a more generic name, where Python says "target_list", that refines down to 'something which can identify the generated-value'.

So, no, there's an "everything" which (might be) an object but which cannot be used in that scenario.


Two "howevers":

However, instead of looking at the narrow clause, (third comment about wording not being taken as an whole!!!)* the full quotation was:

<<<
In Python, everything is an object. As long as the LHS is a legal-object which makes sense for the situation, it can be used.
>>>

Context!

However, from the docs: "A function definition defines a user-defined function object (see section The standard type hierarchy)". Accordingly, is a function-definition an object? No! It defines an object.

That said, does anyone think that something like:

    for a_function( etc ) in iterable/iterator:

is acceptable?
- see both Python definition and (full-)quotation.

I've not come-across a language which does allow such - YMMV/mea culpa; and am struggling to see how it could possibly be useful.

In-turn, how this discussion could become profitable...


* Looking at the correspondent's email-address (cf 'handle') - and as an unfair stereotype, raises the question of issues related to (English) language-skills - which, arrogantly implies/assumes that native English-speakers are all highly-capable. (?) A negative-interpretation is to note his apparent intelligence, but wonder if failing to represent others' comments fairly is deliberate, or carelessness. Is there an irony in behaving/failing in such, whilst attempting to hold Python's structure to some golden-ideal?


Web.Refs:
https://docs.python.org/3/reference/compound_stmts.html#the-for-statement
https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-target_list
https://docs.python.org/3/reference/compound_stmts.html#function-definitions

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to