I came up with a fairly boring example that does use places. Note that you
have to put this in a module and save the file:

> #lang racket
> (require racket/serialize
>          web-server/lang/serial-lambda
>          )
> (define current-place
>   (make-parameter 'initial))
> (define (main)
>   (define p
>     (place ch
>            (parameterize ([current-place 'p])
>              (define proc
>                (deserialize (place-channel-get ch)))
>              (place-channel-put ch (proc)))))
>   (place-channel-put/get p (serialize
>                             (serial-lambda ()
>                               (format "I was run on place ~a."
>                                       (current-place))))))


Then at the REPL, you can do:

> > (main)
> "I was run on place p."


-Philip

On Tue, Jan 17, 2017 at 9:07 PM, Philip McGrath <phi...@philipmcgrath.com>
wrote:

> For a quick example (without places), if you enter this in the definitions
> window of Dr. Racket:
>
>> #lang racket
>> (require web-server/lang/serial-lambda
>>          racket/serialize
>>          )
>> (define serialized-proc
>>   (serialize (serial-lambda (x)
>>                (printf "Your number is: ~a" x))))
>> serialized-proc
>> ((deserialize serialized-proc) 42)
>
> This is what you will get when you run the program:
>
>> '((3) 1 (('anonymous-module . "lifted.3")) 0 () () (0))
>> Your number is: 42
>
>
> There are a few caveats with serial-lambda. A big one is that you can't
> use it in the REPL: it has to be in a module context, so that there's a way
> to use the serialization information later. A second caveat is that any
> lexical values in the closure of serial-lambda must themselves be
> serializable: this is an instance of the general rule that, for serialize
> to succeed, all the nested contents of the data structure to be serialized
> must be serializable, not just the outermost container. Here's an example:
>
> #lang racket
>> (require web-server/lang/serial-lambda
>>          racket/serialize)
>> (define (make-proc lexical-value)
>>   (serial-lambda (immediate-arg)
>>     (printf (string-append "This value is part of the closure, so \n"
>>                            "it must be serializable:\n\t ~a\n")
>>             lexical-value)
>>     (printf "The immediate argument can be anything:\n\t ~a\n"
>>             immediate-arg)))
>> (struct opaque ())
>> (define works
>>   (make-proc (list 'apples 'peaches 'pears)))
>> ;; calling works on an non-serializable argument succeeds
>> (works (opaque))
>> ;; you can see that the lexical arg shows up
>> ;; in the serialized representation
>> (serialize works)
>> (newline)
>> (define broken
>>   (make-proc (opaque)))
>> ;; make-proc will succeed, and broken
>> ;; will appear to work as expected
>> (broken 42)
>> ;; however, attempting to serialize broken
>> ;; will raise an exn:fail
>> (serialize broken)
>
>
> If you have specific questions, I am happy to try to help!
>
> -Philip
>
> On Mon, Jan 16, 2017 at 11:13 PM, Andreas Olsson <photoguy....@gmail.com>
> wrote:
>
>> Strangely I can't get the example working from the docs and serial lambda
>> isn't a cakewalk ether. So if you got a working example please share it!
>>
>> --
>> 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.

Reply via email to