racket class类示例代码
代码语言:racket
所属分类:其他
代码描述:racket class类示例代码
代码标签: 示例
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#lang racket (define fish% (class object% (init size) ; initialization argument (super-new) ; superclass initialization ;; Field (define current-size size) ;; Public methods (define/public (get-size) current-size) (define/public (grow amt) (set! current-size (+ amt current-size))) (define/public (eat other-fish) (grow (send other-fish get-size))))) ;; Create an instance of fish% (define charlie (new fish% [size 10])) ;; Use `send' to call an object's methods (sen.........完整代码请登录后点击上方下载按钮下载查看
网友评论0