nonlocal fails ?

R.Wieser address at not.available
Fri Nov 15 06:56:02 EST 2019


Michael,

> Well I've only seen this done in languages where other mechanisms
>for returning complex types are not present.

:-) Than you have not seen to many languages I'm afraid.

There are quite a number of languages where /every/ type of argument 
(including values) can be transfered "by reference".  Though some default to 
"by value", where others default to "by reference".

As for "complex types" ?   I don't think a(n ASCII) string can be considered 
any kind of a complex type, but most all languages I know of transfer them 
"by reference" only (though some fake "by value" by using a copy-on-write 
mechanism).

> In C you can either return a pointer to the string (and remember who's
> responsibility it is to free the memory!), or you can allocate memory
> yourself and pass the pointer to a function, like strcpy.

Or pass a reference to an empty pointer, have the procedure allocate the 
memory and return the address of it in that pointer.

And only the second one comes near to what I indicated I asked about: a 
mutable value stored outside the current procedure.

> In Python there is no similar equivalent,

It looks like it

> other than hacks involving passing in mutable objects

The only "hack" I see here is to transfer /mutable/ object, instead of a 
non-mutable one.

> Fair enough, but trying to do 1:1 transliterations isn't going to
> help you learn idiomatic Python.

If I would have wanted that, why would I post here with open questions ? 
But yes, I often refer to how other languages work, in an attempt to get the 
other to tell me whats so special/different about the current languages 
solution for it.

Regards,
Rudy Wieser




More information about the Python-list mailing list