4 ms·
The scheme standard actually bit my sorry behind recently. I was porting a small library between scheme implementations, and my tests were failing. I had alway
by Johnny_Brahms 10y ago
The scheme standard actually bit my sorry behind recently. I was porting a small library between scheme implementations, and my tests were failing.
I had always thought it was evaluated left->right (which it was in the first scheme implementation), but it is in fact standardised as "The order of evaluation is unspecified". The reason I hadn't noticed before was that most my code is rather functional. Now I was reading a char from a file handle, and peeking it as the other argument.
It failed because read-char is destructive (it changes the position of the file pointer), and since the order was the other way around in the scheme I was porting to, all the procedures relying on my "read-until" method started failing left and right.
It just took me ~20 years to figure it out...
- agumonkey 10y agoouch.
- sigjuice 10y agoWould this be an issue in Common Lisp? I believe CL function arguments are evaluated left-to-right.
- lispm 10y agoThat's right. The standard says left to right. It's not good style to exploit that, but you can.
- fiddlerwoaroof 10y agoIt is undefined in Common Lisp whether or not the car of a form is resolved to a function before or after the other arguments, iirc
- Johnny_Brahms 10y agoYup. Did not feel great. The worst part is that I admitted to writing code that rely on order of evaluation on Hackernews. To my defense it is _very_ old code that I converted from an even older turbo Pascal program I wrote as a teenager
- Johnny_Brahms 10y agoTo clarify: the bug took about 3 minutes to figure out. Learning the evaluation order of procedure arguments is undefined took 20 years though :)
- agumonkey 10y agoAnd I had no idea it was officially fixed ordered in standard. I've read mentions in papers but I never realized what they meant.
- Johnny_Brahms 10y agoWell: The thing is that it is _not_ fixed. It is defined as unspecified.