954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Scheme combine function help needed

I came accross this problem and I was wondering if anyone could help...
Consider this data definition that a company uses to keep track of the substances it stores in its factory:

;; A tank is 
;; (make-tank string number)
(define-struct tank (substance quantity))


Some examples would be:

(make-tank "oil" 25) 
(make-tank "distilled water" 10)


Write the function combine. You give it a list of tanks and it combines all the like substances together into one big tank of the correct size, returning a list of the new tanks.
For example:

(combine (cons (make-tank "water" 7) 
         (cons (make-tank "oil" 10)
         (cons (make-tank "water" 2)
         (cons (make-tank "vinegar" 3)
         (cons (make-tank "vinegar" 1)
         (cons (make-tank "water" 3) empty)))))))
"should be"
(cons (make-tank "water" 12)
      (cons (make-tank "oil" 10)
            (cons (make-tank "vinegar" 4) empty)))


Thank you

Soccerplayer13
Newbie Poster
2 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You