我对Scheme很新,我使用DrRacket,我希望得到一些急需的帮助。
我需要"结合"我的结构的四个字段值构成一个你应该返回的结构。
我所指的四个字段值位于代码的if语句中:
((auction-itemnum anentry)(auction-name anentry)(拍卖 - 无聊)(拍卖状况)
这当然不起作用,因为它不会让我这样做。
这意味着我的第二个if语句也不起作用,但是如果我能找到第一个,那么第二个将是明确的。
我需要的输出是:(制作拍卖50" Bob" 100" Open")
(至少第二次检查预期)
但是,弄清楚第二次检查也会让其他人工作。
这是我的代码:
(define-struct auction (itemnum name currbid status))
(define Auction1
(make-auction 50 "Bob" 100 "Open"))
(define Auction2
(make-auction 20 "Joe" 40 "Closed"))
;; Data Definition of an auction
;; An auction is a structure: (make-auction itemnum name currbid status)
;; interp. item number, name, current bid, and status, represented
;; by a string
;; Signature: auctionbid: string number entry -> entry
;; Purpose: Consumes a bidder, a bid amount, and an auction entry
;; then returns an entry
;; Tests:
(check-expect (auctionbid "Frank" 150 Auction1) (make-auction 50 "Frank" 150 "Open"))
(check-expect (auctionbid "Billy" 80 Auction1) (make-auction 50 "Bob" 100 "Open"))
(check-expect (auctionbid "Jenny" 50 Auction2) (make-auction 20 "Joe" 40 "Closed"))
;; Define:
(define (auctionbid aname bid anentry)
(cond
[(or (< bid (auction-currbid anentry)) (string=? "Closed" (auction-status anentry)))
((auction-itemnum anentry) (auction-name anentry)
(auction-currbid anentry) (auction-status anentry))]
[(> bid (auction-currbid anentry))
((auction-itemnum anentry)(aname)
(bid)(auction-status anentry))]
))
答案 0 :(得分:2)
世界上没有理由为什么你想要一个不可变结构的副本。如果你没有改变任何东西,只需返回结构本身。否则,您需要使用&#34; make-auction&#34;
构建一个新结构(define (auctionbid aname bid anentry)
(cond
[(or (< bid (auction-currbid anentry))
(string=? "Closed" (auction-status anentry)))
anentry]
[(> bid (auction-currbid anentry))
(make-auction (auction-itemnum anentry)
aname bid
(auction-status anentry))]))