Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute LISP Online

(define (pred x y)

  (string<=? (symbol->string x)

             (symbol->string y)))

(define (count-copy l c)

  (if (or (null? l) (not (equal? (car l) c)))

      0

      (+ 1 (count-copy (cdr l) c))))

(define (f2 l)

  (if (null? l)

      '()

      (let ((n (count-copy l (car l))))

        (cons (car l)

              (if (> n 0)

                  (cons n (f2 (list-tail l n)))

                  (f2 (cdr l)))))))

(define (f pred L)

  (f2 (merge-sort pred L)))

> (f pred '(a b c b a c b m))
(a 2 b 3 c 2 m 1)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.