We are using scheme version r5rs trying to check a procedure pointer for the type it is pointing to.
We’ve created a object using:
(define (%macro name exp env)
(define (set-exp new_exp) (set! exp new_exp))
(define (set-env new_env) (set! env new_env))
(define (set-name new_name) (set! name new_name))
(define (%dispatch call)
(cond
((eq? call 'get-exp) exp)
((eq? call 'get-env) env)
((eq? call 'get-name) name)
((eq? call 'set-exp) set-exp)
((eq? call 'set-env) set-env)
((eq? call 'set-name) set-name)
))
%dispatch
)
We then want to check a procedure reference to determine if it points to the dispatch function in another part of the code:
(define (macro? exp)
(eq? %macro exp)
)
This doesn’t seem to work, how do we properly check the pointer if it points to a macro object (really the dispatch procedure)?
Any help is greatly appreciated 🙂
Perhaps add one more method to your object that responds to ‘macro?. In the terms of a Java programmer: avoid instanceof calls. If all your objects follow a common protocol like implementing a macro? method, would that solve the problem?
In more featureful languages like full Racket, using a structure type property would also work. Since you’re deliberately in r5rs, your options are more limited.