manipulating continuations
Hello list I'm new to scheme and guile - started using them a few days ago for a project. So here we go: this is the bit of code that causing me troubles: (define (foo) (call/cc (lambda (return) (display "first part") (newline) (call/cc (lambda (cont) (return cont))) (display "second part") (newline Basically, I use call/cc to stop the procedure foo after printing "first part" and return a continuation. Then, if I call this continuation it prints "second part" and ends. To test this code, I did this: guile> (define c (foo)) first part guile> (c) second part yay, it works. But now, what if I want to run the continuation directly, rather than storing it and calling it later ? This is what I get: guile> ((foo)) first part second part Backtrace: In current input: 15: 0* [#] :15:1: In expression ((foo)): :15:1: Wrong type to apply: # ABORT: (misc-error) There. I don't understand why I get this error message. Cheers Tom
Re: Memory leak with threads + guile 1.8.7 ?
Hi Cedric, You posted a mail to the list some months ago: On Wed 15 Sep 2010 15:47, Cedric Cellier writes: > I'm using guile in an C program that spawn a lot of short lived > threads, each of which passing in guile mode (guile 1.8.7), and I'm > facing a memory leak even when the threads does nothing (ie. the > C function called by scm_with_guile consists only of a return NULL. > After some time, if I call a gc-stats I have many many segments of > 21Mb allocated, although gc-live-object-stats reports that almost > nothing is alive (acording to expectations). > > I am under the impression that some of these segments, created by a > now defunct thread, can not be reused by others. > > So I made a small program that continuously creates thread and run > a NOP scm_with_guile in it, and then join it (so that thre thread local > storage itself is not leaked). > > With the useless scm_with_guile call, this programm leaks memory > very quickly. Comment out the scm_with_guile call and there is no more > leak. > > What do you think ? It's a bug, but with interesting implications in 1.9. I have filed bug #32436 about this. Thanks for the test case, Andy -- http://wingolog.org/
Re: manipulating continuations
Hi Thomas, On Sat 12 Feb 2011 15:10, Thomas Girod writes: > (define (foo) > (call/cc >(lambda (return) > (display "first part") > (newline) > (call/cc > (lambda (cont) > (return cont))) > (display "second part") > (newline > > guile> (define c (foo)) > first part > guile> (c) > second part > > yay, it works. But now, what if I want to run the continuation directly, > rather than storing it and calling it later ? This is what I get: > > guile> ((foo)) > first part > second part > > Backtrace: > In current input: > 15: 0* [#] In this expression, `foo' has returned twice. The first time it returned a continuation, which was applied. The second time it returned whatever `newline' returned: the unspecified value. Applying the unspecified value failed. If you use Guile 1.9/2.0, partial continuations behave more in the way you were thinking of: (use-modules (ice-9 control)) (define (foo) (% (begin (display "first part\n") (abort) (display "second part\n")) (lambda (cont) ;; abort jumps back here, to the handler. return the partial ;; continuation. cont))) scheme@(guile-user)> (foo) first part $1 = # scheme@(guile-user)> ($1) second part scheme@(guile-user)> ((foo)) first part second part scheme@(guile-user)> Have fun with Guile, Andy -- http://wingolog.org/
Re: manipulating continuations
> From: Andy Wingo > Cc: guile-user@gnu.org > > Hi Thomas, > > In this expression, `foo' has returned twice. The first time it > returned a continuation, which was applied. The second time it returned > whatever `newline' returned: the unspecified value. Applying the > unspecified value failed. This first part is good. It explains that you have evaluated ((newline)) on the second call. > If you use Guile 1.9/2.0, partial continuations behave more in the way > you were thinking of: > > (use-modules (ice-9 control)) > > (define (foo) > (% (begin >(display "first part\n") >(abort) >(display "second part\n")) > (lambda (cont) >;; abort jumps back here, to the handler. return the partial >;; continuation. >cont))) This is not Scheme and should be ignored by anyone who is new to Scheme. I have been using Scheme, off and on, for decades but I can't read this program. What is (% ...)? What is a "partial continuation"? Has Guile gone off into left field, never to return? Can we continue from R5RS or R6RS? -- Keith
Re: manipulating continuations
On Sat 12 Feb 2011 17:40, Keith Wright writes: > What is (% ...)? What is a "partial continuation"? % sets up a prompt. http://www.gnu.org/software/guile/docs/master/guile.html/Prompts.html http://en.wikipedia.org/wiki/Delimited_continuation http://www.ccs.neu.edu/scheme/pubs/pldi93-sitaram.pdf > Has Guile gone off into left field, never to return? Hardly, these control operators are nearly a quarter of a century old... > Can we continue from R5RS or R6RS? R5RS and R6RS's continuations are not generally useful for making abstractions that compose well together. I would not recommend them to anyone. Regards, Andy -- http://wingolog.org/
manipulating continuations
Hello list First of all, I'm new to scheme and guile - started using them a few days ago for a project. So here we go: this is the bit of code that causing me troubles: (define (foo) (call/cc (lambda (return) (display "first part") (newline) (call/cc (lambda (cont) (return cont))) (display "second part") (newline Basically, I use call/cc to stop the procedure foo after printing "first part" and return a continuation. Then, if I call this continuation it prints "second part" and ends. To test this code, I did this: guile> (define c (foo)) first part guile> (c) second part yay, it works. But now, what if I want to run the continuation directly, rather than storing it and calling it later ? This is what I get: guile> ((foo)) first part second part Backtrace: In current input: 15: 0* [#] :15:1: In expression ((foo)): :15:1: Wrong type to apply: # ABORT: (misc-error) There. I don't understand why I get this error message. Cheers Tom
Re: manipulating continuations
() Andy Wingo () Sat, 12 Feb 2011 18:16:20 +0100 R5RS and R6RS's continuations are not generally useful for making abstractions that compose well together. I would not recommend them to anyone. Are you saying Guile 2.0 breaks code that uses these traditional continuations (successfully, in previous Guile versions)? I think the OP example should be in NEWS, if so, to avoid a surprise.
Re: manipulating continuations
On Sat 12 Feb 2011 21:56, Thien-Thi Nguyen writes: > () Andy Wingo > () Sat, 12 Feb 2011 18:16:20 +0100 > >R5RS and R6RS's continuations are not generally useful for making >abstractions that compose well together. I would not recommend them to >anyone. > > Are you saying Guile 2.0 breaks code that uses these traditional > continuations (successfully, in previous Guile versions)? No, I am not saying that. Tom's code works the same on Guile 1.8 and on 1.9/2.0. Regards, Andy -- http://wingolog.org/
Guile-WWW 2.30 available
release notes: Thanks to Mike Gran, Guile-WWW 2.30 should be usable on Guile 1.9.x. thi README excerpt: This is the Guile WWW library, a set of Guile Scheme modules to facilitate HTTP, URL and CGI programming. NEWS excerpt: - 2.30 | 2011-02-12 - portability fix for Guile 1.9.14 (among others, probably) home page: http://www.nongnu.org/guile-www/