• Re: Function problem

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jun 18 14:50:57 2025
    From Newsgroup: comp.lang.lisp

    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))
    --- Synchronet 3.21d-Linux NewsLink 1.2