<div dir="ltr"><div><div>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?<br>
<br></div>Thank you again and happy new year.<br><br></div>Alegria<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 31, 2013 at 10:53 AM, Alexander D. Knauth <span dir="ltr"><<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Yes, you can do it with a struct with the property <span style="font-family:'Courier New'">prop:procedure</span>. </div>
<div><br></div><div><div><font face="'Courier New'">#lang racket</font></div><div><font face="'Courier New'"><br></font></div><div><font face="'Courier New'">(require rackunit)</font></div><div><font face="'Courier New'"><br>
</font></div><div><font face="'Courier New'">(struct my-proc (proc str)</font></div><div><font face="'Courier New'"> #:property prop:procedure (struct-field-index proc))</font></div><div><font face="'Courier New'"><br>
</font></div><div><font face="'Courier New'">(define f</font></div><div><font face="'Courier New'"> (my-proc (lambda (x) (+ x 1))</font></div><div><font face="'Courier New'"> "(lambda (x) (+ x 1))"))</font></div>
<div><font face="'Courier New'"><br></font></div><div><font face="'Courier New'">(check-true (procedure? f))</font></div><div><font face="'Courier New'">(check-equal? (f 1) 2)</font></div><div><font face="'Courier New'">(check-equal? (my-proc-str f)</font></div>
<div><font face="'Courier New'"> "(lambda (x) (+ x 1))")</font></div><div><font face="'Courier New'"><br></font></div><div><font face="'Courier New'">(define-syntax-rule (my-lambda args body ...)</font></div>
<div><font face="'Courier New'"> (my-proc (lambda args body ...)</font></div><div><font face="'Courier New'"> (substring (~v '(lambda args body ...)) 1)))</font></div><div><font face="'Courier New'"><br>
</font></div><div><font face="'Courier New'">(define f2</font></div><div><font face="'Courier New'"> (my-lambda (x) (+ x 1)))</font></div><div><font face="'Courier New'"><br></font></div><div><font face="'Courier New'">(check-true (procedure? f2))</font></div>
<div><font face="'Courier New'">(check-equal? (f2 1) 2)</font></div><div><font face="'Courier New'">(check-equal? (my-proc-str f2)</font></div><div><font face="'Courier New'"> "(lambda (x) (+ x 1))")</font></div>
<div><br></div></div><br><div><div><div class="h5"><div>On Dec 29, 2013, at 10:45 PM, Alegria Baquero wrote:</div><br></div></div><blockquote type="cite"><div><div class="h5"><div dir="ltr"><div><div>Hello,<br><br></div>is there any way to transform a function's body to a string such as "(lambda(x)...)"?<br>
<br></div>Thanks<br><br>Alegria<br></div></div></div><div class="im"> ____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></blockquote></div><br></div></blockquote></div><br><br clear="all"><br>-- <br><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">---------------------------------------------------------------------------------------</span><div>
<span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">PhD candidate<br><span style="background-color:rgb(255,255,255)">Department of Informatics<br><span style="color:rgb(34,34,34)">Donald</span> <span style="color:rgb(34,34,34)">Bren</span> School of Information and Computer Sciences<br>
University of Cal</span>ifornia, Irvine</span></div>
</div>