Why (first [*' *]) instead of just *?
Lines 57--62 of https://github.com/clojure/math.numeric-tower/blob/master/src/main/clojure/clojure/math/numeric_tower.clj ;; so this code works with both 1.2.x and 1.3.0: (def ^{:private true} minus (first [-' -])) (def ^{:private true} mult (first [*' *])) (def ^{:private true} plus (first [+' +])) (def ^{:private true} dec* (first [dec' dec])) (def ^{:private true} inc* (first [inc' inc])) I was wondering why (first [*' *]) is used instead of just *. My guess, but I do not know how to verify: 1. IIRC early versions of Clojure defaulted to auto-promotion arithmetic operators. 2. My guess the default was changed to not permote between 1.2.x and 1.3.0. 3. Total guess, the 1.2.x reader treat the ' at the end of a symbol as being it's own thing and change to (quote ..) 4. So that in 1.2.x [*' *] would become [* (quote *)], and first would get *, and * auto promoted in 1.2.x. In 1.3.0 first gets the auto-promotion version *'. But that a total guess. Why is this construction used? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How do I upgrade nREPL?
I saw no difference in behavior, if I understood how to create the :dev profile: {:user {:plugins [[cider/cider-nrepl 0.9.0-SNAPSHOT] [lein-pprint 1.1.2]] :dependencies [[org.clojure/tools.nrepl 0.2.10]]} :dev {:dependencies [[org.clojure/tools.nrepl 0.2.10]]}} -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How do I upgrade nREPL?
Through some additional experimentation, I have found when I start Leiningen repl within a Leiningen project, the nrepl dependency from ~/.lien/profiles.clj is being used. nREPL 0.2.10 is started. This is true if I start via `lein repl` or `cider-jack-in`. The problem exists when starting free of a project. -- Shannon -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How do I upgrade nREPL?
I would like to upgrade nREPL, but it appears I am still using version 0.2.6. My ~/.lein/profiles.clj: {:user {:plugins [[cider/cider-nrepl 0.9.0-SNAPSHOT] [lein-pprint 1.1.2]] :dependencies [[org.clojure/tools.nrepl 0.2.10]]}} When I start lein repl britannia:~ srseverance$ lein repl nREPL server started on port 50957 on host 127.0.0.1 - nrepl://127.0.0.1:50957 REPL-y 0.3.5, nREPL 0.2.6 Clojure 1.6.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 (The first time after adding tools.nrepl to profiles.clj, leiningen did download nrepl 0.2.10.) And M-x cider-jack-in ; CIDER 0.9.0snapshot (package: 20150329.1355) (Java 1.8.0_25, Clojure 1.6.0, nREPL 0.2.6) WARNING: CIDER requires nREPL 0.2.7 to work properly Leiningen is version 2.5.1 This is on Max OS X 10.10.2 -- Shannon -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Making cryptograms, my first Clojure function. Feedback welcome.
Dan, Good point in general. However, in this case, the function returned is used to make cryptograms, simple cryptographic word puzzles. Characters outside a-z, A-Z, 0-9 are passed through by design to leave punctuation and whitespace in place to provide structure to aid the person solving the puzzle. Stripping the context or shuffling them would make the problem harder. Too hard for intended audience. -- Shannon Severance On Thursday, June 13, 2013 11:49:34 AM UTC-7, Alan Thompson wrote: One thing that threw me at first was the double arg in the function #(encrypt % %). It took a while before I realized you were supplying each character as both the map key value and a default return value (thus, a non-alphanumeric char like * would come through w/o translation). While this works, what I would do instead is be more explicit that only certain chars are allowed in the first place. So, I'd add a filter up front that would throw an exception if any non-alphanumeric char were encountered. I can't tell you how many times this fail-fast type of behavior has saved me, since it makes bugs easy to find rather than burying the cause of a problem (kinda like getting an error at compile-type instead of at runtime). Alan Thompson -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Making cryptograms, my first Clojure function. Feedback welcome.
My wife informed me that cryptograms typically use the same substitutions for upper and lower case letters. If a becomes h, then A becomes H. Changes: 1. Revert to explicit strings for characters to shuffle, without using range and what not. 2. a-z mapping matches A-Z mapping 3. Comments to clarify this is for a word puzzle. Additional based on the How to Design Functions from Gregor Kiczales Introduction to Systematic Program Design - Part 1https://www.coursera.org/course/programdesignon coursera. (Pr ;; - (String - String) ;; Returns an anonymous function (AF) closed over a simple ;; replacement cipher. ;; ;; AF has type String - String ;; Produce a simple cryptogram, a word game, based on the ;; cipher in its closure. ;; ;; ** THIS IS FOR WORD GAMES/ENTERTAINMENT ONLY ** ;; ** DO NOT USE TO ENCRYPT ANYTHING YOU WISH ** ;; ** TO KEEP SECRET. ** ;; ;; The replacement cipher has the following properties ;; Each digit is replaced with a digit. ;; Each letter is replaced with a letter. ;; Case is preserved. ;; The mapping between a letter and another ;;is the same irrespective of case. ;; ;; Multiple calls to make-crypto will return different cryptos each ;; with different substitution keys. Multiple calls to a given crypto ;; returned by make-crypto will use the same substitution key. (defn make-crypto [] (let [make-upper #(.toUpperCase (apply str %)) lower (seq abcdefghijklmnopqrstuvwxyz) digit (seq 0123456789) [sl sd] (map shuffle [lower digit]) encrypt (zipmap (concat lower (make-upper lower) digit) (concat sl(make-upper sl) sd))] (fn [s] (apply str (map #(encrypt % %) s) Examples using famous phrases in US history: user= ((make-crypto) Only Thing We Have to Fear Is Fear Itself.) Fxkv Wjyxb Di Jnoi wf Rinp Yg Rinp Ywgikr. user= ((make-crypto) I have a dream that my four little children will one #_= day live in a nation where they will not be judged by the color of #_= their skin but by the content of their character.) B axgv x fevxl caxc lm hzie ybccyv rabyfevn qbyy znv\n fxm ybgv bn x nxcbzn qavev cavm qbyy nzc ov difkvf om cav rzyze zh\ ncavbe jpbn oicom cav rzncvnc zh cavbe raxexrcve. user= ((make-crypto) One small step for man, one giant leap for mankind.) Bqy psxkk pzyc hbv sxq, bqy grxqz kyxc hbv sxqnrqi. -- Shannon -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Making cryptograms, my first Clojure function. Feedback welcome.
Thank you all, I've learned something from each entry. My latest version, incorporating some of the changes suggested: (defn make-crypto [] (let [lower (map char (range (int \a) (inc (int \z upper (map char (range (int \A) (inc (int \Z digit (map char (range (int \0) (inc (int \9 [sl su sd] (map shuffle [lower upper digit]) encrypt (zipmap (concat lower upper digit) (concat sl su sd))] (fn [s] (apply str (map #(encrypt % %) s) I specified the range the way I did because I wanted meaningful start and end points, I don't have the code points for many characters memorized. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Making cryptograms, my first Clojure function. Feedback welcome.
Thank you. I will sit down with the code and Clojure references to figure out what it is doing. For this problem, I don't want to use the full printable range. That would make the word problem too difficult. I specifically set mine up to substitute UPPER for UPPER, lower for lower, digit for digit, and then preserve any other characters, (spacing punctuation etc.) as is, to decrease the diffieculty. On Monday, June 10, 2013 8:00:41 PM UTC-7, Michael-Keith Bernard wrote: Here is an alternative implementation that generalizes the encrypt/decrypt functionality. It also uses all printable characters for the source dictionary. https://gist.github.com/SegFaultAX/5754209 P.S. I accidentally posted this as a reply to an older question I happened to have open. On Monday, June 10, 2013 6:16:03 PM UTC-7, Shannon Severance wrote: I'm new to Clojure, but with some lisp experience, I've dabbled in Scheme for a few years. Used Racket earlier this year for a couple of sectoins of a MOOC. And occasionally write Emacs lisp. The idea is to create cyptogramshttps://en.wikipedia.org/wiki/Cryptogram. These are word puzzles using simple ciphers, and not meant for keeping real secrets. ;; - (String - String) ;; Returns a function that takes a string and produces a cryptogram. ;; Multiple calls to make-crypto will return different cryptos ;; each with different substitution keys. Multiple calls to a given ;; crypto returned by make-crypto will use the same substitution key. (defn make-crypto [] (let [lower (seq abcdefghijklmnopqrstuvwxyz) upper (seq ABCDEFGHIJKLMNOPQRSTUVWXYZ) digit (seq 0123456789) shuffled-lower (shuffle lower) shuffled-upper (shuffle upper) shuffled-digit (shuffle digit) encrypt (reduce conj (map (partial assoc {}) (concat lower upper digit) (concat shuffled-lower shuffled-upper shuffled-digit)))] (fn [s] (apply str (map #(encrypt % %) s) To me, it looks like too much code in defining the encrypt map. But I do not know how. -- Shannon -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Making cryptograms, my first Clojure function. Feedback welcome.
I'm new to Clojure, but with some lisp experience, I've dabbled in Scheme for a few years. Used Racket earlier this year for a couple of sectoins of a MOOC. And occasionally write Emacs lisp. The idea is to create cyptograms https://en.wikipedia.org/wiki/Cryptogram. These are word puzzles using simple ciphers, and not meant for keeping real secrets. ;; - (String - String) ;; Returns a function that takes a string and produces a cryptogram. ;; Multiple calls to make-crypto will return different cryptos ;; each with different substitution keys. Multiple calls to a given ;; crypto returned by make-crypto will use the same substitution key. (defn make-crypto [] (let [lower (seq abcdefghijklmnopqrstuvwxyz) upper (seq ABCDEFGHIJKLMNOPQRSTUVWXYZ) digit (seq 0123456789) shuffled-lower (shuffle lower) shuffled-upper (shuffle upper) shuffled-digit (shuffle digit) encrypt (reduce conj (map (partial assoc {}) (concat lower upper digit) (concat shuffled-lower shuffled-upper shuffled-digit)))] (fn [s] (apply str (map #(encrypt % %) s) To me, it looks like too much code in defining the encrypt map. But I do not know how. -- Shannon -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Making cryptograms, my first Clojure function. Feedback welcome.
Thank you for your example. I especially like doing sl, su, sd in one line. However: user= ((gen-crypto) 1 for me, 2 for you.) 1 zdu gy, 2 zdu fdx. The numbers are coming through without translation. I believe defining digit as: user= (map #(char (+ 48 %)) (range 10)) (\0 \1 \2 \3 \4 \5 \6 \7 \8 \9) will fix that issue. Or (map char (range 48 58)) On Monday, June 10, 2013 7:42:45 PM UTC-7, Kelker Ryan wrote: Here's my re-write. user (defn gen-crypto [] (let [atoz (range 65 91) upper (map char atoz) lower (map #(char (+ % 32)) atoz) digit (range 10) [sl su sd] (map shuffle [lower upper digit]) encrypt (reduce conj (map hash-map (concat lower upper digit) (concat sl su sd)))] (fn [s] (apply str (map #(encrypt % %) s) #'user/gen-crypto user ((gen-crypto) abc)ghm user ((gen-crypto) abc)efz 11.06.2013, 10:31, Shannon Severance s...@s53.me javascript:: I'm new to Clojure, but with some lisp experience, I've dabbled in Scheme for a few years. Used Racket earlier this year for a couple of sectoins of a MOOC. And occasionally write Emacs lisp. The idea is to create cyptograms. These are word puzzles using simple ciphers, and not meant for keeping real secrets. ;; - (String - String) ;; Returns a function that takes a string and produces a cryptogram. ;; Multiple calls to make-crypto will return different cryptos ;; each with different substitution keys. Multiple calls to a given ;; crypto returned by make-crypto will use the same substitution key. (defn make-crypto [] (let [lower (seq abcdefghijklmnopqrstuvwxyz) upper (seq ABCDEFGHIJKLMNOPQRSTUVWXYZ) digit (seq 0123456789) shuffled-lower (shuffle lower) shuffled-upper (shuffle upper) shuffled-digit (shuffle digit) encrypt (reduce conj (map (partial assoc {}) (concat lower upper digit) (concat shuffled-lower shuffled-upper shuffled-digit)))] (fn [s] (apply str (map #(encrypt % %) s) To me, it looks like too much code in defining the encrypt map. But I do not know how. -- Shannon -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.