Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun p (X)
- (print X))
- ;clen
- (defun clen (X L)
- (cond ((null (car L)) NIL)
- ((= (car L) X) t)
- (t (clen X (cdr L)) )
- ))
- ;(p (clen 3 '(1 2 3 4 5 6 7)))
- ;clenx
- (defun clenx (X L)
- (cond ((null (car L)) NIL)
- ((= (car L) X) 1)
- (t (+ 1 (clenx X (cdr L))) )
- ))
- ;(p (clenx 7 '(1 2 3 4 5 6 7)))
- ;sort2----------------------------------------
- ; find maximum item from list
- (defun max2 (L)
- (cond ((null (cdr L)) (car L))
- ((>= (car L) (cadr L)) (max2 (cons (car L)(delete (cadr L) L))) )
- (t (max2 (cons (cadr L)(delete (car L) L))) )
- ))
- ; deletes given item from list (only first occurance)
- (defun deleteOnce (X L)
- (cond ((= (car L) X) (cdr L) )
- (t (cons (car L) (deleteOnce X (cdr L)) ) )
- ))
- (defun sort2 (L)
- (cond ((null (cdr L)) L)
- (t (cons (max2 L) (sort2 (deleteOnce (max2 L) L)) ))
- ))
- ;(p (sort2 '(1 2 5 4 8 7)))
- ;(p (sort2 '(1 1 5 6 )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement