[plt-scheme] Programatically Constructed Symbol Used As An Identifier???

From: Grant Rettke (grettke at acm.org)
Date: Fri Jun 26 10:26:01 EDT 2009

Hi Zelah,

On Fri, Jun 26, 2009 at 6:31 AM, Zelah Hutchinson<zelah at inbox.com> wrote:
> The "add" function is where I run in to trouble. The problem seems to be that 'adder is not the same as
> the function "adder".

> (symbol? 'adder)
> (procedure? 'adder)
> (symbol? adder)
> (procedure? adder)

> How can I make this work the way I want it to. The important parts for me are that the function I wish to
> call is already defined somewhere in my program and for calling it I wish to construct the existing name
> at run-time.

(define (add x y)
 (apply (symbol->function (append-symbol 'add 'er))
    (list x y)))

(define (symbol->function s)
  (case s
    [(adder) adder]
    [else (error "No function for ~a" s)]))

Believe it or not, this is probably how you really want to do it.

Posted on the users mailing list.