[racket] send/suspend outside #lang web-server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Sep 5 10:28:39 EDT 2011

You can't use the stateful and stateless send/suspends in the same
program. I think that's the problem with just switching the require in
the second file.

Jay

On Mon, Sep 5, 2011 at 8:16 AM, Veer <diggerrrrr at gmail.com> wrote:
> Thanks for reply.
>
> So stateless send/suspend will not work unless language is web-server
> , fine but when
> I use statefull send/suspend (in "something.rkt")  , it still does not
> work as expected.
> So what changes should I make so that get-something function returns 'something.
>
> Thanks.
>
>
> On Mon, Sep 5, 2011 at 6:08 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>> There are two send/suspend functions in the Web server collection.
>>
>> The one from web-server/lang/web is the stateless one. This relies on
>> the program transformation that #lang web-server implements, so it
>> must be used inside modules that use that language.
>>
>> The one from web-server/servlet/web is the stateful one. This is
>> implemented purely with native continuations, so it can be used
>> anywhere.
>>
>> Jay
>>
>> On Mon, Sep 5, 2011 at 12:44 AM, Veer <diggerrrrr at gmail.com> wrote:
>>> Can I use send/suspend  outside the #lang web-server module ?
>>> For example , the two modules  below don't work , I get something like :
>>> "Attempt to capture a continuation from within an unsafe context: ...."
>>>
>>> For statefull servlets this type of example works fine.
>>>
>>>
>>> "Module test.rkt"
>>> #lang web-server
>>> (require web-server/servlet-env)
>>> (require "something.rkt")
>>>
>>>
>>> (define (start request)
>>>  (show request))
>>>
>>> (define (show request)
>>>
>>>  (define (gen-resp make-url)
>>>    (response/xexpr
>>>     `(html (body (h1 "testing")
>>>                  (a ((href ,(make-url do-something))) "do something")))))
>>>
>>>  (define (do-something request)
>>>
>>>    (define something (get-something))
>>>
>>>
>>>    (cond
>>>      [(request? something) (error 'no-good)]
>>>      [else (error 'ok "~a" something)]))
>>>
>>>  (send/suspend/dispatch gen-resp))
>>>
>>> (serve/servlet  start #:stateless? #t )
>>>
>>>
>>> "Module something.rkt"
>>> #lang racket
>>> (require web-server/lang/web)
>>> (require web-server/http/xexpr)
>>>
>>> (provide get-something)
>>>
>>> (define (get-something)
>>>
>>>  (define  req
>>>    (send/suspend
>>>     (lambda (make-url)
>>>       (response/xexpr
>>>        `(html (body (h1 "something")
>>>                     (a ((href ,make-url)) "try something")))))))
>>>
>>>  (printf "why are we not here\n")
>>>  'something)
>>> _________________________________________________
>>>  For list-related administrative tasks:
>>>  http://lists.racket-lang.org/listinfo/users
>>>
>>
>>
>>
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://faculty.cs.byu.edu/~jay
>>
>> "The glory of God is Intelligence" - D&C 93
>>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93



Posted on the users mailing list.