Paste number 20643: from srfi 1

Index of paste annotations: 1

Paste number 20643: from srfi 1
Pasted by: saccade
When:8 years, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+FXF
Channel:#scheme
Paste contents:
Raw Source | XML | Display As
(define (null-list? l)
  (cond ((pair? l) #f)
	((null? l) #t)
	(else (error "null-list?: argument out of domain" l))))

(define (list= = . lists)
  (or (null? lists) ; special case

      (let lp1 ((list-a (car lists)) (others (cdr lists)))
	(or (null? others)
	    (let ((list-b (car others))
		  (others (cdr others)))
	      (if (eq? list-a list-b)	; EQ? => LIST=
		  (lp1 list-b others)
		  (let lp2 ((list-a list-a) (list-b list-b))
		    (if (null-list? list-a)
			(and (null-list? list-b)
			     (lp1 list-b others))
			(and (not (null-list? list-b))
			     (= (car list-a) (car list-b))
			     (lp2 (cdr list-a) (cdr list-b)))))))))))
			

(list= eq? '(a) '(a))

;Value: #t

(list= eq? '(a) '(a) '(a))

;Value: #f

Annotations for this paste:

Annotation number 1: solution pointed out by Riastradh
Pasted by: saccade
When:8 years, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+FXF/1
Paste contents:
Raw Source | Display As
(define (list= = . lists)
  (or (null? lists) ; special case

      (let lp1 ((list-a (car lists)) (others (cdr lists)))
	(or (null? others)
	    (let ((list-b (car others))
		  (others (cdr others)))
	      (if (eq? list-a list-b)	; EQ? => LIST=
		  (lp1 list-b others)
		  (let lp2 ((list-a-1 list-a) (list-b-1 list-b))
		    (if (null-list? list-a-1)
			(and (null-list? list-b-1)
			     (lp1 list-b others))
			(and (not (null-list? list-b-1))
			     (= (car list-a-1) (car list-b-1))
			     (lp2 (cdr list-a-1) (cdr list-b-1)))))))))))


(list= eq? '(a) '(a))

;Value: #t

(list= eq? '(a) '(a) '(a))

;Value: #t

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.