chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Printing procedures returned from call/cc


From: Felix
Subject: Re: [Chicken-users] Printing procedures returned from call/cc
Date: Tue, 31 Jul 2012 23:09:30 +0200 (CEST)

From: "Jeronimo Pellegrini" <address@hidden>
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)
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]