[racket] procedure to string
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131231/e2db9702/attachment.html>