Advertisement
Jobjob

Programmation déclarative - Q1 - 08/2011

Jan 5th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.53 KB | None | 0 0
  1. (define (add-multiplicity l e)
  2.   (if (null? l)
  3.       (list (cons e 1))
  4.       (if (equal? (car (car l)) e)
  5.           (cons (cons e (+ (cdr (car l)) 1)) (cdr l))
  6.           (cons (car l) (add-multiplicity (cdr l) e))
  7.           )
  8.       )
  9.   )
  10.  
  11. (define (multiplicitylst lst)
  12.   (letrec
  13.       ((walk (lambda (list mul)
  14.                (if (null? list)
  15.                    mul
  16.                    (walk (cdr list) (add-multiplicity mul (car list)))
  17.                    )
  18.                )
  19.              ))
  20.     (walk lst '())
  21.     )
  22.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement