Talk:Clojure Programming/Examples/Norvig Spelling Corrector

The or in Clojure behaves differently than in Python

>>> s = set >>> s or 2 2 user=> (or #{} 2)
 * {}

We could use the fact that (seq #{}) is nil. However, or is a macro, and so does not automatically turn its arguments into sequences. Easiest to have known and known-edits2 return sequences (probably not as idiomatic)

(defn known [words nwords] (seq (for [w words :when (nwords w)] w)))

and

(defn known-edits2 [word nwords]  (seq (for [e1 (edits1 word) e2 (edits1 e1) :when (nwords e2)] e2)))