this is my first day on Dr.Racket
and R5RS
language. I'm trying to modify the existing code I share below.
;; This is an internal helper procedure.
;; - it gets the method out of "in-object"
;; - it invokes the method, passing "for-object" as the
;; "self" for the method.
;;
(define (apply-method in-object for-object message args)
(let ((method (get-method message in-object)))
(cond ((method? method)
(apply method for-object args))
((eq? in-object for-object)
(display method)
(error "No method for" message 'in
(safe-ask 'UNNAMED-OBJECT
in-object 'NAME)))
(else (error "Can't delegate" message
"from" (safe-ask 'UNNAMED-OBJECT
for-object 'NAME)
"to" (safe-ask 'UNNAMED-OBJECT
in-object 'NAME))))))
(define (get-method message object) ; single-inheritance
(object message))
This snippet is the part of considerably huge project. Therefore, I share only the related part. Inside the project, when this apply-method
procedure is called. I got error on the line that starts with let
expression. The error message is as the following:
objsys.scm:53:2: application: not a procedure; expected a procedure that can be applied to arguments
given: #f
arguments...:
So, I wonder if is there anyone who can help me to solve the problem. EDIT
I suspect that there is a syntactic error like misused or unaligned paranthesis above but I cannot find the exact place that cause error.
When you have used apply-method
the value of in-object
is #f
. When apply-method
tries to do (get-method message in-object)
get-method
then applies (in-object message)
that turns into (#f 'some-unknown-message)
and since #f
is not a procedure racket has problems treating it as one and ends up with an error telling you that during application the given value #f
is not a procedure.
Since you are using racket, perhaps you should just start the debugger and put a breakpoint on get-method
and you'll see it. Note that Scheme and Racket languages has only one namespace for all bindings so you cannot have a procedure and a variable by the same name since a named procedure would occupy the very same variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.