Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on Michaels imperative Java solution, this is a idiomatic (lazy sequences) Clojure solution:</p> <pre><code>(ns stackoverflow (:import (java.nio.charset Charset CharsetEncoder))) (defn all-letters [charset] (let [encoder (. (Charset/forName charset) newEncoder)] (letfn [(valid-char? [c] (and (.canEncode encoder (char c)) (Character/isLetter c))) (all-letters-lazy [c] (when (&lt;= c (int Character/MAX_VALUE)) (if (valid-char? c) (lazy-seq (cons (char c) (all-letters-lazy (inc c)))) (recur (inc c)))))] (all-letters-lazy 0)))) </code></pre> <p><strong>Update:</strong> Thanks cgrand for this preferable high-level solution:</p> <pre><code>(defn letters [charset-name] (let [ce (-&gt; charset-name java.nio.charset.Charset/forName .newEncoder)] (-&gt;&gt; (range 0 (int Character/MAX_VALUE)) (map char) (filter #(and (.canEncode ce %) (Character/isLetter %)))))) </code></pre> <p>But the performace comparison between my first approach</p> <pre><code>user&gt; (time (doall (stackoverflow/all-letters "ascii"))) "Elapsed time: 33.333336 msecs" (\A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z \\ a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z) </code></pre> <p>and your solution </p> <pre><code>user&gt; (time (doall (stackoverflow/letters "ascii"))) "Elapsed time: 666.666654 msecs" (\A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z \\ a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z) </code></pre> <p>is quite interesting. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload