Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread Joao Pedro Abreu De Souza
Shu-hung, very cool information.

Em qui, 25 de out de 2018 às 16:57, Shu-Hung You <
shu-hung@eecs.northwestern.edu> escreveu:

> FWIW here's the part in the document that could be helpful:
>
> 1. The section in the Guide that talks about the concept of prompts
> and their usage in the continuation in Racket:
> https://docs.racket-lang.org/guide/prompt.html
> The prompt is kind of like a mark on the continuations that lets the
> control operators find the portion of continuations they want to
> manipulate.
>
> 2. About your original question (why (print 'hello) isn't captured),
> there are two things happening here:
>
> 2a. Begin is a special syntactic form. It does not just mean
> evaluating a sequence of expressions in order. When used at certain
> contexts such as top-level (module-level) context, begin splices the
> forms it contains to the surrounding context. The last paragraph in
> the guide ( https://docs.racket-lang.org/guide/begin.html ) briefly
> talked about it. The reference (
>
> https://docs.racket-lang.org/reference/begin.html#(form._((quote._~23~25kernel)._begin))
> ) made it explicit that the forms
> (begin expr expr ...)   and
> (begin form form ...)
> are different.
>
> As an example, in the following module, with or without begin makes no
> difference at all. The subforms are spliced to the module-level
> context:
>
> #lang racket
>
> (define (even??? x) (odd??? (- x 1)))
>
> ;; At module-level context, this begin works as if the
> ;; program were just written directly without begin:
> ;; (displayln ...)
> ;; (define (odd??? ...
> (begin
> (displayln "No difference")
> (define (odd??? x) (odd? x)))
>
> (odd??? 9)
> (even??? 8)
>
> This, combined with the following reason (2b) is why your code didn't
> work as expected.
>
> 2b. The evaluation of module-level expressions and definitions are
> implicitly wrapped in a prompt. That is, for a module
>
> #lang racket
>
> expr1
> (define def2 expr2)
> expr3
> expr4
> (define def5 expr5)
> ...
>
> the evaluation of each expr is implicitly wrapped by the default
> prompt as if it were evaluated using:
>
> procedure instantiate a module M:
> for each module-level expression/definition EXPR do:
>   with DEFAULT_PROMPT:
>   result = eval(EXPR)
>   ...
>
> The control operators (e.g. call/cc and abort) by default looks for
> the default prompt. This effectively delimits the control effect of
> each module-level expression and therefore the call/cc in your code
> will not capture the println portion.
>
> This behavior is described in the reference about how the body of a
> module is evaluated, starting from the paragraph ``A module body is
> executed only when the module is explicitly instantiated ...''
> https://docs.racket-lang.org/reference/module.html
>
> On Thu, Oct 25, 2018 at 2:00 PM  wrote:
> >
> >
> > About (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
> >
> > 1. "prompt" form does not exist in racket.
> > It is a procedure application or special form ?
> >
> > 2. assume this procedure or special form exists to construct a prompt.
> >
> > (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
> >
> > After the (lambda (k) ...) evaluated, value of k is (* 2 []), then I call
> > (k 0) ; < When does the control flow come back here?
> >
> > (k 0) ---jump to--> (* 2 []), and then?
> >
> > What happens after (*2 0) ? What is the continuation of (*2 0)?
> >
> >
> > On Friday, October 26, 2018 at 2:11:43 AM UTC+8, Joao Pedro Abreu De
> Souza wrote:
> >>
> >> well, let's go by parts :
> >>
> >> 1) call/cc in principle will capture the complete continuation of a
> expression, right? Delimited continuation will capture ... welll, delimited
> continuations. But delimited by what? By a prompt.
> >> In a delimited contninuation style(not really, but I dont want to mix
> functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda
> (k) (set! x k) 2)
> >>
> >> this will set x with (* 2 []), because delimited capture from prompt.
> call/cc in racket works in a similar way, if around the most extern s-exp
> exists a prompt.
> >>
> >> 2) well, when I dont know exactly why begin dont work and lambda do,
> but I have a clue : if you do (syntax->datum (expand '(begin (print "hi")
> (print "hello" in drracket, you will receive
> >> '(begin (#%app print '"hi") (#%app print '"hello"))
> >>
> >> and if you do (syntax->datum (expand '((lambda () (print "hi") (print
> "hello") you will receive '(#%app (lambda () (#%app print '"hi") (#%app
> print '"hello")))
> >>
> >> Probably, as begin dont is involved in a #%app, he dont is invoked with
> a prompt. But this is just speculation of my part.
> >>
> >> Em qui, 25 de out de 2018 às 14:13,  escreveu:
> >>>
> >>> Thank Joao
> >>>
> >>> I change my code like this:
> >>>
> >>> #lang racket
> >>>
> >>>
> >>> ((lambda ()
> >>>
> >>>   (define saved-k #f)
> >>>
> >>>   (println (+ 1 (call/cc
> >>> (lambda (k) ; k is the captured 

Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread Shu-Hung You
FWIW here's the part in the document that could be helpful:

1. The section in the Guide that talks about the concept of prompts
and their usage in the continuation in Racket:
https://docs.racket-lang.org/guide/prompt.html
The prompt is kind of like a mark on the continuations that lets the
control operators find the portion of continuations they want to
manipulate.

2. About your original question (why (print 'hello) isn't captured),
there are two things happening here:

2a. Begin is a special syntactic form. It does not just mean
evaluating a sequence of expressions in order. When used at certain
contexts such as top-level (module-level) context, begin splices the
forms it contains to the surrounding context. The last paragraph in
the guide ( https://docs.racket-lang.org/guide/begin.html ) briefly
talked about it. The reference (
https://docs.racket-lang.org/reference/begin.html#(form._((quote._~23~25kernel)._begin))
) made it explicit that the forms
(begin expr expr ...)   and
(begin form form ...)
are different.

As an example, in the following module, with or without begin makes no
difference at all. The subforms are spliced to the module-level
context:

#lang racket

(define (even??? x) (odd??? (- x 1)))

;; At module-level context, this begin works as if the
;; program were just written directly without begin:
;; (displayln ...)
;; (define (odd??? ...
(begin
(displayln "No difference")
(define (odd??? x) (odd? x)))

(odd??? 9)
(even??? 8)

This, combined with the following reason (2b) is why your code didn't
work as expected.

2b. The evaluation of module-level expressions and definitions are
implicitly wrapped in a prompt. That is, for a module

#lang racket

expr1
(define def2 expr2)
expr3
expr4
(define def5 expr5)
...

the evaluation of each expr is implicitly wrapped by the default
prompt as if it were evaluated using:

procedure instantiate a module M:
for each module-level expression/definition EXPR do:
  with DEFAULT_PROMPT:
  result = eval(EXPR)
  ...

The control operators (e.g. call/cc and abort) by default looks for
the default prompt. This effectively delimits the control effect of
each module-level expression and therefore the call/cc in your code
will not capture the println portion.

This behavior is described in the reference about how the body of a
module is evaluated, starting from the paragraph ``A module body is
executed only when the module is explicitly instantiated ...''
https://docs.racket-lang.org/reference/module.html

On Thu, Oct 25, 2018 at 2:00 PM  wrote:
>
>
> About (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
>
> 1. "prompt" form does not exist in racket.
> It is a procedure application or special form ?
>
> 2. assume this procedure or special form exists to construct a prompt.
>
> (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
>
> After the (lambda (k) ...) evaluated, value of k is (* 2 []), then I call
> (k 0) ; < When does the control flow come back here?
>
> (k 0) ---jump to--> (* 2 []), and then?
>
> What happens after (*2 0) ? What is the continuation of (*2 0)?
>
>
> On Friday, October 26, 2018 at 2:11:43 AM UTC+8, Joao Pedro Abreu De Souza 
> wrote:
>>
>> well, let's go by parts :
>>
>> 1) call/cc in principle will capture the complete continuation of a 
>> expression, right? Delimited continuation will capture ... welll, delimited 
>> continuations. But delimited by what? By a prompt.
>> In a delimited contninuation style(not really, but I dont want to mix 
>> functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda (k) 
>> (set! x k) 2)
>>
>> this will set x with (* 2 []), because delimited capture from prompt.  
>> call/cc in racket works in a similar way, if around the most extern s-exp 
>> exists a prompt.
>>
>> 2) well, when I dont know exactly why begin dont work and lambda do, but I 
>> have a clue : if you do (syntax->datum (expand '(begin (print "hi") (print 
>> "hello" in drracket, you will receive
>> '(begin (#%app print '"hi") (#%app print '"hello"))
>>
>> and if you do (syntax->datum (expand '((lambda () (print "hi") (print 
>> "hello") you will receive '(#%app (lambda () (#%app print '"hi") (#%app 
>> print '"hello")))
>>
>> Probably, as begin dont is involved in a #%app, he dont is invoked with a 
>> prompt. But this is just speculation of my part.
>>
>> Em qui, 25 de out de 2018 às 14:13,  escreveu:
>>>
>>> Thank Joao
>>>
>>> I change my code like this:
>>>
>>> #lang racket
>>>
>>>
>>> ((lambda ()
>>>
>>>   (define saved-k #f)
>>>
>>>   (println (+ 1 (call/cc
>>> (lambda (k) ; k is the captured continuation
>>>   (set! saved-k k)
>>>   0
>>>
>>>   (println 'hello)
>>>
>>>   (saved-k 100)
>>>
>>>
>>>   ))
>>>
>>> Now it works as I expected.
>>>
>>> But why?
>>>
>>> "begin" special form packages a sequence of expressions into a single 
>>> expression. After compiled, it should be continuation-passing style.
>>>
>>> "lambda" 

Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread serioadamo97

About (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)

1. "prompt" form does not exist in racket. 
It is a procedure application or special form ?

2. assume this procedure or special form exists to construct a prompt.

(+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)

After the (lambda (k) ...) evaluated, value of k is (* 2 []), then I call
(k 0) ; < When does the control flow come back here?

(k 0) ---jump to--> (* 2 []), and then?

What happens after (*2 0) ? What is the continuation of (*2 0)?


On Friday, October 26, 2018 at 2:11:43 AM UTC+8, Joao Pedro Abreu De Souza 
wrote:
>
> well, let's go by parts :
>
> 1) call/cc in principle will capture the complete continuation of a 
> expression, right? Delimited continuation will capture ... welll, delimited 
> continuations. But delimited by what? By a prompt.
> In a delimited contninuation style(not really, but I dont want to mix 
> functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda 
> (k) (set! x k) 2)
>
> this will set x with (* 2 []), because delimited capture from prompt.  
> call/cc in racket works in a similar way, if around the most extern s-exp 
> exists a prompt.
>
> 2) well, when I dont know exactly why begin dont work and lambda do, but I 
> have a clue : if you do (syntax->datum (expand '(begin (print "hi") (print 
> "hello" in drracket, you will receive
> '(begin (#%app print '"hi") (#%app print '"hello"))
>
> and if you do (syntax->datum (expand '((lambda () (print "hi") (print 
> "hello") you will receive '(#%app (lambda () (#%app print '"hi") (#%app 
> print '"hello")))
>
> Probably, as begin dont is involved in a #%app, he dont is invoked with a 
> prompt. But this is just speculation of my part.
>
> Em qui, 25 de out de 2018 às 14:13, > 
> escreveu:
>
>> Thank Joao
>>
>> I change my code like this:
>>
>> #lang racket
>>
>>
>> ((lambda ()
>>
>>   (define saved-k #f)
>>
>>   (println (+ 1 (call/cc
>> (lambda (k) ; k is the captured continuation
>>   (set! saved-k k)
>>   0
>>
>>   (println 'hello)
>>
>>   (saved-k 100)
>>
>>
>>   ))
>>
>> Now it works as I expected.
>>
>> But why?
>>
>> "begin" special form packages a sequence of expressions into a single 
>> expression. After compiled, it should be continuation-passing style.
>>
>> "lambda" special form also have a sequence of expressions in it.
>>
>> They are essentially the same, except the lambda can be applied.
>>
>> What is prompt you mentioned?
>>
>> I have not heard of this concept before.
>>
>> Can you tell me something about the prompt?
>>
>> Thanks.
>>
>> On Friday, October 26, 2018 at 12:40:37 AM UTC+8, Joao Pedro Abreu De 
>> Souza wrote:
>>>
>>> Well, call/cc is like (in racket) delimited continuation, and have a 
>>> implicit prompt around a s-exp, so, as begin is a macro, he don't create a 
>>> prompt. The continuation captured is (+ 1 []) in your example.
>>>
>>> If you change the begin to a let, this works, because let expand to a 
>>> application of a lambda, so create prompt as you expected
>>>
>>> Em quinta-feira, 25 de outubro de 2018,  escreveu:
>>>
 Dear all,

 I am learning call/cc in racket, so I wrote some experiment code:

 #lang racket

 (begin

   (define saved-k #f)

   (+ 1 (call/cc
 (lambda (k) ; k is the captured continuation
   (set! saved-k k)
   0)))

   (println 'hello)

   (saved-k 100)

   ;; why 'hello not print more than once??
  
   )

 The execution result of this codeis:

 1
 hello
 101


 It does not meet my expectation, my expectation is :


 1
 hello
 101
 hello
 101
 loop


 About continuation, for example:

 assume  exp1 is:
 (+ 1 (call/cc
 (lambda (k) ; k is the captured continuation
   (set! saved-k k)
   0)))

 exp2 is:
 (println 'hello)

 Whether exp2 is the continuation of exp1

 Are these two expressions equivalent?

 (begin
   (exp1)
   (exp2))


 (exp1 (lambda (v)
 (exp2 continuation-of-exp2)))


 So exp2 is exp1's continuation?

 It makes me confused.

 Excuse me, this question may be stupid, forgive my ignorance...

 Thanks.

 Br,
 serioadamo97

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to racket-users...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com .

Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread Joao Pedro Abreu De Souza
well, let's go by parts :

1) call/cc in principle will capture the complete continuation of a
expression, right? Delimited continuation will capture ... welll, delimited
continuations. But delimited by what? By a prompt.
In a delimited contninuation style(not really, but I dont want to mix
functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda
(k) (set! x k) 2)

this will set x with (* 2 []), because delimited capture from prompt.
call/cc in racket works in a similar way, if around the most extern s-exp
exists a prompt.

2) well, when I dont know exactly why begin dont work and lambda do, but I
have a clue : if you do (syntax->datum (expand '(begin (print "hi") (print
"hello" in drracket, you will receive
'(begin (#%app print '"hi") (#%app print '"hello"))

and if you do (syntax->datum (expand '((lambda () (print "hi") (print
"hello") you will receive '(#%app (lambda () (#%app print '"hi") (#%app
print '"hello")))

Probably, as begin dont is involved in a #%app, he dont is invoked with a
prompt. But this is just speculation of my part.

Em qui, 25 de out de 2018 às 14:13,  escreveu:

> Thank Joao
>
> I change my code like this:
>
> #lang racket
>
>
> ((lambda ()
>
>   (define saved-k #f)
>
>   (println (+ 1 (call/cc
> (lambda (k) ; k is the captured continuation
>   (set! saved-k k)
>   0
>
>   (println 'hello)
>
>   (saved-k 100)
>
>
>   ))
>
> Now it works as I expected.
>
> But why?
>
> "begin" special form packages a sequence of expressions into a single
> expression. After compiled, it should be continuation-passing style.
>
> "lambda" special form also have a sequence of expressions in it.
>
> They are essentially the same, except the lambda can be applied.
>
> What is prompt you mentioned?
>
> I have not heard of this concept before.
>
> Can you tell me something about the prompt?
>
> Thanks.
>
> On Friday, October 26, 2018 at 12:40:37 AM UTC+8, Joao Pedro Abreu De
> Souza wrote:
>>
>> Well, call/cc is like (in racket) delimited continuation, and have a
>> implicit prompt around a s-exp, so, as begin is a macro, he don't create a
>> prompt. The continuation captured is (+ 1 []) in your example.
>>
>> If you change the begin to a let, this works, because let expand to a
>> application of a lambda, so create prompt as you expected
>>
>> Em quinta-feira, 25 de outubro de 2018,  escreveu:
>>
>>> Dear all,
>>>
>>> I am learning call/cc in racket, so I wrote some experiment code:
>>>
>>> #lang racket
>>>
>>> (begin
>>>
>>>   (define saved-k #f)
>>>
>>>   (+ 1 (call/cc
>>> (lambda (k) ; k is the captured continuation
>>>   (set! saved-k k)
>>>   0)))
>>>
>>>   (println 'hello)
>>>
>>>   (saved-k 100)
>>>
>>>   ;; why 'hello not print more than once??
>>>
>>>   )
>>>
>>> The execution result of this codeis:
>>>
>>> 1
>>> hello
>>> 101
>>>
>>>
>>> It does not meet my expectation, my expectation is :
>>>
>>>
>>> 1
>>> hello
>>> 101
>>> hello
>>> 101
>>> loop
>>>
>>>
>>> About continuation, for example:
>>>
>>> assume  exp1 is:
>>> (+ 1 (call/cc
>>> (lambda (k) ; k is the captured continuation
>>>   (set! saved-k k)
>>>   0)))
>>>
>>> exp2 is:
>>> (println 'hello)
>>>
>>> Whether exp2 is the continuation of exp1
>>>
>>> Are these two expressions equivalent?
>>>
>>> (begin
>>>   (exp1)
>>>   (exp2))
>>>
>>>
>>> (exp1 (lambda (v)
>>> (exp2 continuation-of-exp2)))
>>>
>>>
>>> So exp2 is exp1's continuation?
>>>
>>> It makes me confused.
>>>
>>> Excuse me, this question may be stupid, forgive my ignorance...
>>>
>>> Thanks.
>>>
>>> Br,
>>> serioadamo97
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to racket-users...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread serioadamo97
Thank Joao

I change my code like this:

#lang racket


((lambda ()
   
  (define saved-k #f)

  (println (+ 1 (call/cc
(lambda (k) ; k is the captured continuation
  (set! saved-k k)
  0

  (println 'hello)

  (saved-k 100)


  ))

Now it works as I expected.

But why?

"begin" special form packages a sequence of expressions into a single 
expression. After compiled, it should be continuation-passing style.

"lambda" special form also have a sequence of expressions in it.

They are essentially the same, except the lambda can be applied.

What is prompt you mentioned?

I have not heard of this concept before.

Can you tell me something about the prompt?

Thanks.

On Friday, October 26, 2018 at 12:40:37 AM UTC+8, Joao Pedro Abreu De Souza 
wrote:
>
> Well, call/cc is like (in racket) delimited continuation, and have a 
> implicit prompt around a s-exp, so, as begin is a macro, he don't create a 
> prompt. The continuation captured is (+ 1 []) in your example.
>
> If you change the begin to a let, this works, because let expand to a 
> application of a lambda, so create prompt as you expected
>
> Em quinta-feira, 25 de outubro de 2018, > 
> escreveu:
>
>> Dear all,
>>
>> I am learning call/cc in racket, so I wrote some experiment code:
>>
>> #lang racket
>>
>> (begin
>>
>>   (define saved-k #f)
>>
>>   (+ 1 (call/cc
>> (lambda (k) ; k is the captured continuation
>>   (set! saved-k k)
>>   0)))
>>
>>   (println 'hello)
>>
>>   (saved-k 100)
>>
>>   ;; why 'hello not print more than once??
>>  
>>   )
>>
>> The execution result of this codeis:
>>
>> 1
>> hello
>> 101
>>
>>
>> It does not meet my expectation, my expectation is :
>>
>>
>> 1
>> hello
>> 101
>> hello
>> 101
>> loop
>>
>>
>> About continuation, for example:
>>
>> assume  exp1 is:
>> (+ 1 (call/cc
>> (lambda (k) ; k is the captured continuation
>>   (set! saved-k k)
>>   0)))
>>
>> exp2 is:
>> (println 'hello)
>>
>> Whether exp2 is the continuation of exp1
>>
>> Are these two expressions equivalent?
>>
>> (begin
>>   (exp1)
>>   (exp2))
>>
>>
>> (exp1 (lambda (v)
>> (exp2 continuation-of-exp2)))
>>
>>
>> So exp2 is exp1's continuation?
>>
>> It makes me confused.
>>
>> Excuse me, this question may be stupid, forgive my ignorance...
>>
>> Thanks.
>>
>> Br,
>> serioadamo97
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread Joao Pedro Abreu De Souza
Well, call/cc is like (in racket) delimited continuation, and have a
implicit prompt around a s-exp, so, as begin is a macro, he don't create a
prompt. The continuation captured is (+ 1 []) in your example.

If you change the begin to a let, this works, because let expand to a
application of a lambda, so create prompt as you expected

Em quinta-feira, 25 de outubro de 2018,  escreveu:

> Dear all,
>
> I am learning call/cc in racket, so I wrote some experiment code:
>
> #lang racket
>
> (begin
>
>   (define saved-k #f)
>
>   (+ 1 (call/cc
> (lambda (k) ; k is the captured continuation
>   (set! saved-k k)
>   0)))
>
>   (println 'hello)
>
>   (saved-k 100)
>
>   ;; why 'hello not print more than once??
>
>   )
>
> The execution result of this codeis:
>
> 1
> hello
> 101
>
>
> It does not meet my expectation, my expectation is :
>
>
> 1
> hello
> 101
> hello
> 101
> loop
>
>
> About continuation, for example:
>
> assume  exp1 is:
> (+ 1 (call/cc
> (lambda (k) ; k is the captured continuation
>   (set! saved-k k)
>   0)))
>
> exp2 is:
> (println 'hello)
>
> Whether exp2 is the continuation of exp1
>
> Are these two expressions equivalent?
>
> (begin
>   (exp1)
>   (exp2))
>
>
> (exp1 (lambda (v)
> (exp2 continuation-of-exp2)))
>
>
> So exp2 is exp1's continuation?
>
> It makes me confused.
>
> Excuse me, this question may be stupid, forgive my ignorance...
>
> Thanks.
>
> Br,
> serioadamo97
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] confusion about call-with-current-continuation

2018-10-25 Thread serioadamo97
Dear all,

I am learning call/cc in racket, so I wrote some experiment code:

#lang racket

(begin

  (define saved-k #f)

  (+ 1 (call/cc
(lambda (k) ; k is the captured continuation
  (set! saved-k k)
  0)))

  (println 'hello)

  (saved-k 100)

  ;; why 'hello not print more than once??
 
  )

The execution result of this codeis:

1
hello
101


It does not meet my expectation, my expectation is :


1
hello
101
hello
101
loop


About continuation, for example:

assume  exp1 is:
(+ 1 (call/cc
(lambda (k) ; k is the captured continuation
  (set! saved-k k)
  0)))

exp2 is:
(println 'hello)

Whether exp2 is the continuation of exp1

Are these two expressions equivalent?

(begin
  (exp1)
  (exp2))


(exp1 (lambda (v)
(exp2 continuation-of-exp2)))


So exp2 is exp1's continuation?

It makes me confused.

Excuse me, this question may be stupid, forgive my ignorance...

Thanks.

Br,
serioadamo97

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] distributed computation support for handin-server?

2018-10-25 Thread Tom Gillespie
That is inviting the students with a more hackerish mentality to find ...
alternative ways of scoring points. Probably better to not even entice them
with the possibility, given the bureaucratic headaches that it could cause.
Tom

On Wed, Oct 24, 2018 at 11:11 PM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

> Another random thought; has anyone thought of pushing this out to the
> student computer, by supplying students with a hopefully-opaque executable
> that runs the tests on a student program and then outputs a digitally
> signed test result?
>
> John
>
>
> > On Oct 23, 2018, at 21:50, Greg Hendershott 
> wrote:
> >
> > Have you considered some sort of yield-management incentive, such as
> > offering a higher grade to students who submit during less-busy
> > periods? :P
> >
> >
> > Although I don't know anything about the handin server, or very much
> > about load-balancing, just riffing:
> >
> > A simple round-robin HTTP proxy probably won't maximize processor
> > utilization. Maybe that doesn't matter. If it matters, I might start
> > with a single HTTP server that puts jobs in a queue, and let dedicated
> > racket-process-per-cpu processes pull them out one by one.
> >
> > I might try just using the filesystem for the queue. Something like:
> > Handin jobs are saved to files under a "to-do" dir. Workers claim jobs
> > by renaming a files into an "underway" dir, one"), and later clean
> > delete that and plop a result file into a "done" dir. The HTTP server
> > watches that, sends the response. (You could instead use a "real"
> > database, or even a whole messaging system. But this might be one of
> > those cases where the filesystem is the least-worst choice.)
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] distributed computation support for handin-server?

2018-10-25 Thread 'John Clements' via Racket Users
Another random thought; has anyone thought of pushing this out to the student 
computer, by supplying students with a hopefully-opaque executable that runs 
the tests on a student program and then outputs a digitally signed test result?

John


> On Oct 23, 2018, at 21:50, Greg Hendershott  wrote:
> 
> Have you considered some sort of yield-management incentive, such as
> offering a higher grade to students who submit during less-busy
> periods? :P
> 
> 
> Although I don't know anything about the handin server, or very much
> about load-balancing, just riffing:
> 
> A simple round-robin HTTP proxy probably won't maximize processor
> utilization. Maybe that doesn't matter. If it matters, I might start
> with a single HTTP server that puts jobs in a queue, and let dedicated
> racket-process-per-cpu processes pull them out one by one.
> 
> I might try just using the filesystem for the queue. Something like:
> Handin jobs are saved to files under a "to-do" dir. Workers claim jobs
> by renaming a files into an "underway" dir, one"), and later clean
> delete that and plop a result file into a "done" dir. The HTTP server
> watches that, sends the response. (You could instead use a "real"
> database, or even a whole messaging system. But this might be one of
> those cases where the filesystem is the least-worst choice.)



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.