Re: [Python-ideas] Another way to avoid clumsy lambdas, while adding new functionality
Just for the record, I never called them bills just because they contain a dollar sign! I was thinking of a short word which describes an expression who's evaluation changes depending on the local circumstances. Like a legal bill, not a dollar bill. The name macro doesn't really work, as it's only an expression, it's not a code block. --- The idea was never to start passing complex expressions around the place. It was just to allow a function to take an expression containing about one or two names, and evaluate the expression internally, so this... func(lambda foo: foo > 0) ...can become... func($foo > 0) Other uses are there, and might be helpful from time to time, but it's mainly about cleaning up APIs. I personally work with user facing Python APIs all day, and users are generally programming interactively, so perhaps my take is atypical. --- What the hell is a thunk anyway? It's a horrible name. --- On the jQuery like syntax, $(foo), that might work and might do away with the issue of expressions containing bills always evaluating to bills. I took that too far. Good point. Cheers
On Wed, Mar 05, 2014 at 12:41:10PM +0000, Carl Smith wrote:
Just for the record, I never called them bills just because they contain a dollar sign! I was thinking of a short word which describes an expression who's evaluation changes depending on the local circumstances. Like a legal bill, not a dollar bill.
Hmmm. Well, I don't really get the connection between legal bills and delayed evaluation, and I still really dislike the name.
The name macro doesn't really work, as it's only an expression, it's not a code block.
There is nothing about macros that *require* them to accept a full block of code. In fact, there are multiple different meanings for macro, although they are all related they do have significant differences: http://en.wikipedia.org/wiki/Macro_%28computer_science%29 Macros in C are not the same kind of thing as macros in Lisp.
---
The idea was never to start passing complex expressions around the place.
What you consider a complex expression somebody else may consider a simple expression. Unless you want to demand some arbitrary hard limit on complexity (and how do you measure complexity?) this "bill" system would have to allow the exact same types of expressions that are legal elsewhere in Python. [...]
What the hell is a thunk anyway? It's a horrible name.
Wikipedia is your friend: http://en.wikipedia.org/wiki/Thunk Also, more here: http://c2.com/cgi/wiki?CallByName The meaning of thunk I'm referring to comes from the call-by-name argument passing model. Suppose we pass an expression to a function: function(arg=x-1) and the body of the function looks like this: if arg > 1: y = arg + 1 else: y = arg - 1 return y*arg In the "call-by-name" model, the function body executes like this: if (x+1) > 1: y = (x+1) + 1 else: y = (x+1) - 1 return y*(x+1) which not only duplicates the "x+1" part four times, but may require evaluating it three times. To avoid this wasteful duplication, the compiler creates a special thunk value, which is something like a function with no arguments: def thunk(): if cache is None: cache = x-1 return cache (This should be considered pseudo-code, not the exact way Algol or Haskell work -- real thunks also allow you to assign a value back to the "name". Also, technically the presence of a cache makes it call-by-need rather than call-by-name). The body of the function then becomes: if thunk() > 1: y = thunk() + 1 else: y = thunk() - 1 return y*thunk() So as you can see, what I've been calling a thunk is not precisely like Algol thunks. One thing which is missing is the dynamic scoping: in the thunk evaluation, the x comes from the caller's scope. But the delayed evaluation part is quite similar, enough that I think the name may be appropriate. Another name for this might be a "promise", as in the promise to execute a computation later. -- Steven
On Mar 5, 2014, at 7:35, Steven D'Aprano
So as you can see, what I've been calling a thunk is not precisely like Algol thunks. One thing which is missing is the dynamic scoping: in the thunk evaluation, the x comes from the caller's scope. But the delayed evaluation part is quite similar, enough that I think the name may be appropriate. Another name for this might be a "promise", as in the promise to execute a computation later.
As I mentioned in one of the previous threads, Alice does lazy evaluation with futures and promises--the same construct it uses for concurrent scheduling, closely related to what Python has in concurrent.futures (Python merges futures and promises into a single object with two different APIs, but the idea is the same). If `expr` evaluated to an object with the same API as a concurrent.futures.Future, that's not a terrible form of explicit evaluation. But if it's doing something like dynamic scoping, it might look pretty misleading.
Carl Smith wrote:
I was thinking of a short word which describes an expression who's evaluation changes depending on the local circumstances. Like a legal bill, not a dollar bill.
Oh. Well, I must say that this was very far from being the first interpretation of the word "bill" that sprang to mind when I saw it. I wasn't even aware of this meaning of the term "legal bill" (although admittedly I'm not used to living in a country where the laws vary wildly from one place to another). -- Greg
On 2014-03-05 23:23, Greg Ewing wrote:
Carl Smith wrote:
I was thinking of a short word which describes an expression who's evaluation changes depending on the local circumstances. Like a legal bill, not a dollar bill.
Oh. Well, I must say that this was very far from being the first interpretation of the word "bill" that sprang to mind when I saw it.
I wasn't even aware of this meaning of the term "legal bill" (although admittedly I'm not used to living in a country where the laws vary wildly from one place to another).
In the UK we talk about "Bills" being put before Parliament. It reminds me of that quotation about the UK and US: “Two nations divided by a common language”. In the UK you can pay a bill using a cheque; in the US you can pay the check using bills (but a "check" is also a (UK) cheque!).
On Mar 5, 2014, at 17:27, MRAB
In the UK we talk about "Bills" being put before Parliament.
In the US also, except it's Congress, and most of our political discussion isn't about bills before Congress or anything else of political consequence.
It reminds me of that quotation about the UK and US: “Two nations divided by a common language”. In the UK you can pay a bill using a cheque; in the US you can pay the check using bills (but a "check" is also a (UK) cheque!).
How many restaurants still accept cheques (or checks)? The only thing they're really used for anymore is paying money to the government... So this bit of confusion will die away. Pants, on the other hand, aren't going away any time soon.
Greg Ewing writes:
MRAB wrote:
In the UK we talk about "Bills" being put before Parliament.
In NZ too, but once it's passed, it's the law -- it's not up to individual interpretation!
NZ is a common law country, is it not?
participants (6)
-
Andrew Barnert
-
Carl Smith
-
Greg Ewing
-
MRAB
-
Stephen J. Turnbull
-
Steven D'Aprano