unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* manipulating continuations
@ 2011-02-12 14:10 Thomas Girod
  2011-02-12 15:43 ` Andy Wingo
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Girod @ 2011-02-12 14:10 UTC (permalink / raw)
  To: guile-user

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* [#<unspecified>]

<unnamed port>:15:1: In expression ((foo)):
<unnamed port>:15:1: Wrong type to apply: #<unspecified>
ABORT: (misc-error)

There. I don't understand why I get this error message.

Cheers

Tom




^ permalink raw reply	[flat|nested] 8+ messages in thread
* manipulating continuations
@ 2011-02-12  8:35 Tomtom
  0 siblings, 0 replies; 8+ messages in thread
From: Tomtom @ 2011-02-12  8:35 UTC (permalink / raw)
  To: guile-user

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* [#<unspecified>]

<unnamed port>:15:1: In expression ((foo)):
<unnamed port>:15:1: Wrong type to apply: #<unspecified>
ABORT: (misc-error)

There. I don't understand why I get this error message.

Cheers

Tom



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-02-17 11:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-12 14:10 manipulating continuations Thomas Girod
2011-02-12 15:43 ` Andy Wingo
2011-02-12 16:40   ` Keith Wright
2011-02-12 17:16     ` Andy Wingo
2011-02-12 20:56       ` Thien-Thi Nguyen
2011-02-12 21:33         ` Andy Wingo
     [not found]   ` <1297887196-sup-8146@cresylol.hd.free.fr>
2011-02-17 11:08     ` Andy Wingo
  -- strict thread matches above, loose matches on Subject: below --
2011-02-12  8:35 Tomtom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).