Skip to content

Instantly share code, notes, and snippets.

@microamp
Created August 7, 2020 11:13
Show Gist options
  • Save microamp/95642fd5c9326cbb5ccb152cc617842f to your computer and use it in GitHub Desktop.
Save microamp/95642fd5c9326cbb5ccb152cc617842f to your computer and use it in GitHub Desktop.
set? with no helper function
#lang racket
(define set?
(lambda (lat)
(cond
[(null? lat) #t]
[(null? (cdr lat)) #t]
[(eq? (car lat) (car (cdr lat))) #f]
[else (and (set? (cons (car lat) (cdr (cdr lat))))
(set? (cdr lat)))])))
(set? '()) ;; #t
(set? '(a)) ;; #t
(set? '(a b)) ;; #t
(set? '(a a)) ;; #f
(set? '(a b c d e)) ;; #t
(set? '(a b c b a)) ;; #f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment