Scheme 方案格式帮助

Scheme 方案格式帮助,scheme,racket,Scheme,Racket,我一直在为学校做一个项目,该项目从类文件中提取函数,并将它们转换为对象/类。本作业是关于scheme中的面向对象编程 然而,我的问题是我的代码格式不正确 每当我给它一个要传递的文件时,它给我的输出将该类的方法包装在一个列表中,这样就不会真正声明该类。我一辈子都搞不懂如何将方法列表中的括号去掉 我真的很感激任何帮助 下面是输出、类文件和代码 (define pointInstance (let ((myx 1) (myy 2)) (lambda msg (con

我一直在为学校做一个项目,该项目从类文件中提取函数,并将它们转换为对象/类。本作业是关于scheme中的面向对象编程

然而,我的问题是我的代码格式不正确

每当我给它一个要传递的文件时,它给我的输出将该类的方法包装在一个列表中,这样就不会真正声明该类。我一辈子都搞不懂如何将方法列表中的括号去掉

我真的很感激任何帮助

下面是输出、类文件和代码

(define pointInstance  
  (let ((myx 1) (myy 2))  
    (lambda msg  
      (cond  
       (((eq? (car msg) getx) myx)  
        ((eq? (car msg) gety) myy)  
        ((eq? (car msg) setx) (set! myx x))  
        ((eq? (car msg) show) (begin (display "[") (display myx) (display ",") (display  myy) (display "]"))))))))
如果您在cond之后查看,您将看到所有这些eq语句是如何包含在列表中的。我不能让它正常工作,除非它们没有被顶级列表所包装

;;;; PART1 ---  A super-easy set of classes. Just models points and lines. Tests all of >the 
;; basics of class behavior without touching on anything particularly complex.

(class pointInstance (parent:) (constructor_args:)
  (ivars: (myx 1) (myy 2))
  (methods: 
   (getx () myx)
   (gety () myy)
   (setx (x) (set! myx x))
   (show () (begin (display "[") (display myx) (display ",") (display myy) (display "]")))
   ))



(require (lib "trace.ss"))

;; Continue reading until you hit the end of the file, all the while
;; building a list with the contents 
(define load-file
 (lambda (port)
 (let ((rec (read port)))
 (if (eof-object? rec)
 '()
 (cons rec (load-file port))))))

;; Open a port based on a file name using open-input-file
(define (load fname)
 (let ((fport (open-input-file fname)))
 (load-file fport)))



;(define lis (load "C:\\Users\\Logan\\Desktop\\simpletest.txt"))
;(define lis (load "C:\\Users\\Logan\\Desktop\\complextest.txt"))
(define lis (load "C:\\Users\\Logan\\Desktop\\pointinstance.txt"))

;(display  (cdaddr (cdddar lis)))

(define makeMethodList
  (lambda (listToMake retList)
    ;(display listToMake)
    (cond
      [(null? listToMake)
       retList
       ;(display "The list passed in to parse was null")
      ]
      [else
      (makeMethodList (cdr listToMake) (append retList (list (getMethodLine         listToMake))))
      ]
        )
    ))
;(trace makeMethodList)

;this works provided you just pass in the function line
(define getMethodLine 
  (lambda (functionList)
    `((eq? (car msg) ,(caar functionList)) ,(caddar functionList))))

(define load-classes
  (lambda paramList
    (cond 
    [(null? paramList) (display "Your parameters are null, man.")]
[(null? (car paramList))(display "Done creating class definitions.")]
[(not (null? (car paramList)))

     (begin 
     (let* ((className (cadaar paramList))
            (classInstanceVars (cdaddr (cddaar paramList)))
            (classMethodList (cdr (cadddr (cddaar paramList))))
            (desiredMethodList (makeMethodList classMethodList  '()))

            )
       ;(display "Classname: ")
       ;(display className)
       ;(newline)(newline)

       ;(display "Class Instance Vars: ")
       ;(display classInstanceVars)
       ;(newline)(newline)

       ;(display "Class Method List: ")
       ;(display classMethodList)
       ;(newline)

       ;(display "Desired Method List: ")
       ;(display desiredMethodList))
       ;(newline)(newline)

;---------------------------------------------------- 
;do not delete the below code!`
      `(define ,className 
         (let  ,classInstanceVars 
           (lambda msg 
             ;return the function list here
             (cond ,(makeMethodList classMethodList  '())))
             ))
;---------------------------------------------------
))]
)
))

(load-classes lis)
;(load-classes lis)
;(load-classes-helper lis)
;(load-classes "simpletest.txt")
;(load-classes "complextest.txt")

;method list
;(display (cdr (cadddr (cddaar <class>))))
;;;;第1部分——一组超级简单的类。只是模型点和线。测试所有>项
;; 基本的类行为,而不涉及任何特别复杂的内容。
(类pointInstance(父级:)(构造函数参数:)
(ivars:(第一个多年电价)(第二个多年电价)
(方法:
(getx()myx)
(gety()myy)
(setx(x)(set!myx))
(显示()(开始(显示“[”)(显示myx)(显示“,”)(显示myy)(显示“]))
))
(需要(库“trace.ss”))
;; 一直读到文件的末尾
;; 构建包含内容的列表
(定义加载文件)
(lambda(港口)
(let((rec(读取端口)))
(如果(eof对象?rec)
'()
(cons rec(加载文件端口(()())))
;; 使用“打开输入文件”根据文件名打开端口
(定义(加载fname)
(let((fport(打开输入文件fname)))
(加载文件fport)))
;(定义lis(加载“C:\\Users\\Logan\\Desktop\\simpletest.txt”))
;(定义lis(加载“C:\\Users\\Logan\\Desktop\\complextest.txt”))
(定义lis(加载“C:\\Users\\Logan\\Desktop\\pointinstance.txt”))
;(显示(cdaddr(cdddar lis)))
(定义makeMethodList)
(lambda(listToMake retList)
(显示列表制作)
(续)
[(空?listToMake)
复述
;(显示“传入解析的列表为空”)
]
[其他
(makeMethodList(cdr listToMake)(追加retList(list(getMethodLine listToMake)))
]
)
))
;(跟踪makeMethodList)
;如果您只需传入函数行,则此操作有效
(定义getMethodLine
(lambda(功能列表)
`((等式(car消息),(caar功能列表)),(caddar功能列表)))
(定义荷载等级)
(lambda参数列表)
(续)
[(空?参数列表)(显示“您的参数为空,伙计。”)]
[(null?(car参数列表))(显示“创建类定义完成”。)]
[(非(空?(汽车参数列表)))
(开始
(let*((类别名称(CADAR参数列表))
(classInstanceVars(cdaddr(cddaar参数列表)))
(类方法列表(cdr(CADDR(cddaar参数列表)))
(desiredMethodList(makeMethodList类MethodList’())
)
;(显示“Classname:”)
;(显示类名)
;(新行)(新行)
;(显示“类实例变量:”)
;(显示classInstanceVars)
;(新行)(新行)
;(显示“类方法列表:”)
;(显示类方法列表)
(新行)
;(显示“所需方法列表:”)
;(显示所需方法列表)
;(新行)(新行)
;---------------------------------------------------- 
;请勿删除以下代码`
`(定义,类名)
(let,classInstanceVars
(兰姆达味精)
;在此处返回函数列表
(第二,(makeMethodList类MethodList’()))
))
;---------------------------------------------------
))]
)
))
(负荷等级lis)
;(负荷等级lis)
;(加载类)
;(加载类“simpletest.txt”)
;(加载类“complextest.txt”)
;方法列表
;(显示(cdr(CADDR(cddaar)))

条件的第1子句中,左括号太多了

即:

更新:

你在找这个吗

(cond ,@(makeMethodList classMethodList  '())
      ^^
或者你可以:

(cond . ,(makeMethodList classMethodList  '())

cond
的第1子句中的左括号太多

即:

更新:

你在找这个吗

(cond ,@(makeMethodList classMethodList  '())
      ^^
或者你可以:

(cond . ,(makeMethodList classMethodList  '())

我知道,我不知道如何摆脱它。你对如何去掉方法的外圆括号有什么建议吗?@John:请不要把问题作为家庭作业,除非OP声明它确实是家庭作业,或者除非你有一个水晶球。我知道,我不知道如何去掉它。你对如何去掉方法的外圆括号有什么建议吗?@John:请不要把问题作为家庭作业,除非OP声明它确实是家庭作业,或者除非你有一个水晶球。