commit 69ac4b06f3c13b82217887274250c917c6c4a41e
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Fri, 2 Dec 2022 00:18:11 -0500
First day
Diffstat:
A | LICENSE | | | 15 | +++++++++++++++ |
A | README.md | | | 9 | +++++++++ |
A | day1.clj | | | 98 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 122 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+Copyright 2022 Jake Bauer <jbauer@paritybit.ca>
+
+Permission to use, copy, modify, and/or distribute this software for any purpose
+with or without fee is hereby granted, provided that the above copyright notice
+and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
diff --git a/README.md b/README.md
@@ -0,0 +1,9 @@
+# Clojurecember
+
+In which I attempt to learn at least a little bit of Clojure, even if it's just
+about one standard library data structure, each day of December.
+
+## DEC01
+
+Installed Clojure and followed the [Clojure Syntax Learning
+Guide](https://www.clojure.org/guides/learn/syntax).
diff --git a/day1.clj b/day1.clj
@@ -0,0 +1,98 @@
+; LITERALS
+
+; Numeric Types
+42 ; integer
+-1.5 ; floating point
+22/7 ; ratio
+
+; Character Types
+"hello" ; string
+\e ; character
+#"[0-9]+" ; regular expression
+
+; Symbols and Idents
+map ; symbol
++ ; symbol - most punctuation allowed
+clojure.core/+ ; namespaced symbol
+nil ; null value
+true false ; booleans
+:alpha ; keyword
+:release/alpha ; keyword with namespace
+
+; Literal Collections
+'(1 2 3) ; list
+[1 2 3] ; vector
+#{1 2 3} ; set
+{:a 1, :b 2} ; map
+
+; EVALUATION
+
+; Source code is read as characters by the Reader either from .clj files or
+; interactively via the REPL.
+
+; The unit of source code is a Clojure expression, not a Clojure source file.
+; Clojure source files are read as a series of expressions as if they had been
+; typed manually at the REPL.
+
+; Clojure is run on the JVM, and the compiler compiles the output from the
+; Reader into bytecode that can be executed on the JVM.
+
+; INTERACTIVITY
+
+; The REPL has the following parts:
+; 1. Read an expression (a string of characters) to produce Clojure data.
+; 2. Evaluate the data returned from #1 to yield a result (also Clojure data).
+; 3. Print the result by converting it from data back to characters.
+; 4. Loop back to the beginning.
+
+'(1 2 3) ; Just a list of values, not code to evaluate
+(1 2 3) ; Will throw an error because trying to evaluate data as code
+
+*1, *2, *3 ; Special symbols: the result of the nth previous evaluation
+
+(require '[clojure.repl :refer :all]) ; Provides a number of special functions
+
+(doc +) ; Displays documentation for a function
+(apropos "+") ; Find functions that match a particular string or regex
+(find-doc "word") ; Like apropos but also searches docstrings
+(dir clojure.repl) ; See full listing of functions in given namespace
+(source demunge) ; View source code for the given function
+
+(def x 7) ; Setting definind x to 7 in the current namespace
+(+ x x) ; Using the above-defined variable, result will be 14
+
+; Printing
+
+(println "hi") ; Human readable printout with newline
+(print "hi") ; Human readable printout without newline
+(prn "hi") ; Printed as data that can read by the Reader with newline
+(pr "hi") ; Printed as data that can read by the Reader without newline
+
+; TEST YOUR KNOWLEDGE
+
+; 1. Using the REPL, compute the sum of 7654 and 1234.
+
+(+ 7654 1234)
+
+; 2. Rewrite the following algebraic expression as a Clojure expression:
+; ( 7 + 3 * 4 + 5 ) / 10.
+
+(/ (+ 7 (* 3 4) 5) 10)
+
+; 3. Using REPL documentation functions, find the documentation for the rem and
+; mod functions. Compare the results of the provided expressions based on the
+; documentation.
+
+(doc rem)
+(doc mod)
+
+; These are subtly different in that they behave differently when the numerator
+; and divisor are of different signs.
+; https://www.nickivance.com/writing/20181129_remainders/index.html
+; https://math.stackexchange.com/questions/2179579/how-can-i-find-a-mod-with-negative-number
+
+; 4. Using find-doc, find the function that prints the stack trace of the most recent REPL exception.
+
+(find-doc "trace")
+
+; Answer is clojure.repl/pst