Sujet : Re: Function problem
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 18. Jun 2025, 15:50:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102ujoe$36fp7$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Write a Function 'total' that takes an orderd list ie.
((itemA quantityA costA)(itemB quantityB costB)....)
but returns a list giving the total cost plus the overall cost.
Eg:
LISP>(total'((book 2 10)(pen 3 2)(notepad 1 12)))
((BOOK 20)(PEN 6)(NOTEPAD 12)(TOTAL 38))
Gauche Scheme
(use util.match) ;; match-lambda
(let ((grand 0))
(append
(map
(match-lambda ((item quan price)
(let1 total (* quan price)
(inc! grand total) (list item total))))
'((book 2 10)(pen 3 2)(notepad 1 12)))
`((total ,grand))))
((book 20) (pen 6) (notepad 12) (total 38))