On Mon, Oct 25, 2021 at 03:47:29AM +1100, Chris Angelico wrote:
> There are two possibilities: either it's a SyntaxError, or it's a
> run-time UnboundLocalError if you omit both of them (in which case it
> would be perfectly legal and sensible if you specify one of them).
>
> I'm currently inclin
On Sun, Oct 24, 2021 at 05:40:55PM +0100, Jonathan Fine wrote:
> Please forgive me if it's not already been considered. Is the following
> valid syntax, and if so what's the semantics? Here it is:
>
> def puzzle(*, a=>b+1, b=>a+1):
> return a, b
We can consider that to be syntactic s
On Sun, Oct 24, 2021 at 05:24:46PM +0400, Abdulla Al Kathiri wrote:
> It’s not a good idea to use a mutable object anyways a default value.
Unless you intend to use a mutable object as a default value, and have
it persist from one call to the next. Then it is absolutely fine.
One of the use-cas
On Mon, Oct 25, 2021 at 4:24 PM Christopher Barker wrote:
>
> On Sun, Oct 24, 2021 at 9:58 AM Chris Angelico wrote:
>>
>> > > def puzzle(*, a=>b+1, b=>a+1):
>> > > return a, b
>
>
>>
>> > >
>> > > Aside: In a functional programming language
>> > > a = b + 1
>> > > b = a + 1
>>
Serhiy Storchaka writes:
> They have. Both function and type classes have constructors
Ah, right. "First-class values", of course they do.
Thanks!
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to pytho
On Sun, Oct 24, 2021 at 9:58 AM Chris Angelico wrote:
> > > def puzzle(*, a=>b+1, b=>a+1):
> > > return a, b
> > >
> > > Aside: In a functional programming language
> > > a = b + 1
> > > b = a + 1
> > > would be a syntax (or at least compile time) error.
>
but it's a NameE
On Mon, Oct 25, 2021 at 3:12 PM Sebastian Berg
wrote:
>
> On Mon, 2021-10-25 at 03:47 +1100, Chris Angelico wrote:
> > On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine
> > wrote:
> > >
> > > Hi
> > >
> > > Please forgive me if it's not already been considered. Is the
> > > following valid syntax, an
+1 to this idea -- thanks Chris A!
On Sat, Oct 23, 2021 at 2:01 PM Bruce Leban wrote:
> Here's one way you could imagine writing this today:
>>
>
> def bisect(a, x, lo=0, hi=lambda: len(a)):
> hi = hi() if callable(hi) else hi
> ...
>
> which is clumsy and more importantly do
Hi Chris
You wrote:
In fact, on subsequent consideration, I'm inclining more strongly
> towards SyntaxError, due to the difficulty of explaining the actual
> semantics. Changing the PEP accordingly.
Your PEP, so your choice. I now think that if implemented, your PEP adds to
the Python compiler
On Sat, Oct 23, 2021 at 5:16 PM Chris Angelico wrote:
> # Very common: Use None and replace it in the function
> def bisect_right(a, x, lo=0, hi=None, *, key=None):
> if hi is None:
> hi = len(a)
>
Note that if this is changed to
def bisect_right(a, x, lo=0, hi[w
On Sun, 24 Oct 2021, Erik Demaine wrote:
I think the semantics are easy to specify: the argument defaults get
evaluated for unspecified order, in left to right order as specified in the
def. Those may trigger exceptions as usual.
Sorry, that should be:
I think the semantics are easy to spec
On Mon, Oct 25, 2021 at 4:29 AM Erik Demaine wrote:
>
> On Sun, 24 Oct 2021, Erik Demaine wrote:
>
> > I think the semantics are easy to specify: the argument defaults get
> > evaluated for unspecified order, in left to right order as specified in the
> > def. Those may trigger exceptions as usua
On Mon, 25 Oct 2021, Chris Angelico wrote:
On Mon, Oct 25, 2021 at 3:47 AM Chris Angelico wrote:
On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine wrote:
Please forgive me if it's not already been considered. Is the following valid
syntax, and if so what's the semantics? Here it is:
def
On 24/10/2021 03:48, Steven D'Aprano wrote:
On Sun, Oct 24, 2021 at 01:16:02PM +1100, Chris Angelico wrote:
And is it really a problem if we delay the late-binding to the point
where the value is actually needed? Here's a toy example:
# Using only early binding.
def function(spam,
On Mon, 2021-10-25 at 03:47 +1100, Chris Angelico wrote:
> On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine
> wrote:
> >
> > Hi
> >
> > Please forgive me if it's not already been considered. Is the
> > following valid syntax, and if so what's the semantics? Here it is:
> >
> > def puzzle(*, a=
More about thunks. I've resisted the temptation to look at the Wikipedia
page -- this is from memory.
On Sat, Oct 23, 2021 at 11:39 PM Steven D'Aprano
wrote:
> > I would prefer to see this situation handled as part of a
> > larger-scale
> > change of adding some kind of "inline lambd
On Sun, 24 Oct 2021, Chris Angelico wrote:
Is anyone interested in coauthoring this with me? Anyone who has
strong interest in seeing this happen - whether you've been around the
Python lists for years, or you're new and interested in getting
involved for the first time, or anywhere in between!
On Mon, Oct 25, 2021 at 3:47 AM Chris Angelico wrote:
>
> On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine wrote:
> >
> > Hi
> >
> > Please forgive me if it's not already been considered. Is the following
> > valid syntax, and if so what's the semantics? Here it is:
> >
> > def puzzle(*, a=>b+1
On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine wrote:
>
> Hi
>
> Please forgive me if it's not already been considered. Is the following valid
> syntax, and if so what's the semantics? Here it is:
>
> def puzzle(*, a=>b+1, b=>a+1):
> return a, b
>
> Aside: In a functional programming l
Hi
Please forgive me if it's not already been considered. Is the following
valid syntax, and if so what's the semantics? Here it is:
def puzzle(*, a=>b+1, b=>a+1):
return a, b
Aside: In a functional programming language
a = b + 1
b = a + 1
would be a syntax (or at least compi
Yes! Exactly that.
I believe (and believed in some discussions here since maybe 4-5 years ago)
that having something close to the dask.delayed() function baked into the
language works be a good think.
And as a narrow point, it could address the narrower late-bound function
argument matter as one
On Sun, Oct 24, 2021, 10:11 AM Chris Angelico
> Not sure I understand. Your example was something like:
>
> def fn2(thing):
> a, b = 13, 21
> x = 5
> print("Thing is:", thing)
>
> def f(x=defer: a + b):
> a, b = 3, 5
> fn2(defer: x)
> return x
>
> So inside f(), "defer: a +
On Mon, Oct 25, 2021 at 1:16 AM Zomatree . wrote:
>
> What would the the syntax for the default be, i would presume just a single
> expression like a lambda, but what about something like an async function,
> for example:
> ```py
> async def foo(arg=>await get_arg()):
> ```
> would this work?
T
What would the the syntax for the default be, i would presume just a single
expression like a lambda, but what about something like an async function, for
example:
```py
async def foo(arg=>await get_arg()):
```
would this work?
___
Python-ideas mailing
On Mon, Oct 25, 2021 at 12:47 AM David Mertz, Ph.D.
wrote:
>
> On Sun, Oct 24, 2021, 12:20 AM Chris Angelico
>>
>> How would it know to look for a and b inside fn2's scope, instead of looking
>> for x inside fn2's scope?
>
>
> The same way 'eval("a+b")' knows to look in the local scope when evalu
On Sun, Oct 24, 2021 at 09:39:27AM -0400, David Mertz, Ph.D. wrote:
> This has been a topic of other threads over the years, and something I've
> wanted at least since I first worked with Dask's 'delayed()' function.
You mean this?
https://docs.dask.org/en/latest/delayed.html
--
Steve
__
Hi Serhiy
Thank you for so clearly explaining how names get passed to function and
class constructors.
You also wrote:
> We do not have generalized way to call arbitrary constructor with
> automatically passing __name__, __qualname__ and __module__. And it would
> be convenient.
>
> create n
On Sun, Oct 24, 2021 at 12:39:38PM +0100, Matt del Valle wrote:
> I'll confess though I'm not a fan of any of the alternate syntaxes. I think
> => works really well, particularly if lambdas in the form: `(*args) =>
> expr` are added at some point in the future
So if we have the arrow shortcut for
On Sun, Oct 24, 2021, 12:20 AM Chris Angelico
> How would it know to look for a and b inside fn2's scope, instead of
> looking for x inside fn2's scope?
>
The same way 'eval("a+b")' knows to look in the local scope when evaluated.
I mean, of course 'x' could be rebound in some scope before it wa
On Sun, Oct 24, 2021, 12:25 AM Guido van Rossum
> I am worried that this side-thread about dynamic scopes (which are a
> ridiculous idea IMO) will derail the decent proposal of the PEP.
>
It's really not a suggestion about dynamic scoping but about more
generalized deferred computation.
This has
Yeah I realized that when I went to my laptop hhh. Hence the previous email
correcting it.
> On 24 Oct 2021, at 5:19 PM, Steven D'Aprano wrote:
>
> On Sun, Oct 24, 2021 at 04:57:16PM +0400, Abdulla Al Kathiri wrote:
>
>> def insort_right(a, x, lo=0, hi={len(a)}, *, key=None): …
>
> That's a
Oops I forgot that this could evaluate to a set if “a” was defined beforehand.
Maybe not a good idea after all. It’s not a good idea to use a mutable object
anyways a default value.
> On 24 Oct 2021, at 4:57 PM, Abdulla Al Kathiri
> wrote:
>
> How about this syntax:
>
> def insort_right(a, x
On Sun, Oct 24, 2021 at 04:57:16PM +0400, Abdulla Al Kathiri wrote:
> def insort_right(a, x, lo=0, hi={len(a)}, *, key=None): …
That's already legal syntax for a default value of a set with one
element, len(a).
--
Steve
___
Python-ideas mailing lis
On Sun, Oct 24, 2021 at 10:18:52PM +1100, Steven D'Aprano wrote:
> Find some languages (Lisp, Smalltalk, any others?) and show that they
> are abused by people in that community.
Oops, sorry I left out a clause.
Find some language **with late-binding defaults** and show that they are
abused by
How about this syntax:
def insort_right(a, x, lo=0, hi={len(a)}, *, key=None): …
Similar to the expression curly brackets in f-string. If the user didn’t
specify a value for hi, the expression between the curly brackets will be
evaluated and assigned to hi.
Abdulla
Sent from my iPhone
> O
On Sun, Oct 24, 2021 at 11:45 PM Ricky Teachey wrote:
>
> It seems to me that the syntax for late binding could be chosen so as to
> leave the possibility of expansion open in the future, and defer (har har)
> the entire generalized thunk discussion?
>
> So why not go with syntax like this, wher
24.10.21 15:20, Stephen J. Turnbull пише:
> What do you mean by "constructor" here? Normally that word refers to
> methods that populate the attributes of instances (in Python, __init__
> and__new__). But functions and methods don't have such, so you must
> mean something else?
They have. Both f
It seems to me that the syntax for late binding could be chosen so as to
leave the possibility of expansion open in the future, and defer (har har)
the entire generalized thunk discussion?
So why not go with syntax like this, where before the ? just represents a
keyword to be bike shedded ("defer"
Jonathan Fine writes:
> >From my phone.
>
> An important thing about def x and class A is that the strings x and A are
> made available to the constructor for x and A respectively.
What do you mean by "constructor" here? Normally that word refers to
methods that populate the attributes of in
On Sun, Oct 24, 2021 at 9:52 PM Serhiy Storchaka wrote:
>
> 23.10.21 19:07, Chris Angelico пише:
> > _missing = object()
> > def spaminate(thing, count=_missing):
> > if count is _missing: count = thing.getdefault()
> >
> > Proposal: Proper syntax and support for late-bound argument defaults.
Agreed on the point about PEP 661, if this is accepted I don't think it
will have much to offer.
For what it's worth I'm a very strong +1 on PEP 671 as it stands. Thanks
for showing me something I didn't even know I wanted Chris :)
I'll confess though I'm not a fan of any of the alternate syntaxe
On Sun, Oct 24, 2021 at 9:34 PM Paul Moore wrote:
>
> This should probably reference PEP 661 (Sentinel Values) which is
> being discussed on Discourse:
> https://discuss.python.org/t/pep-661-sentinel-values/9126
>
> It's a different proposal, but one of the major motivating use cases
> (if not the
On Sat, Oct 23, 2021 at 11:47:59PM -0700, Brendan Barnwell wrote:
> It's true that any feature can be abused, but I think this
> temptation to shoehorn function logic into the argument list will be
> more
> likely to result in unwieldy signatures than the current situation.
That sh
23.10.21 19:07, Chris Angelico пише:
> _missing = object()
> def spaminate(thing, count=_missing):
> if count is _missing: count = thing.getdefault()
>
> Proposal: Proper syntax and support for late-bound argument defaults.
>
> def spaminate(thing, count=:thing.getdefault()):
> ...
Few y
This should probably reference PEP 661 (Sentinel Values) which is
being discussed on Discourse:
https://discuss.python.org/t/pep-661-sentinel-values/9126
It's a different proposal, but one of the major motivating use cases
(if not the only one) for sentinels is handling function default
values tha
On 2021-10-23 23:33, Steven D'Aprano wrote:
On Sat, Oct 23, 2021 at 08:29:54PM -0700, Brendan Barnwell wrote:
For me the biggest problem with this idea is that it only handles a
subset of cases, namely those that can be expressed as an expression
inlined into the function definition.
On Sat, Oct 23, 2021 at 11:53 PM Steven D'Aprano
wrote:
> If we had thunks, that would give us late binding for free:
>
> def bisect(a, x, lo=0, hi=thunk len(a), *, key=None)
>
I'm unclear on exactly what the semantics of a thunk would be, but I don't
see how it could do what you want here.
On Sun, Oct 24, 2021 at 5:53 PM Steven D'Aprano wrote:
>
> On Sun, Oct 24, 2021 at 02:09:59PM +1100, Chris Angelico wrote:
>
> > The biggest problem with thunks is knowing when to trigger evaluation.
>
> I think Algol solved that problem by having thunks a purely internal
> mechanism, not a first-
48 matches
Mail list logo