From: Captain Obvious on 23 Apr 2010 04:18 JUR> (defun closures-from-loop (list) JUR> (let (result) JUR> (loop for el in list do JUR> (let ((el el)) JUR> (push (lambda () (format t "~s~%" el)) result))) JUR> (reverse result))) I think it is well-known idiom. When you know about things like that, chances that you'll introduce bug are fairly low. By the way, this kind of thing also bugs JavaScript developers, but even more -- their "var" construct does not always introduce new bindings, they can only reliably create new bindings via function parameters.
From: His kennyness on 23 Apr 2010 20:08 Captain Obvious wrote: > JUR> (defun closures-from-loop (list) > JUR> (let (result) > JUR> (loop for el in list do > JUR> (let ((el el)) > JUR> (push (lambda () (format t "~s~%" el)) result))) > JUR> (reverse result))) > > I think it is well-known idiom. When you know about things like that, > chances that you'll introduce bug are fairly low. Change yer frickin name. This behavior is utterly non-obvious and someone who has written more Lisp in a week (me) than you'll write in your life trips up on this massive exception to the principle of least surprise all the time. All I would say is that it is not a reason to hate loop. I'd say it is a reason to /fix/ loop, but I have not thought thru the consequences. > > By the way, this kind of thing also bugs JavaScript developers,... I'm sorry, I could have sworn you just defended Lisp by saying it was no different than a steaming turd of a language*. I must be hallucinating, or you need to recalibrate your reasoning engine. > but even > more -- their "var" construct does not always introduce new bindings, > they can only reliably create new bindings via function parameters. God, how clueless can you get? You know the language sucks and you make it a point of defense for God's language? This newsgroup has fallen into the hands of a bunch of twits, hasn't it? HK * which I love because the interweb supports it and it has lambda, but still... kt
From: RG on 23 Apr 2010 21:09 In article <4bd236dc$0$5002$607ed4bc(a)cv.net>, His kennyness <kentilton(a)gmail.com> wrote: > Change yer frickin name. .... > This newsgroup has fallen into the hands of a bunch of twits, hasn't it? Too... much... irony... intercranial... pressure... building... head... will... explode... AAAUUUGGHHH!!!
From: Johan Ur Riise on 24 Apr 2010 03:34 Tamas K Papp <tkpapp(a)gmail.com> writes: > On Fri, 23 Apr 2010 03:42:56 +0200, Johan Ur Riise wrote: > >> Another reason to hate loop: >> >> (defun closures-from-loop (list) >> (loop for el in list collect (lambda () (format t "~s~%" el)))) >> >> (loop for lambda in (closures-from-loop (list 1 2 3 'a 'b 'c)) >> do (funcall lambda)) >> >> prints, since heavy setq-ing is going on behind the scene curtain: >> >> C >> C >> C >> C >> C >> C >> NIL >> >> >> >> (defun closures-from-mapcar (list) >> (mapcar (lambda (el) (lambda () (format t "~s~%" el))) list)) >> >> (mapcar #'funcall (closures-from-mapcar (list 1 2 3 'a 'b 'c))) >> >> prints: >> >> 1 >> 2 >> 3 >> A >> B >> C >> (NIL NIL NIL NIL NIL NIL) >> >> >> Of course, when you find the bug you can also say: >> >> (defun closures-from-loop (list) >> (let (result) >> (loop for el in list do >> (let ((el el)) >> (push (lambda () (format t "~s~%" el)) result))) >> (reverse result))) > > There is no bug, just a misunderstanding on your part. Oh, someone is irritable today. I had a bug in my code, which sometimes happens in the best families. > > Unlike Scheme, CL iteration constructs are not required to have a > different variable for each iteration of the loop body. There have > been many discussions on this topic, see eg > http://coding.derkeiler.com/Archive/Lisp/comp.lang.lisp/2008-10/msg01003.html > > Just use > > (defun closures-from-loop (list) > (loop for el in list collect > (let ((el el)) > (lambda () (format t "~s~%" el))))) That fixes my bug
From: Captain Obvious on 24 Apr 2010 06:45 Hk> Change yer frickin name. This behavior is utterly non-obvious I'm not saying it is. But I think people who have considerable lisp programming experience should be aware of it. Hk> and someone who has written more Lisp in a week (me) than you'll write Hk> in your life Uh-oh, this week I've pushed 64 KiB, 1600 lines long patch to the project I'm working on. (Ok, most of it is moving things around, but still...) I wonder why do you assume I'm writing less code than you? Hk> All I would say is that it is not a reason to hate loop. I'd say it is Hk> a reason to /fix/ loop, but I have not thought thru the consequences. Um, maybe people who wrote CL standard did think about the consequences and were not pleased by them? Hk> I'm sorry, I could have sworn you just defended Lisp by saying it was Hk> no different than a steaming turd of a language*. No, I'm just stating the fact I consider interesting.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: optimize, inline, oh my (questions) Next: ITA may be sold |