[racket] procedure to string

From: Laurent (laurent.orseau at gmail.com)
Date: Tue Dec 31 06:42:25 EST 2013

Not sure that's what you really want, but you can use a simple macro to get
both the procedure and the corresponding string when defining the procedure:

#lang racket

;; Macro:
(define-syntax-rule (lambda+string args body ...)
  (values
   (lambda args body ...)
   (~a '(lambda args body ...))))

;; Example:
(define-values
  (foo foo-str)
  (lambda+string (x y) (+ x y 3)))

;; Tests:
(foo 3 4)
foo-str

If you want to get the body of an existing procedure, I don't know of any
other way that search for the procedure in the source file and extract it
from there, which is not a trivial matter and not 100% possible.

Laurent


On Mon, Dec 30, 2013 at 4:45 AM, Alegria Baquero
<alegriabaquero at gmail.com>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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131231/4eb2581f/attachment.html>

Posted on the users mailing list.