Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lisp Function Problem

9 views
Skip to first unread message

Robert L.

unread,
May 26, 2018, 5:47:10 PM5/26/18
to
nissan2000 wrote:

> 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))

(define (total purchases)
(match purchases
[`((,item ,quan ,price) ...)
(let ((totals (map * quan price)))
`(,@(map list item totals) (total ,(apply + totals))))]))

'((book 20) (pen 6) (notepad 12) (total 38))

--
"They created ... an America which is not the real America ... but ultimately
this shadow America becomes ... so widely disseminated that its images and its
values come to devour the real America. And so the grand irony of all of
Hollywood is that Americans come to define themselves by the shadow of
America...." http://archive.org/details/nolies
0 new messages