Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.scheme

Reply
 
Thread Tools Display Modes
  #16 (permalink)  
Old 10-22-2008, 12:41 PM
Jussi Piitulainen
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

Abdulaziz Ghuloum writes:
> Jussi Piitulainen wrote:
>> I think Abdulaziz meant them to be the same, but when I tried to
>> use them for something, I noticed the difference.

>
> Obviously, I completely messed this up. Sorry. Mostly, I was


Ok, thanks. No problem.

> But now I'm confused for why this needs call/cc at all. Why would
> one not just do:
>
> (define (generate-one-element-at-a-time ls)
> (lambda ()
> (if (null? ls)
> 'last-element
> (let ([a (car ls)])
> (set! ls (cdr ls))
> a))))


So it falls flat. But perhaps the for-each call inside the original
generate-one-element-at-a-time was struggling to get out, in the way
that becomes so much more apparent in Michele Simionato's interesting
post. It did what I wanted, at least.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #17 (permalink)  
Old 10-24-2008, 06:45 PM
Grant Rettke
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 21, 4:32*am, leppie <xacc....@gmail.com> wrote:
> PS: Continuations confuse the crap out of me. For a beginner I would
> not worry about it too much, there are much nicer things to learn


Leppie, you implemented a R6RS interpreter and still you say this, is
there hope for the rest of us?!
Reply With Quote
  #18 (permalink)  
Old 10-24-2008, 11:12 PM
Aaron W. Hsu
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

Grant Rettke <grettke@gmail.com> writes:

>On Oct 21, 4:32=A0am, leppie <xacc....@gmail.com> wrote:
>> PS: Continuations confuse the crap out of me. For a beginner I would
>> not worry about it too much, there are much nicer things to learn


>Leppie, you implemented a R6RS interpreter and still you say this, is
>there hope for the rest of us?!


Implementing continuations is probably much harder than using them. I
know that I am able to use continuations fairly easily if I take a little
time to think about the problem.

Aaron Hsu

--
+++++++++++++++ ((lambda (x) (x x)) (lambda (x) (x x))) +++++++++++++++
Email: <arcfide@sacrideo.us> | WWW: <http://www.sacrideo.us>
Scheme Programming is subtle; subtlety can be hard.
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++
Reply With Quote
  #19 (permalink)  
