[plt-scheme] How can I print the procedure?

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Dec 3 05:50:36 EST 2007

Are you using HTDP language or general Scheme?

In your case, using 'eval' seems to be the the answer:

Using Language: Pretty Big (includes MrEd and Advanced Student)

(define (min-f measure L)
  (cond ((empty? (rest L)) (first L))
        ((< (measure (first L))
            (measure (min-f measure (rest L))))
         (first L))
        (else (min-f measure (rest L)))))

(define (my-measure f)
  (local ((define evaled-f (eval f)))
    (+ (evaled-f 1) (evaled-f 10) (evaled-f 100))))

(define my-list-of-functions (list 'sin
                                   'cos
                                   '(lambda(x)(+ (sin x)(cos x)))
                                   '(lambda(x)(* (sin x)(cos x)))))

(min-f my-measure my-list-of-functions)

;gives

sin

Chongkai



Majorinc, Kazimir wrote:
> I said:
>
> (define (min-f measure L)
>  (cond ((empty? (rest L)) (first L))
>        ((< (measure (first L))
>            (measure (min-f measure (rest L))))
>         (first L))
>        (else (min-f measure (rest L)))))
>
> (define (my-measure f)(+ (f 1) (f 10) (f 100)))
> (define my-list-of-functions (list (lambda(x)(sin x))
>                                   (lambda(x)(cos x))
>                                   (lambda(x)(+ (sin x)(cos x)))
>                                   (lambda(x)(* (sin x)(cos x)))))
>
> (min-f my-measure my-list-of-functions)
>
> And PLT said:
>
> #<procedure>
>
> Is there any way to actually print that #<procedure>? Except rewriting 
> such programs so they do not only calculate procedures, but also 
> prepare human-readable output? It can be significant complication ...
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.