Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

post you are run length encoding in lisp

Name: Anonymous 2014-10-05 3:18

critique mine pl0x:

(defun rle (str) ;run length encoding
(let ((i 0) c count out)
(while (< i (length str))
(if (eq c (elt str i))
(setq count (1+ count))
(when c
(setq out (append out (list (cons c count)))))
(setq c (elt str i))
(setq count 1))
(setq i (1+ i)))
(when c (setq out (append out (list (cons c count)))))
out))

Name: >>12 2014-10-05 18:26

>>21

(defun rle (l)
(cond ((eq l '()) '())
- (t (let (e (rle (cdr l)))
+ (t (let ((e (rle (cdr l))))
(cond
((eq e '()) (cons (cons 1 (car l)) e))
((eq (car l) (cdar e)) (cons (cons (+ 1 (caar e)) (cdar e)) (cdr e)))
(t (cons (cons 1 (car l)) e)))))))


Fuck, I'm an idiot.

I just deepened the varlist of let, and it worked perfectly!

(rle '(a a a b c c))
((3 . a) (1 . b) (2 . c))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List