Old 10-26-2008, 09:23 AM
jos koot
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 21, 8:53*am, the.brown.dragon.b...@gmail.com wrote:
> Hello,
>
> I have just started learning scheme using and got pretty confused when
> I reached call-with-current-continuation.
>
> After reading up on Wikipedia (http://en.wikipedia.org/wiki/Call-with-
> current-continuation) I think I've got some idea of how what call/cc
> is. But I'm still a bit confused by the example given:
>
> * * *1 *;;[LISTOF X] -> ( -> X u 'you-fell-off-the-end)
> * * *2 *(define (generate-one-element-at-a-time lst)
> * * *3 * *(define (generator)
> * * *4 * * *(call/cc control-state))
> * * *5
> * * *6 * *(define (control-state return)
> * * *7 * * *(for-each
> * * *8 * * * (lambda (element)
> * * *9 * * * * (set! return
> * * 10 * * * * * * * (call/cc
> * * 11 * * * * * * * *(lambda (resume-here)
> * * 12 * * * * * * * * *(set! control-state resume-here)
> * * 13 * * * * * * * * *(return element)))))
> * * 14 * * * lst)
> * * 15 * * *(return 'you-fell-off-the-end))
> * * 16
> * * 17 * *generator)
>
> Basically, what's confusing me is line 9 - why is "return" getting
> set! at this point? And how can it be? Won't the continuation jump out
> of the current context so it no longer continues?
>
> Help?
>
> BD

18 (define x (generate-one-element-at-a-time '(1 2 3)))
19 (x)

The set! first evaluates the call/cc call at line 10, and stores the
value only after call/cc has returned. But call/cc does not return
yet.
In line 13 it returns an element to the continuation of the call to x
in line 19. So line 19 produces element 1.
However, in line 12 variable control-state is updated such as to
contain a continuation that finishes the assignment of line 9.

20 (x)

So now the assignment of line 9 is completed. The value is that of
(return element) which is the continuation of line 20 as passed to
control-state by procedure generator.
After the assignment of line 9 is completed, for-each does the next
cycle while return points to the continuation of line 20.

You may want to have a look at: http://schemecookbook.org/Cookbook/CoRoutines

Jos
Reply With Quote
  #20 (permalink)  
Old 10-26-2008, 04:13 PM
Jens Axel Soegaard
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

Grant Rettke skrev:
> On Oct 21, 4:32 am, leppie <xacc....@gmail.com> wrote:
>> PS: Continuations confuse the crap out of me. For a beginner I would
>> not worry about it too much, there are much nicer things to learn

>
> Leppie, you implemented a R6RS interpreter and still you say this, is
> there hope for the rest of us?!


I'd say yes - they are easier to implement than understand.

--
Jens Axel Søgaard
Reply With Quote
  #21 (permalink)  
Old 10-28-2008, 09:03 AM
leppie
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 26, 7:13*pm, Jens Axel Soegaard
<findrealaddresswithgoo...@soegaard.net> wrote:
> Grant Rettke skrev:
>
> > On Oct 21, 4:32 am, leppie <xacc....@gmail.com> wrote:
> >> PS: Continuations confuse the crap out of me. For a beginner I would
> >> not worry about it too much, there are much nicer things to learn

>
> > Leppie, you implemented a R6RS interpreter and still you say this, is
> > there hope for the rest of us?!

>
> I'd say yes - they are easier to implement than understand.
>


I am just now implementing them (full re-invokable continuations), but
both implementing and understanding is hard, but I have had some good
help from #scheme on freenode.

Hopefully within the next few weeks I will have something working

Stay tuned!

Reply With Quote
  #22 (permalink)  
Old 10-28-2008, 02:33 PM
leppie
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 26, 7:13*pm, Jens Axel Soegaard
<findrealaddresswithgoo...@soegaard.net> wrote:
> Grant Rettke skrev:
>
> > On Oct 21, 4:32 am, leppie <xacc....@gmail.com> wrote:
> >> PS: Continuations confuse the crap out of me. For a beginner I would
> >> not worry about it too much, there are much nicer things to learn

>
> > Leppie, you implemented a R6RS interpreter and still you say this, is
> > there hope for the rest of us?!

>
> I'd say yes - they are easier to implement than understand.
>


I am busy implementing them (full re-invokable continuations) for
IronScheme at the moment.

Hopefully I will have something working in a few weeks

Stay tuned

leppie

Reply With Quote
  #23 (permalink)  
Old 10-28-2008, 02:35 PM
leppie
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 24, 8:45*pm, Grant Rettke <gret...@gmail.com> wrote:
> On Oct 21, 4:32*am, leppie <xacc....@gmail.com> wrote:
>
> > PS: Continuations confuse the crap out of me. For a beginner I would
> > not worry about it too much, there are much nicer things to learn

>
> Leppie, you implemented a R6RS interpreter and still you say this, is
> there hope for the rest of us?!


Full continuations are coming soon to IronScheme

leppie

PS: this is a duplicate message as my replies do not seem to come
through...
Reply With Quote
  #24 (permalink)  
Old 10-29-2008, 02:45 AM
Grant Rettke
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 28, 10:33*am, leppie <xacc....@gmail.com> wrote:
> I am busy implementing them (full re-invokable continuations) for
> IronScheme at the moment.


Awesome!
Reply With Quote
  #25 (permalink)  
Old 10-29-2008, 05:26 AM
the.brown.dragon.blog@gmail.com
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 26, 3:23*pm, jos koot <jos.k...@telefonica.net> wrote:
> On Oct 21, 8:53*am, the.brown.dragon.b...@gmail.com wrote:
>
> > Hello,

>
> > I have just started learning scheme using and got pretty confused when
> > I reached call-with-current-continuation.

>
> > After reading up on Wikipedia (http://en.wikipedia.org/wiki/Call-with-
> > current-continuation) I think I've got some idea of how what call/cc
> > is. But I'm still a bit confused by the example given:

>
> > * * *1 *;;[LISTOF X] -> ( -> X u 'you-fell-off-the-end)
> > * * *2 *(define (generate-one-element-at-a-time lst)
> > * * *3 * *(define (generator)
> > * * *4 * * *(call/cc control-state))
> > * * *5
> > * * *6 * *(define (control-state return)
> > * * *7 * * *(for-each
> > * * *8 * * * (lambda (element)
> > * * *9 * * * * (set! return
> > * * 10 * * * * * * * (call/cc
> > * * 11 * * * * * * * *(lambda (resume-here)
> > * * 12 * * * * * * * * *(set! control-state resume-here)
> > * * 13 * * * * * * * * *(return element)))))
> > * * 14 * * * lst)
> > * * 15 * * *(return 'you-fell-off-the-end))
> > * * 16
> > * * 17 * *generator)

>
> > Basically, what's confusing me is line 9 - why is "return" getting
> > set! at this point? And how can it be? Won't the continuation jump out
> > of the current context so it no longer continues?

>
> > Help?

>
> > BD

>
> * * * 18 (define x (generate-one-element-at-a-time '(1 2 3)))
> * * * 19 (x)
>
> The set! first evaluates the call/cc call at line 10, and stores the
> value only after call/cc has returned. But call/cc does not return
> yet.
> In line 13 it returns an element to the continuation of the call to x
> in line 19. So line 19 produces element 1.
> However, in line 12 variable control-state is updated such as to
> contain a continuation that finishes the assignment of line 9.
>
> * * *20 (x)
>
> So now the assignment of line 9 is completed. The value is that of
> (return element) which is the continuation of line 20 as passed to
> control-state by procedure generator.
> After the assignment of line 9 is completed, for-each does the next
> cycle while return points to the continuation of line 20.
>
> You may want to have a look at:http://schemecookbook.org/Cookbook/CoRoutines
>
> Jos


Thanks Jos. I re-read your message 3 times and I think I get it.

So if I understand correctly - a continuation (cont value) returns the
next "continuation context". In the example, this is saved in the
"return" variable and used in the next iteration.

cheers,
BD
Reply With Quote
  #26 (permalink)  
Old 10-29-2008, 09:34 AM
jos koot
Guest
 
Posts: n/a
Default Re: Call-with-current-continuation

On Oct 29, 7:26*am, the.brown.dragon.b...@gmail.com wrote:
> On Oct 26, 3:23*pm, jos koot <jos.k...@telefonica.net> wrote:
>
>
>
> > On Oct 21, 8:53*am, the.brown.dragon.b...@gmail.com wrote:

>
> > > Hello,

>
> > > I have just started learning scheme using and got pretty confused when
> > > I reached call-with-current-continuation.

>
> > > After reading up on Wikipedia (http://en.wikipedia.org/wiki/Call-with-
> > > current-continuation) I think I've got some idea of how what call/cc
> > > is. But I'm still a bit confused by the example given:

>
> > > * * *1 *;;[LISTOF X] -> ( -> X u 'you-fell-off-the-end)
> > > * * *2 *(define (generate-one-element-at-a-time lst)
> > > * * *3 * *(define (generator)
> > > * * *4 * * *(call/cc control-state))
> > > * * *5
> > > * * *6 * *(define (control-state return)
> > > * * *7 * * *(for-each
> > > * * *8 * * * (lambda (element)
> > > * * *9 * * * * (set! return
> > > * * 10 * * * * * * * (call/cc
> > > * * 11 * * * * * * * *(lambda (resume-here)
> > > * * 12 * * * * * * * * *(set! control-state resume-here)
> > > * * 13 * * * * * * * * *(return element)))))
> > > * * 14 * * * lst)
> > > * * 15 * * *(return 'you-fell-off-the-end))
> > > * * 16
> > > * * 17 * *generator)

>
> > > Basically, what's confusing me is line 9 - why is "return" getting
> > > set! at this point? And how can it be? Won't the continuation jump out
> > > of the current context so it no longer continues?

>
> > > Help?

>
> > > BD

>
> > * * * 18 (define x (generate-one-element-at-a-time '(1 2 3)))
> > * * * 19 (x)

>
> > The set! first evaluates the call/cc call at line 10, and stores the
> > value only after call/cc has returned. But call/cc does not return
> > yet.
> > In line 13 it returns an element to the continuation of the call to x
> > in line 19. So line 19 produces element 1.
> > However, in line 12 variable control-state is updated such as to
> > contain a continuation that finishes the assignment of line 9.

>
> > * * *20 (x)

>
> > So now the assignment of line 9 is completed. The value is that of
> > (return element) which is the continuation of line 20 as passed to
> > control-state by procedure generator.
> > After the assignment of line 9 is completed, for-each does the next
> > cycle while return points to the continuation of line 20.

>
> > You may want to have a look at:http://schemecookbook.org/Cookbook/CoRoutines

>
> > Jos

>
> Thanks Jos. I re-read your message 3 times and I think I get it.
>
> So if I understand correctly - a continuation (cont value) returns the
> next "continuation context". In the example, this is saved in the
> "return" variable and used in the next iteration.
>
> cheers,
> BD


Correct, Jos
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: OT: Chance to Make SAS-L History: Did You Know That... Craig Stroup Newsgroup comp.soft-sys.sas 0 08-14-2007 08:05 PM
proc report sas to excel: break not working Bob Sayre Newsgroup comp.soft-sys.sas 1 06-29-2006 04:50 PM
Re: Read/Write Microsoft Word document William W. Viergever Newsgroup comp.soft-sys.sas 0 05-31-2006 08:46 PM
Re: Read/Write Microsoft Word document Joe Whitehurst Newsgroup comp.soft-sys.sas 0 05-31-2006 08:35 PM
Proc report: How to break only on certain values of a variable? Bob Sayre Newsgroup comp.soft-sys.sas 0 10-07-2005 02:15 PM



All times are GMT. The time now is 06:23 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.