code blocks in Python

Hung Jung Lu hungjunglu at yahoo.com
Mon Nov 24 18:27:09 EST 2003


Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.1035.1069703636.702.python-list at python.org>...
> 
> You should be able to express the desired semantics of your extension to the
> language without requiring us to execute code.  I have yet to see an
> explanation of why you want
> 
>     def c:
>         x += 1
> 
> added to the language.  I can guess that it binds c to a "code block".  How
> do I use it?  The above is illegal syntax in Python today.  Am I supposed to
> guess how to use it?  That has nothing to do with compile().  Am I supposed
> to run it with the exec statement or do you envision me just inserting
> 
>     c
> 
> into my code?

Skip: being you a Python old timer, I think you are just grumbling for
no good reason. :)

Before anything else, people are already jumping into implementation
details, optimization, syntax, etc. I am barely starting to look at
whether there have been previous existing efforts, and if so, why were
they discarded, etc.

> 
> What exactly have you given me that I couldn't have done with
> 
>     x = 1
>     x += 1
> 

I come back again to repeat it one more time: the compile() function
already exists and works in Python. Before you do your posting, please
think about the compile() function first. (Do I need to say it one
more time? I don't mind.)

So, let me try to pretend I am Skip Montanaro, and follow through with
the process.

(a) OK, I have been told that compile() function exists in 
    Python.
(b) I am complaining that I can do
    x = 1
    x += 1
    without resorting to codeblocks. So there is no need for 
    codeblocks. Codeblocks are useless, good for nothing.
(c) OK, one more time, I have been told that compile() function 
    exists and works in Python. Everytime I talk about codeblocks, 
    I need to think about the compile() function first.
(d) Aha! So by analogy, there is no need for the compile() 
    function in Python. I get it now!
(e) Wait a second... searching through the Python newsgroup 
    archive I find hundreds if not thousands of messages 
    related to the usage of the compile() function. So the 
    compile() function can't be useless. Either thousands of 
    Python users are wrong, or I have not been careful in my 
    thinking process.
(f) Hmm... let me look at those messages and try to understand 
    how people are using the compile() function.
(g) Aha! The compile() function is not useless. I know how to 
    use it, now.
(h) Aha! Codeblocks are not useless.
(i) Aha! So codeblocks are analogous to the compile() function,
    the only difference is that codeblocks are compiled at
    compile time. The compile function compiles the code string
    at runtime.
(j) Wait, I think Hung Jung has said everything before in his 
    messages.

Bingo! Now you get it.

Hung Jung




More information about the Python-list mailing list