简体   繁体   English

DrRacket:应用程序:不是R5RS语言的过程错误

[英]DrRacket:application: not a procedure Error on R5RS language

this is my first day on Dr.Racket and R5RS language. 这是我在Dr.RacketR5RS语言上的第一天。 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. 在项目内部,调用此apply-method过程时。 I got error on the line that starts with let expression. 我在以let表达式开头的行上出错了。 The error message is as the following: 错误消息如下:

objsys.scm:53:2: application: not a procedure; objsys.scm:53:2:申请:不是程序; expected a procedure that can be applied to arguments 期望一个可以应用于参数的过程
given: #f 给出:#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. 我怀疑有一个语法错误,如上面的误用或未对齐的paranthesis但我找不到导致错误的确切位置。

When you have used apply-method the value of in-object is #f . 使用apply-methodin-object值为#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. apply-method尝试做(get-method message in-object) get-method然后应用(in-object message)变成(#f 'some-unknown-message)并且因为#f 不是一个过程球拍将其视为一个问题,最后会出现一个错误,告诉您在应用程序中,给定值#f不是一个过程。

Since you are using racket, perhaps you should just start the debugger and put a breakpoint on get-method and you'll see it. 既然你正在使用racket,也许你应该启动调试器并在get-method上设置一个断点,你会看到它。 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. 请注意,Scheme和Racket语言只有一个名称空间用于所有绑定,因此您不能使用相同名称的过程和变量,因为命名过程将占用相同的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM