Reputation: 623
I'm fairly new to Scheme and I'm using DrRacket and I hope to get some much needed assistance.
I need to "combine" the four field values of my structure to make a single structure which you should be returning.
The four field values I am referring to are in the if statement of the code:
((auction-itemnum anentry)(auction-name anentry)(auction-currbid anentry)(auction-status anentry))
That of course does not work, as it won't let me run that.
This means my second if statement isn't going to work either, but if I can figure out the first one, then the second one will be clear.
The output I need is: (make-auction 50 "Bob" 100 "Open")
(at least for the second check-expect)
But figuring out the second check-expect will make the others work as well.
Here is my code:
(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))]
))
Upvotes: 2
Views: 144
Reputation: 2671
There's no reason in the world why you'd ever want a copy of an immutable struct. Just return the struct itself if you're not changing anything. Otherwise, you need to construct a new struct using "make-auction":
(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))]))
Upvotes: 2