Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

OS/2 must die!


devel / comp.lang.python / Re: code blocks in Python

SubjectAuthor
* Re: code blocks in Pythonjlfivn
`- Re: code blocks in PythonMRAB

1
Re: code blocks in Python

<bc904f8a-ce36-464e-a43b-ae218bad383bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17596&group=comp.lang.python#17596

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:ad4:5848:0:b0:441:4092:c385 with SMTP id de8-20020ad45848000000b004414092c385mr8359928qvb.24.1648203150705;
Fri, 25 Mar 2022 03:12:30 -0700 (PDT)
X-Received: by 2002:ac8:5f11:0:b0:2e1:ee56:ecc with SMTP id
x17-20020ac85f11000000b002e1ee560eccmr8539224qta.286.1648203150426; Fri, 25
Mar 2022 03:12:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Fri, 25 Mar 2022 03:12:30 -0700 (PDT)
In-Reply-To: <vs56mue8hmdob1@news.supernews.com>
Injection-Info: google-groups.googlegroups.com; posting-host=217.180.35.2; posting-account=Ky7_UQoAAAAsUcTeaTzynwEgFIhi1dv3
NNTP-Posting-Host: 217.180.35.2
References: <8ef9bea6.0311221215.804bdb3@posting.google.com>
<vrvjpt7fh4lob8@news.supernews.com> <8ef9bea6.0311221913.427cb53e@posting.google.com>
<8ef9bea6.0311231634.1ca497ac@posting.google.com> <mailman.1009.1069640669.702.python-list@python.org>
<8ef9bea6.0311232220.4e308a4c@posting.google.com> <mailman.1023.1069685306.702.python-list@python.org>
<8ef9bea6.0311241105.e53c47d@posting.google.com> <mailman.1035.1069703636.702.python-list@python.org>
<8ef9bea6.0311241527.61a27b6c@posting.google.com> <vs56mue8hmdob1@news.supernews.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bc904f8a-ce36-464e-a43b-ae218bad383bn@googlegroups.com>
Subject: Re: code blocks in Python
From: 19dmcelw...@daos.uk (jlfivn)
Injection-Date: Fri, 25 Mar 2022 10:12:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 62
 by: jlfivn - Fri, 25 Mar 2022 10:12 UTC

On Monday, 24 November 2003 at 23:54:49 UTC, John Roth wrote:
> "Hung Jung Lu" <hungj...@yahoo.com> wrote in message
> news:8ef9bea6.03112...@posting.google.com...
> > Skip Montanaro <sk...@pobox.com> wrote in message
> news:<mailman.1035.106970...@python.org>...
> > >
> > 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 what?
> Functionality is not added to Python simply because it looks like
> a logical extension of something else that already exists. First,
> you need to show a compelling use case.
> So far, I've seen one thing in your proposal: dynamic binding
> of free variables in a function, rather than static binding. All
> questions of syntax aside, please show me why this matters,
> bearing in mind that I've never programmed in a language
> that has this, and am not going to be convinced by references
> to such languages.
> While I'm not *the* person that has to be convinced (that's Guido),
> I'm probably representative. If you don't manage a compelling
> case for why dynamic binding is a useful option, then you're not going
> to get anywhere with this proposal.
> By the way - if I understand the guts of the proposal, the compile
> function has nothing to do with it, and wouldn't be used to implement
> it in any case.
> John Roth

One use case is modifying the underlying bytecode of the code block to allow features that are not implemented or should not be implemented in python but still make sense in context. For example python-goto is a module that allows you to add goto statements to python code. Currently it has to be applied as a decorator to a function which then needs to be called. Being able to create a code block and then run it instead of having to rap it in a function could be very useful is such cases.
I propose the following syntax:

code_block : #start a code block
print("foobar")

#the code block would be executed immediately
#would print "foobar"

code_block as my_code: #save the code to the named variable;does not execute immediately
print("foobar")
#no output but code is in my_code

exec(my_code)
#would print "foobar"

@with_goto #the code block would be past to the decorator then executed
code_block:
print("ignore the fact that I'm using goto")
goto .cheat
print("goto is a bad idea")
label .cheat

#output :"ignore the fact that I'm using goto"

Re: code blocks in Python

<mailman.363.1648245701.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17597&group=comp.lang.python#17597

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: code blocks in Python
Date: Fri, 25 Mar 2022 21:58:30 +0000
Lines: 57
Message-ID: <mailman.363.1648245701.2329.python-list@python.org>
References: <8ef9bea6.0311221215.804bdb3@posting.google.com>
<vrvjpt7fh4lob8@news.supernews.com>
<8ef9bea6.0311221913.427cb53e@posting.google.com>
<8ef9bea6.0311231634.1ca497ac@posting.google.com>
<mailman.1009.1069640669.702.python-list@python.org>
<8ef9bea6.0311232220.4e308a4c@posting.google.com>
<mailman.1023.1069685306.702.python-list@python.org>
<8ef9bea6.0311241105.e53c47d@posting.google.com>
<mailman.1035.1069703636.702.python-list@python.org>
<8ef9bea6.0311241527.61a27b6c@posting.google.com>
<vs56mue8hmdob1@news.supernews.com>
<bc904f8a-ce36-464e-a43b-ae218bad383bn@googlegroups.com>
<05fd9979-1ce5-d51d-27b5-7be43ab2b5a3@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de LJw71k3i1LGBkBXIbRY0aQx66cz1My8ilheGerQnHHXQ==
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=k2tjBwFD;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'looks': 0.02;
'underlying': 0.07; 'python.': 0.08; ':-)': 0.09; 'binding': 0.09;
'cases.': 0.09; 'from:addr:python': 0.09; 'received:192.168.1.64':
0.09; 'subject:Python': 0.12; 'syntax': 0.15; 'context.': 0.16;
'executed': 0.16; 'far,': 0.16; 'from:addr:mrabarnett.plus.com':
0.16; 'from:name:mrab': 0.16; 'goto': 0.16; 'languages.': 0.16;
'message-id:@mrabarnett.plus.com': 0.16; 'montanaro': 0.16;
'programmed': 0.16; 'proposal:': 0.16; 'received:plus.net': 0.16;
'static': 0.16; 'subject:code': 0.16; 'wrote:': 0.16; 'python':
0.16; 'code.': 0.17; 'instead': 0.17; 'probably': 0.17;
'implement': 0.19; 'to:addr:python-list': 0.20; 'language': 0.21;
"i've": 0.22; 'first,': 0.22; 'code': 0.23; 'run': 0.23; 'past':
0.25; 'extension': 0.25; 'else': 0.27; 'function': 0.27; 'fact':
0.28; 'output': 0.28; 'sense': 0.28; 'replying': 0.28; 'it,':
0.29; 'header:User-Agent:1': 0.30; 'module': 0.31; 'think': 0.32;
'logical': 0.32; "wouldn't": 0.32; 'received:192.168.1': 0.32;
'but': 0.32; "i'm": 0.33; 'able': 0.34; 'header:In-Reply-To:1':
0.34; 'following': 0.35; 'currently': 0.37; 'using': 0.37;
'received:192.168': 0.37; 'way': 0.38; 'could': 0.38; 'added':
0.39; 'this,': 0.39; 'use': 0.39; 'block': 0.39; 'wrote': 0.39;
'still': 0.40; 'case.': 0.40; 'proposal,': 0.40; 'something':
0.40; 'should': 0.40; 'seen': 0.62; 'proposal.': 0.62;
'received:212': 0.62; 'come': 0.62; 'simply': 0.63; 'your': 0.64;
'named': 0.65; 'back': 0.67; 'bad': 0.67; '2003': 0.69; 'free':
0.72; 'manage': 0.73; 'features': 0.75; 'implemented': 0.76;
'time:': 0.81; '(do': 0.84; 'jung': 0.84; 'matters,': 0.84;
'exists': 0.91; 'skip:n 40': 0.91; 'time?': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1648245512; bh=+Ig5XnB7aFjpwaNkwJZSb/rkSt61QhGfWmvqNC2P7N0=;
h=Date:Subject:To:References:From:In-Reply-To;
b=k2tjBwFD1ZA6BuCT57zJryJWWWfjqh2LH5pELwX0OcvNbhSJTzjHix6DZsKMRNo1Q
0d/uRqUJ6+dEApqmpsr/G0yILKXKq2Cel1Bma+ezNjtDWDPJLVhjZ2O8N7HUICy4XM
mB0JgTSKrKyYo7I0hUBGynucE+VFONrVyEz+cXLa2F+eshDhA/7r4hA1RXv0q22RPx
7XlZbtDnE8ho5BrP6x8+BRJAx8QDZa5gvQpbUInAuLpiAh+QguMTuy0HJ8PxIW5a5I
SMwsXEOwJkOoEV5c7MK7P1urSblcO5N6fWtXSB+23jA0mFJqQ6yXShxpvBxmSN+VKS
66NCeMzbuAKdQ==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=AKknf/Zy c=1 sm=1 tr=0 ts=623e3b08
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=CjxXgO3LAAAA:8 a=1XWaLZrsAAAA:8 a=ybZZDoGAAAAA:8
a=8AHkEIZyAAAA:8 a=2rfK8zm8I9MArTT0yiQA:9 a=QEXdDO2ut3YA:10
a=0RhZnL1DYvcuLYC8JZ5M:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-GB
In-Reply-To: <bc904f8a-ce36-464e-a43b-ae218bad383bn@googlegroups.com>
X-CMAE-Envelope: MS4xfI8VcnNReK4goNYw9Tu5B4kPlv3EIlj4+Ti/cBx9IfPalVWjkhh15SNiNqTObW456t2OlWfiYBSZ7cYC688+omunyDmVBqVRWdlRVJ3u45/7N8+wB0w4
ryiWmmbWskU3OlXaE7lXCUYV0qmKRxPWUlhGAs9RDLc0xPZthi87uAAzoWC5Yzgji64x+IZPspWh6yRjIM8W/JHsm67IVeQz32w=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <05fd9979-1ce5-d51d-27b5-7be43ab2b5a3@mrabarnett.plus.com>
X-Mailman-Original-References: <8ef9bea6.0311221215.804bdb3@posting.google.com>
<vrvjpt7fh4lob8@news.supernews.com>
<8ef9bea6.0311221913.427cb53e@posting.google.com>
<8ef9bea6.0311231634.1ca497ac@posting.google.com>
<mailman.1009.1069640669.702.python-list@python.org>
<8ef9bea6.0311232220.4e308a4c@posting.google.com>
<mailman.1023.1069685306.702.python-list@python.org>
<8ef9bea6.0311241105.e53c47d@posting.google.com>
<mailman.1035.1069703636.702.python-list@python.org>
<8ef9bea6.0311241527.61a27b6c@posting.google.com>
<vs56mue8hmdob1@news.supernews.com>
<bc904f8a-ce36-464e-a43b-ae218bad383bn@googlegroups.com>
 by: MRAB - Fri, 25 Mar 2022 21:58 UTC

On 2022-03-25 10:12, jlfivn wrote:
> On Monday, 24 November 2003 at 23:54:49 UTC, John Roth wrote:
>> "Hung Jung Lu" <hungj...@yahoo.com> wrote in message
>> news:8ef9bea6.03112...@posting.google.com...
>> > Skip Montanaro <sk...@pobox.com> wrote in message
>> news:<mailman.1035.106970...@python.org>...
>> > >
>> > 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 what?
>> Functionality is not added to Python simply because it looks like
>> a logical extension of something else that already exists. First,
>> you need to show a compelling use case.
>> So far, I've seen one thing in your proposal: dynamic binding
>> of free variables in a function, rather than static binding. All
>> questions of syntax aside, please show me why this matters,
>> bearing in mind that I've never programmed in a language
>> that has this, and am not going to be convinced by references
>> to such languages.
>> While I'm not *the* person that has to be convinced (that's Guido),
>> I'm probably representative. If you don't manage a compelling
>> case for why dynamic binding is a useful option, then you're not going
>> to get anywhere with this proposal.
>> By the way - if I understand the guts of the proposal, the compile
>> function has nothing to do with it, and wouldn't be used to implement
>> it in any case.
>> John Roth
>
> One use case is modifying the underlying bytecode of the code block to allow features that are not implemented or should not be implemented in python but still make sense in context. For example python-goto is a module that allows you to add goto statements to python code. Currently it has to be applied as a decorator to a function which then needs to be called. Being able to create a code block and then run it instead of having to rap it in a function could be very useful is such cases.
> I propose the following syntax:
>
> code_block : #start a code block
> print("foobar")
>
> #the code block would be executed immediately
> #would print "foobar"
>
> code_block as my_code: #save the code to the named variable;does not execute immediately
> print("foobar")
> #no output but code is in my_code
>
> exec(my_code)
> #would print "foobar"
>
> @with_goto #the code block would be past to the decorator then executed
> code_block:
> print("ignore the fact that I'm using goto")
> goto .cheat
> print("goto is a bad idea")
> label .cheat
>
> #output :"ignore the fact that I'm using goto"
>
That must be some kind of record, replying to a post from over 18
_years_ ago! :-)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor