|
|||
|
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. |
|
|
||||
|
||||
|
|
|
|||
|
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?! ![]() |
|
|||
|
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. ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++ |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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! |
|
|||
|
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 |
|
|||
|
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... |
|
|||
|
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 |
|
|||
|
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 |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |