• Re: Function problem

    From B. Pym@21:1/5 to All on Wed Jun 18 14:50:57 2025
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)