[Chicken-users] Printing procedures returned from call/cc
Hello, I was wondering why this happens in Chicken (recent checkout from git): (let ((lst (call/cc (lambda (x) (print 'something) (call/cc (lambda (y) (list x y))) (print lst) (print (eq? (car lst) (cadr lst))) (print (eqv? (car lst) (cadr lst))) == (#procedure (f_10734 . results1838) #procedure (f_10734 . results1838)) #f #f The procedures returned are different continuations (and of course they are certainly not eq? or eqv?). So I was wondering, then, why print (and write, etc) show the same names for them. I mean, they were printed from the same list, so in the same lexical context, and they are different... It's a bit confusing that they look the same when printed -- they wouldn't look the same if their names were something generic like #continuation, but they actually have names that look like something generated by gensym. I'm probably missing something, but can't see exactly what. Thanks! J. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing procedures returned from call/cc
On Tue, 31 Jul 2012, Jeronimo Pellegrini wrote: [...] I was wondering why this happens in Chicken (recent checkout from git): (let ((lst (call/cc (lambda (x) (print 'something) (call/cc (lambda (y) (list x y))) (print lst) (print (eq? (car lst) (cadr lst))) (print (eqv? (car lst) (cadr lst))) == (#procedure (f_10734 . results1838) #procedure (f_10734 . results1838)) #f #f The procedures returned are different continuations (and of course they are certainly not eq? or eqv?). [...] Hello, this is really strange! Since the second lambda expression is in tail position with respect to the first, the two continuations x and y are actually equivalent, so at first I was less surprised by their printed representation than by the results of the equality predicates. But then I tried to wrap some other function call around the inner invocation of call-with-current-continuation -- and the two continuation procedures still had the same printed representation. I guess one just cannot rely on intuition in this case ;-) Ciao, Thomas -- When C++ is your hammer, every problem looks like your thumb. smime.p7s Description: S/MIME Cryptographic Signature ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing procedures returned from call/cc
On Tue, Jul 31, 2012 at 03:24:16PM +0200, Thomas Chust wrote: On Tue, 31 Jul 2012, Jeronimo Pellegrini wrote: I was wondering why this happens in Chicken (recent checkout from git): (let ((lst (call/cc (lambda (x) (print 'something) (call/cc (lambda (y) (list x y))) (print lst) (print (eq? (car lst) (cadr lst))) (print (eqv? (car lst) (cadr lst))) this is really strange! Since the second lambda expression is in tail position with respect to the first, the two continuations x and y are actually equivalent, so at first I was less surprised by their printed representation than by the results of the equality predicates. Same here. I think what we're seeing here is the same procedure but different closure objects (one has access to 'x', the other to 'y'). Only the procedure name is printed. Cheers, Peter -- http://sjamaan.ath.cx -- The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing procedures returned from call/cc
From: Jeronimo Pellegrini j...@aleph0.info Subject: [Chicken-users] Printing procedures returned from call/cc Date: Tue, 31 Jul 2012 09:59:44 -0300 Hello, I was wondering why this happens in Chicken (recent checkout from git): (let ((lst (call/cc (lambda (x) (print 'something) (call/cc (lambda (y) (list x y))) (print lst) (print (eq? (car lst) (cadr lst))) (print (eqv? (car lst) (cadr lst))) == (#procedure (f_10734 . results1838) #procedure (f_10734 . results1838)) #f #f The procedures returned are different continuations (and of course they are certainly not eq? or eqv?). So I was wondering, then, why print (and write, etc) show the same names for them. I mean, they were printed from the same list, so in the same lexical context, and they are different... It's a bit confusing that they look the same when printed -- they wouldn't look the same if their names were something generic like #continuation, but they actually have names that look like something generated by gensym. I'm probably missing something, but can't see exactly what. These procedures are internally generated and represent different closure records but for the same piece of code. The printer for closures will show something that relates to the code, not the allocation or identity. The procedure-id shown here is admittedly useless, though. Attached a patch that at least hints at what sort of procedure is shown. If you find this in any way useful, I can add it to the git repo. cheers, felix diff --git a/library.scm b/library.scm index 67f859f..b1c77f7 100644 --- a/library.scm +++ b/library.scm @@ -1641,11 +1641,11 @@ EOF (let ((winds ##sys#dynamic-winds)) (##sys#call-with-current-continuation (lambda (cont) - (proc - (lambda results - (unless (eq? ##sys#dynamic-winds winds) - (##sys#dynamic-unwind winds (fx- (length ##sys#dynamic-winds) (length winds))) ) - (apply cont results) ) ) ) ) ) ) + (define (call/cc-wrapper . results) + (unless (eq? ##sys#dynamic-winds winds) + (##sys#dynamic-unwind winds (fx- (length ##sys#dynamic-winds) (length winds))) ) + (apply cont results) ) + (proc call/cc-wrapper) (define call/cc call-with-current-continuation) ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing procedures returned from call/cc
On Tue, Jul 31, 2012 at 11:09:30PM +0200, Felix wrote: From: Jeronimo Pellegrini j...@aleph0.info Subject: [Chicken-users] Printing procedures returned from call/cc Date: Tue, 31 Jul 2012 09:59:44 -0300 Hello, I was wondering why this happens in Chicken (recent checkout from git): (let ((lst (call/cc (lambda (x) (print 'something) (call/cc (lambda (y) (list x y))) (print lst) (print (eq? (car lst) (cadr lst))) (print (eqv? (car lst) (cadr lst))) == (#procedure (f_10734 . results1838) #procedure (f_10734 . results1838)) #f #f The procedures returned are different continuations (and of course they are certainly not eq? or eqv?). So I was wondering, then, why print (and write, etc) show the same names for them. I mean, they were printed from the same list, so in the same lexical context, and they are different... It's a bit confusing that they look the same when printed -- they wouldn't look the same if their names were something generic like #continuation, but they actually have names that look like something generated by gensym. I'm probably missing something, but can't see exactly what. These procedures are internally generated and represent different closure records but for the same piece of code. The printer for closures will show something that relates to the code, not the allocation or identity. The procedure-id shown here is admittedly useless, though. OK, I see! Attached a patch that at least hints at what sort of procedure is shown. If you find this in any way useful, I can add it to the git repo. Well, the output certainly more informative with the patch than it was before! Thank you! J. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users