[racket] procedure to string

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Jan 3 15:10:15 EST 2014

What kind of inspection?

If it's for security purposes, you're better off running the procedures 
in a sandbox (see the `racket/sandbox' module). You can even control the 
amount of time something is allowed to run. Also, `serial-lambda' might 
be something you could use, if the sender and receiver are both running 
the same program. (It might work in other circumstances; I don't know.)

Neil ⊥

On 01/02/2014 09:41 AM, Alegria Baquero wrote:
> Thank you for your kind responses. Your solutions are good ones but
> unfortunately don't fit my purpose. Imagine a mobile code scenario where
> you have no control of the definition of a closure. What I want to do is
> to be able to print the body of any incoming closure that arrives in a
> message. So if server A sends server B a closure (lambda () (displayln
> "hello world")), B could grab that incoming closure and capture it as
> the string "(lambda () (displayln "hello world"))" so it can be
> inspected before executing it. Does this make sense? How can I then
> construct a function procedure->string that transforms at runtime
> (without using macros) a closure's body to a string?
>
> Thank you again and happy new year.
>
> Alegria
>
>
> On Tue, Dec 31, 2013 at 10:53 AM, Alexander D. Knauth
> <alexander at knauth.org <mailto:alexander at knauth.org>> wrote:
>
>     Yes, you can do it with a struct with the property prop:procedure.
>
>     #lang racket
>
>     (require rackunit)
>
>     (struct my-proc (proc str)
>        #:property prop:procedure (struct-field-index proc))
>
>     (define f
>        (my-proc  (lambda (x) (+ x 1))
>                 "(lambda (x) (+ x 1))"))
>
>     (check-true (procedure? f))
>     (check-equal? (f 1) 2)
>     (check-equal? (my-proc-str f)
>                    "(lambda (x) (+ x 1))")
>
>     (define-syntax-rule (my-lambda args body ...)
>        (my-proc                 (lambda args body ...)
>                 (substring (~v '(lambda args body ...)) 1)))
>
>     (define f2
>        (my-lambda (x) (+ x 1)))
>
>     (check-true (procedure? f2))
>     (check-equal? (f2 1) 2)
>     (check-equal? (my-proc-str f2)
>                    "(lambda (x) (+ x 1))")
>
>
>     On Dec 29, 2013, at 10:45 PM, Alegria Baquero wrote:
>
>>     Hello,
>>
>>     is there any way to transform a function's body to a string such
>>     as "(lambda(x)...)"?
>>
>>     Thanks
>>
>>     Alegria
>>     ____________________
>>      Racket Users list:
>>     http://lists.racket-lang.org/users
>
>
>
>
> --
> ---------------------------------------------------------------------------------------
> PhD candidate
> Department of Informatics
> Donald Bren School of Information and Computer Sciences
> University of California, Irvine
>
>
> ____________________
>    Racket Users list:
>    http://lists.racket-lang.org/users
>


Posted on the users mailing list.