我有这个代码:
(define (make-entry person money job)
(list person money job))
(define (make-person list)
(define (sampledata
(list (make-entry (make-person "jerry" "nicolas") 100 "clerk")
(make-entry (make-person "shara" "vi") 50 "singer")))
(define trial-person (make-entry (make-person "jerry" "nicolas") 100 "clerk")
我的问题是我不知道我可以使用哪种功能,所以我会导致:
(name trial-person);
Value: (jerry nicolas)
(money trial-person)
;Value: (100)
(job trial-person)
;Value: (clerk)
我做了一些阅读但仍未提出答案。如果有人可以帮助我,那么我可以参加课堂会很好。提前致谢
答案 0 :(得分:0)
在第二个define
上,您正在定义一个过程make-person
,它接受参数list
并且它永远不会结束。如果你正在使用DrRacket并按下 CTRL + i ,你会看到这个奇怪的身份:
(define (make-person list)
(define (sampledata
(list (make-entry (make-person "jerry" "nicolas") 100 "clerk")
(make-entry (make-person "shara" "vi") 50 "singer")))
(define trial-person (make-entry (make-person "jerry" "nicolas") 100 "clerk")
您会发现在过程make-person
的定义中有一个本地过程定义。使用list
作为参数将使过程sampledata
永远不会起作用,因为它使用list
作为过程,但将使用您传递的任何内容。 sampledata
也有一个本地定义trial-person
,但由于这两个过程都没有一个正文,所有这些都会导致语法错误,即使你在最后添加了结束括号。
一个有根据的猜测我想代码应该是这样的:
如果make-person
的实现与list
的实现相同,则应该是:
(define make-person list) ; removed ( before make.person
(define sampledata ; removed ( before sampledata
(list (make-entry (make-person "jerry" "nicolas") 100 "clerk")
(make-entry (make-person "shara" "vi") 50 "singer")))
(define trial-person (make-entry (make-person "jerry" "nicolas") 100 "clerk")) ; added missing ) at end
现在,由于您将代码格式化为好像代码已正确编写,因此几乎不可能看到任何错误或差异,因此我对更改进行了评论。按 CTRL + i 通常会为您节省大量时间。
关于如何制作name
,money
和job
的问题:如果你评估trial-person
,那么如果你知道你的(("jerry" "nicolas") 100 "clerk")
就得到car
cdr
和money
应该清楚100
的定义与从该列表中获取cadr
的过程相同,即<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DEPLOYPARAMS SYSTEM "depcntl.dtd">
<DEPLOYPARAMS DEFAULTSERVERNAME = "" COPYPROGRAMINFO = "YES" COPYMAPVARPERVALS = "YES" COPYWFLOWVARPERVALS = "NO" COPYWFLOWSESSLOGS = "NO" COPYDEPENDENCY = "YES" LATESTVERSIONONLY = "NO" RETAINGENERATEDVAL = "YES" RETAINSERVERNETVALS = "YES" RETAINMAPVARPERVALS = "NO">
<DEPLOYGROUP>
<APPLYLABEL SOURCELABELNAME = "" SOURCEMOVELABEL = "NO" TARGETLABELNAME = "" TARGETMOVELABEL = "NO"/>
</DEPLOYGROUP>
</DEPLOYPARAMS>
。