└── README.org /README.org: -------------------------------------------------------------------------------- 1 | # -*- mode:org -*- 2 | #+STARTUP: indent showall 3 | 4 | Warning: These are just my personal working notes as I learn Clojure, 5 | coming from Racket. 6 | 7 | * Racket -> Clojure 8 | Given a Racket function, what's the clojure.core equivalent? 9 | 10 | Note: This only includes things with a different name or behavior. 11 | 12 | | Racket | Clojure | Comment | 13 | |--------------------------------+----------------------+----------------------------------------| 14 | | begin | do | | 15 | | print | prn | | 16 | | display | print | | 17 | | write | write | | 18 | | pretty-print | pprint | clojure.pprint | 19 | | curry | partial | | 20 | | curryr | N/A | | 21 | | negate | complement | | 22 | | andmap | every? | | 23 | | ormap | some | Returns 1st item not #t | 24 | | (length xs) | (count coll) | Note: list vs collection. | 25 | | count | N/A ? | | 26 | | append | concat | | 27 | | (take xs n) | (take n coll) | Note: args reversed | 28 | | takef | take-while | Note: args reversed | 29 | | hash | hash-map or {} | | 30 | | set | hash-set or #{} | | 31 | | vector | vector or [] | | 32 | | unless | when-not | | 33 | | #t or true | true | | 34 | | #f or false | false | | 35 | | format | format | ~s vs %s. See also: str | 36 | | for | doseq | for-effect iteration form | 37 | | for/list etc. | for | Note: specific vs. generic collections | 38 | | , | ~ | | 39 | | unquote | ~ | | 40 | | ,@ | ~@ | | 41 | | unquote-splicing | ~@ | | 42 | | partition | N/A | Clj partition different | 43 | | regexp pregexp | re-matches | Implicit ^ and $ | 44 | | regexp pregexp | re-find | No implicit ^ and $ | 45 | | regexp-match* | re-seq | | 46 | | regexp-replace* | replace | | 47 | | #rx"\\w" | #"\w" | Clj regexps ~= px (?) | 48 | | #px"\\w" | #"\w" | Note 2 vs. 1 backslashes | 49 | | string->symbol | symbol | | 50 | | symbol->string | str | | 51 | | #:keyword | :keyword | | 52 | | keyword->string | name or str | | 53 | | string->keyword | keyword | | 54 | | dict-values | vals | | 55 | | hash-values | vals | | 56 | | dict-keys | keys | | 57 | | hash-keys | keys | | 58 | | generics | protocols | approximately | 59 | | (define x (make-parameter 10)) | (def ^:dynamic x 10) | | 60 | | (parameterize ([x 42]) ___) | (binding [x 42] ___) | | 61 | 62 | * Clojure -> Racket 63 | See table above. 64 | 65 | Also some clojure.core functions are available in [[https://github.com/greghendershott/rackjure/][#lang rackjure]]: 66 | 67 | | Function | Comment | 68 | |-----------------+-------------------------------------------------------| 69 | | { k v ... ... } | Dictionary literal. | 70 | | (dict key) | Applicable dictionaries. | 71 | | (key dict) | Applicable dictionaries. | 72 | | ~> and ~>> | Threading macros. -> is contract combinator in Racket | 73 | | #(+ % 2) | #λ(+ % 2) -- #λ() b/c #() is array literal in Racket | 74 | | str | | 75 | | swap! | | 76 | | partial | | 77 | | | | 78 | 79 | 80 | NOTE: The following work with lists not collections. 81 | 82 | NOTE: Not yet pushed to public repo. 83 | 84 | | Function | Comment | 85 | |-----------------+-------------------------------------------------------| 86 | | partition | Clojure partition unlike Racket's | 87 | | (take<= xs n) | When < n avail, returns '() instead of erroring. | 88 | | juxt | | 89 | | every? | Alias for andmap | 90 | | some | ormap returns #t or #f. some returns first item or #f | 91 | | | | 92 | 93 | NOTE: Not yet pushed to public repo. 94 | 95 | | Function | Comment | 96 | |----------+---------| 97 | | get | | 98 | | get-in | | 99 | --------------------------------------------------------------------------------