### Running Local MkDocs Server (Full Build) Source: https://github.com/practicalli/learn-clojure/blob/main/README.md This command initiates a full build of the documentation site and starts a local development server, typically accessible at `http://localhost:8000`. It's used for initial setup or when significant changes require a complete rebuild. ```shell make docs ``` -------------------------------- ### Installing Practicalli MkDocs Plugins with pip3 Source: https://github.com/practicalli/learn-clojure/blob/main/README.md This command installs all necessary MkDocs plugins and their dependencies, including `pillow` and `cairosvg` for social card generation, required for the Practicalli documentation site. These plugins are also part of the GitHub Actions workflow. ```shell pip3 install mkdocs-material mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects pillow cairosvg ``` -------------------------------- ### Installing MkDocs Material v9 using pip Source: https://github.com/practicalli/learn-clojure/blob/main/README.md This command installs a specific version (9.x) of the `mkdocs-material` theme using the Python `pip` package manager. It ensures compatibility with the project's documentation build system. ```shell pip install mkdocs-material=="9.*" ``` -------------------------------- ### Managing Service Lifecycle with Clojure Rich Comments Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/repl-workflow.md This snippet demonstrates using a Clojure rich comment block to manage the lifecycle of a service. It includes examples of starting, stopping, and restarting the application server, as well as accessing system environment variables and properties, providing interactive examples for development. ```Clojure (ns practicalli.gameboard.service) (defn app-server-start [port] ,,,) (defn app-server-start [] ,,,) (defn app-server-restart [] ,,,) (defn -main "Start the service using system components" [& options] ,,,) (comment (-main) (app-server-start 8888) (app-server-stop) (app-server-restart 8888) (System/getenv "PORT") (def environment (System/getenv)) (def system-properties (System/getProperties)) ) ; End of rich comment block ``` -------------------------------- ### Loading Text Data from Local Files in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/example-hitchhikers-guide.md This snippet shows how to load the book text and common English words from local files instead of online URLs. It uses the `slurp` function to read the entire file content into memory, demonstrating an alternative for offline processing or when dealing with local resources. ```Clojure (def book (slurp "./hhgttg.txt")) (def common-english-words (-> (slurp "common-english-words.txt") (clojure.string/split #",") set)) ``` -------------------------------- ### Starting Clojure REPL via Terminal UI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/index.md This command starts a Clojure REPL using the `rebel-readline` library, providing an interactive terminal user interface for development and testing within an Exercism project. It's typically run from the root of the project. ```shell clojure -M:repl/rebel ``` -------------------------------- ### Clojure Function Code Block with Line Numbers and Title Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md This example demonstrates a Clojure function code block configured with line numbers starting from 42 and a title indicating its source file. It defines a basic function. ```clojure (defn my-function "With a lovely doc-string" [arguments] (map inc [1 2 3])) ``` -------------------------------- ### Cloning a Forked GitHub Repository Source: https://github.com/practicalli/learn-clojure/blob/main/README.md This command clones a forked GitHub repository to the local machine, replacing `` and `` with the actual account and repository names. This is the first step in setting up the local development environment after forking. ```shell git clone https://github.com//.git ``` -------------------------------- ### Example Nucleotide Count Map (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md Presents an example of the expected output format for nucleotide counts: a map where keys are nucleotides and values are their respective counts. This illustrates the desired structure for a frequency analysis result. ```Clojure {\A 20, \T 21, \G 17, \C 12} ``` -------------------------------- ### Adding Numbers with Clojure's `+` Function Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md Demonstrates basic arithmetic using the `+` function in Clojure. This example shows how to sum multiple numeric arguments, illustrating fundamental function calling with prefix notation. ```Clojure (+ 1 2 3 4 5) ``` -------------------------------- ### Starting a Rebel REPL for Clojure CLI Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md This command launches a 'rebel' REPL (Read-Eval-Print Loop) for the current Clojure project. The `repl/rebel` alias provides an enhanced interactive development environment for Clojure CLI projects. ```bash clojure -M:repl/rebel ``` -------------------------------- ### Creating ClojureScript Project with Leiningen Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/create-project.md This command initializes a new ClojureScript project named 'clojurebridge-landing-page' using the `figwheel-main` template. The `--reagent` flag includes the Reagent library, setting up a single-page application. It requires Leiningen to be installed. ```Shell lein new figwheel-main clojurebridge-landing-page -- --reagent ``` -------------------------------- ### Creating Mermaid Flow Diagrams Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Example of a simple flow diagram defined using Mermaid syntax, demonstrating basic nodes and directional connections. This allows for visual representation of processes or workflows directly within the documentation. ```mermaid graph LR A[Start] --> B{Error?}; B -->|Yes| C[Hmm...]; C --> D[Debug]; D --> B; B ---->|No| E[Yay!]; ``` -------------------------------- ### Analyzing Word Frequencies from Online Sources in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/example-hitchhikers-guide.md This snippet defines functions to fetch a book and common English words from online URLs, then processes the book text to find the most frequent words, excluding common ones. It uses Clojure's threading macro (`->>`) to chain operations like regex matching, lowercasing, filtering, frequency calculation, and sorting. ```Clojure (def book (slurp "http://clearwhitelight.org/hitch/hhgttg.txt")) (def common-english-words (-> (slurp "https://www.textfixer.com/tutorials/common-english-words.txt") (clojure.string/split #",") set)) ;; using a function to pull in any book (defn get-book [book-url] (slurp book-url)) (defn -main [book-url] (->> (get-book book-url) (re-seq #"[a-zA-Z0-9|']+") (map #(clojure.string/lower-case %)) (remove common-english-words) frequencies (sort-by val) reverse)) ;; Call the program (-main "http://clearwhitelight.org/hitch/hhgttg.txt") ``` -------------------------------- ### Deconstructing Clojure Threading Macro with REPL Commenting Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/example-hitchhikers-guide.md This snippet demonstrates how to deconstruct a threading macro (`->>`) in the Clojure REPL by commenting out individual expressions using `#_`. This allows developers to inspect the intermediate results of each step in the pipeline, aiding in debugging and understanding the flow of data. ```Clojure (defn -main [book-url] (->> (get-book book-url) #_(re-seq #"[a-zA-Z0-9|']+") #_(map #(clojure.string/lower-case %)) #_(remove common-english-words) #_frequencies #_(sort-by val) #_reverse)) ``` -------------------------------- ### Annotating GitHub Actions Workflow Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Shows how to use multiple annotations in a YAML-based GitHub Actions workflow, highlighting specific lines like the workflow name, branch names, and installation steps. This provides detailed explanations for different parts of the CI/CD configuration. ```yaml name: ci # (1)! on: push: branches: - master # (2)! - main permissions: contents: write jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: 3.x - run: pip install mkdocs-material # (3)! - run: mkdocs gh-deploy --force ``` -------------------------------- ### Nucleotide Count Shell Examples Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md Illustrates expected input and output for the Nucleotide Count problem, showing how a valid DNA sequence is processed and how an invalid sequence results in an error. ```Shell "GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2 "INVALID" -> error ``` -------------------------------- ### Running Local MkDocs Server (Incremental Build) Source: https://github.com/practicalli/learn-clojure/blob/main/README.md This command performs an incremental build of the documentation, rebuilding only the content that has changed. It's designed to speed up the local development process for minor modifications, though navigation changes might require a full `make docs` rebuild. ```shell make docs-changed ``` -------------------------------- ### Example of Splitting a String with `clojure.string/split` Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/celebrity-name-smash.md This example demonstrates the use of `clojure.string/split` to divide a string into a sequence of substrings based on a regular expression pattern. Here, it splits the string by space characters, returning a vector of words. ```Clojure (clojure.string/split "Clojure is awesome!" #" ") ;; => ["Clojure" "is" "awesome!"] ``` -------------------------------- ### Running Leiningen REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Command to start a terminal REPL (Read-Eval-Print Loop) using Leiningen. This snippet is nested within an admonition and content tab structure, providing a quick way to launch an interactive Clojure session. ```shell lein repl ``` -------------------------------- ### Starting Rebel Readline REPL via Clojure CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/clojure-repl/index.md This command launches the Rebel Readline REPL, which provides a rich interactive experience with features like syntax highlighting and function signatures. It uses the `:repl/rebel` alias from Practicalli Clojure CLI Config for convenient access. ```shell clojure -M:repl/rebel ``` -------------------------------- ### Example of a Clojure Hash Map Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clacks-messages.md This snippet provides a general example of a hash map in Clojure. It illustrates the common practice of using Clojure keywords (prefixed with `:`) as keys to easily look up associated values, serving as an introduction to the map data structure before applying it to the Clacks alphabet. ```Clojure {:name "john" :age "21" :twitter "jr0cket"} ``` -------------------------------- ### Building ClojureScript Project from Command Line Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/run-the-project.md These commands initiate the build process for the ClojureScript project using either Leiningen or the Clojure CLI tools. Both commands leverage Figwheel Main to compile source files and start a development server, enabling live reloading during development. ```Shell lein fig:build ``` ```Shell clojure -A:fig:build ``` -------------------------------- ### Simple Infix vs. Prefix Notation Example in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/maths.md A straightforward comparison of a simple arithmetic expression in infix notation versus Clojure's prefix notation. This example emphasizes how prefix notation makes operator precedence explicit, removing ambiguity and the need to recall operator hierarchy. ```Clojure Infix: 1 + 2 / 3 Prefix: (+ 1 (/ 2 3)) ``` -------------------------------- ### Running Clojure CLI REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Command to start a terminal REPL (Read-Eval-Print Loop) using Clojure CLI. This snippet is nested within an admonition and content tab structure, providing a quick way to launch an interactive Clojure session. ```shell clojure -T:repl/rebel ``` -------------------------------- ### Creating Buttons with FontAwesome Icons - Markdown Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md This Markdown example demonstrates how to create buttons that include FontAwesome icons. By prefixing the link text with an icon shortcode (e.g., `:fontawesome-brands-github:`), and applying the `.md-button` and `.md-button-primary` classes, visually rich buttons are generated. ```markdown [:fontawesome-brands-github: Practicalli Issues](http://practical.li/blog){ .md-button .md-button-primary } [:fontawesome-solid-book-open: Practicalli Books and Blogs](http://practical.li/blog){ .md-button .md-button-primary } [:simple-clojure: Clojure.org](http://clojure.org/){ .md-button .md-button-primary } ``` -------------------------------- ### Starting Rebel REPL for Clojure Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/small-projects/random-clojure-function.md This command initiates a Rebel REPL, providing a rich terminal UI for interactive Clojure development. It should be run from the root directory of the Clojure project, where the `deps.edn` file is located. ```Shell clojure -M:repl/reloaded ``` -------------------------------- ### Calling Character to Clack Conversion (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clacks-messages.md Shows an example call to the `character->clack` function with the input 'a', demonstrating its usage and expected output for a known character. ```Clojure (character->clack "a") ;; => [0 1 0 0 0 1] ``` -------------------------------- ### Embedding Remote File Content via URL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Illustrates embedding content from a remote file specified by a URL using the `--8<--` syntax. This is particularly useful for sharing and synchronizing code examples or configuration files across multiple documentation projects or books. ```markdown --8<-- "https://raw.githubusercontent.com/practicalli/project-templates/main/.dir-locals.el" ``` -------------------------------- ### Using `subs` for Substring Extraction in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/celebrity-name-smash.md This snippet introduces the more concise `subs` function for extracting substrings. It shows how `subs` can take a start and optional end index to get a segment, or just a start index to get the remainder of the string. It also demonstrates its use with calculated midpoints. ```Clojure (subs "Brad" 0 2) ;; => "Br" (subs "Brad" 2) ;; => "ad" (subs "Bradley" 0 (/ (count "Bradley") 2)) ;; => "Bra" ``` -------------------------------- ### Setting up Clojure CLI Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Provides the shell command for creating a new Clojure application project using the Clojure CLI tool. This snippet is part of a content tab, offering an alternative to Leiningen for project initialization. ```shell clojure -T:project/new :template app :name practicalli/gameboard ``` -------------------------------- ### Defining a Random Last Half Subname Function in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/celebrity-name-smash.md This function, `last-celeb-subname`, is designed to extract a random substring from the latter part of a name. It calculates a random starting point using `rand-int` and `inc`, then uses `subs` with only the start index to get the remainder of the string. ```Clojure (defn last-celeb-subname [name] (let [start (inc (rand-int (count name)))] (subs name start))) ``` -------------------------------- ### Setting Image Size in Markdown with MkDocs Material Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Demonstrates how to specify the height and width of an image in Markdown using inline CSS styles within curly braces. This example also includes a theme-specific tag for dark mode. ```Markdown ![Kitty Logo](https://raw.githubusercontent.com/practicalli/graphic-design/live/icons/kitty-light.png#only-dark){style="height:150px;width:150px"} ``` -------------------------------- ### Creating ClojureScript Project with Clojure CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/create-project.md This command creates a new ClojureScript project named 'clojurebridge-landing-page' using the `figwheel-main` template via `clj-new`. The `--reagent` flag integrates the Reagent library, configuring it as a single-page application. It requires Clojure CLI tools and `clj-new` to be installed. ```Shell clj -A:new figwheel-main clojurebridge-landing-page -- --reagent ``` -------------------------------- ### Setting up Leiningen Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Provides the shell command for creating a new Clojure application project using the Leiningen build tool. This snippet is part of a content tab, offering an alternative to Clojure CLI for project initialization. ```shell lein new app practicalli/gameboard ``` -------------------------------- ### Creating Mermaid Entity Relationship Diagrams Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Example of a Mermaid ER diagram, defining entities and their relationships, useful for data modeling and visualizing database schemas. This helps in understanding the structure and connections within a data system. ```mermaid erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains LINE-ITEM { customer-name string unit-price int } CUSTOMER }|..|{ DELIVERY-ADDRESS : uses ``` -------------------------------- ### Initial Nucleotide Count Function Definitions (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md Initial Clojure function definitions for `count-of-nucleotide-in-strand` and `nucleotide-counts`, providing the required argument signatures to allow unit tests to compile. These are starting points before implementing the actual logic. ```Clojure (ns nucleotide-count) (defn count-of-nucleotide-in-strand "Count how many of a given nucleotide is in a strand" [nucleotide strand]) (defn nucleotide-counts "Count all nucleotide in a strand" [strand]) ``` -------------------------------- ### Simulating map with conj and inc (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md This example illustrates a manual way to achieve a similar result to `map inc` by using `conj` to conjoin incremented values into a new empty vector. It shows the underlying operation of building a new sequence element by element. ```Clojure (conj [] (inc 1) (inc 2) (inc 3) (inc 4) (inc 5)) ``` -------------------------------- ### Initial Copy of Static Assets to Docs Directory Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/github-pages-deploy.md Copies the main HTML file, CSS, images, and the initial compiled JavaScript output from the `resources/public` directory into the `/docs` directory, preparing the static site for GitHub Pages. ```shell cp resources/public/index.html docs cp -r resources/public/css docs cp -r resources/public/images images cp resources/public/cljs-out/dev-main.js docs/cljs-out/ ``` -------------------------------- ### Creating a New Clojure Project for Advent of Code (Bash) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/advent-of-code.md This command initializes a new Clojure project using the `clojure` CLI tool. It leverages the `:project/create` task with a `lib` template to set up a project named `practicalli.advent-of-clojure-code/2019`, suitable for organizing daily Advent of Code solutions. ```Bash clojure -T:project/create :template lib practicalli.advent-of-clojure-code/2019 ``` -------------------------------- ### Composing Strings with Clojure Lists and Expressions Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md Illustrates how lists, primarily used for function calls, can also be part of string composition using `str`. This example combines literal strings, a numeric calculation, and a keyword within a string. ```Clojure (str "lists used mainly " (* 2 2) " " :code) ``` -------------------------------- ### Implicit End-of-String Matching with re-matches in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/bob/bob-regular-expression-approach.md This example highlights that `re-matches` implicitly attempts to match the entire input string against the pattern. Therefore, for a full string match, the `$` anchor is often not explicitly required when using `re-matches`, as it behaves as if the pattern is anchored to the start and end of the string. ```Clojure (re-matches #".*\\?" "Okay if like my ? spacebar quite a bit") ``` -------------------------------- ### Creating a Clojure Project with Clojure CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md This command initializes a new Clojure project named `practicalli/tictactoe-cli` using the `clj-new` alias, which is part of the Clojure CLI tools. It sets up the basic project structure for a new application. ```bash clojure -M:new practicalli/tictactoe-cli ``` -------------------------------- ### Creating a New Clojure Project with Clojure CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/codewars/index.md This command initializes a new Clojure library project using the Clojure CLI tool. It creates a project named 'practicalli/readability-is-king', which can be used to organize solutions for CodeWars challenges. This is a prerequisite for copying source and test code into a local project. ```Bash clojure -M:new lib practicalli/readability-is-king ``` -------------------------------- ### Starting a Rich Terminal UI Clojure REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/code-kata/recent-song-list.md This command launches a rich terminal UI Clojure REPL using the `rebel-readline` library. It provides an interactive environment for evaluating Clojure code and interacting with the application, enhancing the development experience. ```shell clojure -M:repl/rebel ``` -------------------------------- ### Starting a Rich Terminal UI Clojure REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-kata/recent-song-list.md This command launches a rich terminal UI Clojure REPL using the `:repl/rebel` alias. It provides an interactive environment for evaluating Clojure code and interacting with the application, offering enhanced features over a standard REPL. ```shell clojure -M:repl/rebel ``` -------------------------------- ### Incomplete Length Function Example in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/recursion.md This snippet provides an incomplete definition of a `length` function that attempts to call an undefined function `kk`. It serves as an example of a function signature but is not functional as written. ```Clojure (defn length [collection] (kk)) ``` -------------------------------- ### Creating a New Clojure Project with Leiningen Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/study-guide-schedule.md This command initializes a new Clojure project using Leiningen, a build automation tool for Clojure. It sets up the basic project structure, including separate directories for source code and test files, facilitating a Test Driven Development (TDD) workflow. ```shell lein new my-project ``` -------------------------------- ### Configuring ClojureScript Deploy Output Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/deploy-build.md This snippet shows the `deploy.cljs.edn` configuration for a ClojureScript project. It specifies the main entry point (`clojurebridge-landing-page.core`) and sets the `output-to` path to `docs/cljs-out/dev-main.js`, which is crucial for deploying the compiled JavaScript file directly to the `/docs` directory, commonly used by GitHub Pages. ```ClojureScript ^{:watch-dirs ["test" "src"] :css-dirs ["resources/public/css"] :auto-testing true} {:main clojurebridge-landing-page.core :output-to "docs/cljs-out/dev-main.js"} ``` -------------------------------- ### Getting Current LocalDate in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/date-time.md This snippet shows how to get the current date using `java.time.LocalDate/now` in Clojure. It returns a `java.time.LocalDate` object representing the current date without time information. The `java.time` namespace is available by default. ```Clojure (java.time.LocalDate/now) ``` -------------------------------- ### Creating a New Clojure Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/code-kata/recent-song-list.md This command uses `clj-new` to scaffold a new Clojure project named `practicalli/song-list`. It sets up the basic directory structure and configuration files for a Clojure application, preparing it for development. ```bash clojure -T:project/create practicalli/song-list ``` -------------------------------- ### Iterating and Incrementing with map and range (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md This example uses `map` to apply the `inc` function to each number generated by `(range 20)`. `range` creates a sequence of numbers from 0 up to (but not including) 20. `map` then increments each of these numbers, returning a new sequence of incremented values. ```Clojure (map inc (range 20)) ``` -------------------------------- ### Clojure deps.edn Alias for Rebel-Readline REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/projects.md This `deps.edn` alias configuration defines a `:repl/rebel` entry, enabling an enhanced REPL environment with Rebel-Readline and CIDER integration. It specifies necessary `:extra-deps` for `nrepl`, `cider-nrepl`, and `com.bhauman/rebel-readline`, and configures `:main-opts` to launch `nrepl.cmdline` with CIDER middleware and `rebel-readline.main` for an interactive session. ```clojure :repl/rebel {:extra-deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.31.0"} com.bhauman/rebel-readline {:mvn/version "0.1.4"}} :main-opts ["-e" "(apply require clojure.main/repl-requires)" "--main" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]" "--interactive" "-f" "rebel-readline.main/-main"]} ``` -------------------------------- ### Creating a New Clojure Project Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-kata/recent-song-list.md This command uses `clj-new` to generate a new Clojure project structure. It initializes a project named `practicalli/song-list` in the current directory, setting up the necessary files and directories for development. ```bash clojure -T:project/create practicalli/song-list ``` -------------------------------- ### Tracing Recursive Length Calculation and Range Example in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/recursion.md This snippet illustrates the step-by-step evaluation of the recursive `length` function for a collection, showing how the base case is reached and values accumulate. It also includes an example of calculating the length of a larger collection generated by `range`. ```Clojure (+ 1 (length [1 2])) (+ 1 (+ 1 (length [2]))) (+ 1 (+ 1 (+ 1 (length [])))) (+ 1 (+ 1 (+ 1 0))) (length (range 24)) ;; => 24 ``` -------------------------------- ### Example Clojure Hash Map Source: https://github.com/practicalli/learn-clojure/blob/main/docs/small-projects/encode-decode/clacks.md This Clojure hash map illustrates a general example of how data can be structured using key-value pairs. It uses keywords as keys and string values to describe a person, demonstrating the concept of self-describing data, which is foundational for the Clacks alphabet design. ```clojure {:name "Jenny Jetpack" :age "21" :twitter "jenjetpack"} ``` -------------------------------- ### RNA Transcription with Eager Error Throwing using `get` in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/rna-transcription.md This `to-rna` function attempts to transcribe DNA to RNA. It uses `get` with `throw` as the not-found value, but this approach eagerly evaluates the `throw` expression, causing the function to always fail regardless of input validity. ```Clojure (defn to-rna [dna] (clojure.string/join (map (fn [nucleotide ](get {\G \C \C \G \T \A \A \U} nucleotide (throw (AssertionError. "Unknown nucleotide")) )) dna))) ``` -------------------------------- ### Displaying Browser Alert using JavaScript Interop in ClojureScript Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md This example illustrates ClojureScript's ability to interact with its JavaScript host environment. It calls the `js/alert` function, which is a standard browser JavaScript function, to display a pop-up alert, highlighting direct access to JavaScript APIs. ```ClojureScript (js/alert "I am a pop-up alert") ``` -------------------------------- ### Highlighting Specific Lines in Clojure Code Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Demonstrates how to highlight multiple lines in a Clojure code block using the `hl_lines` metadata, making specific parts of the code stand out. This feature is useful for drawing attention to critical sections or changes within a code example. ```clojure (defn my-function "With a lovely doc-string" [arguments] (map inc [1 2 3])) ``` -------------------------------- ### Accessing Application State with `get` in Hiccup (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/hiccup-for-html.md This Clojure snippet shows how to dynamically access values from an `app-state` atom within Hiccup. It uses the `get` function to retrieve the value associated with the `:text` key from the de-referenced atom (`@app-state`), embedding it as the content of an `

` tag. ```Clojure [:h1 (get @app-state :text)] ``` -------------------------------- ### Creating a Clojure Project with Practicalli CLI Config Source: https://github.com/practicalli/learn-clojure/blob/main/docs/clojure-repl/index.md This command utilizes the `:project/create` alias from Practicalli Clojure CLI Config to generate a new Clojure project structure. It requires specifying a project name in the format `github-name/project-name` to properly initialize the project directory. ```shell clojure -T:project/create :name github-name/project-name ``` -------------------------------- ### Calling Clack to Character and Sequence to String Conversion (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clacks-messages.md Provides examples of calling `declacksify` for a single clack code and `clacks->string` for a sequence of clack codes, demonstrating the reverse conversion process from clacks back to human-readable characters/words. ```Clojure (declacksify [1 0 0 1 1 1]) ;; => "t" (clacks->string [[0 0 1 0 1 0] [0 1 0 0 0 1] [1 0 0 1 1 1]]) ;; => ("b" "a" "t") ``` -------------------------------- ### Example of a Polymorphic Clojure Function with Calls Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/polymorphism.md This example defines a polymorphic function `i-am-polly` that demonstrates different behaviors based on its arity. When called without arguments, it provides a default message; when called with a string argument, it returns that custom message. The snippet also includes calls to showcase both behaviors. ```Clojure (defn i-am-polly ([] (i-am-polly "My name is polly")) ([message] (str message))) (i-am-polly) (i-am-polly "I call different behaviour depending on arguments sent") ``` -------------------------------- ### Creating a Clojure Project with Leiningen Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md This Leiningen command creates a new Clojure project named `tictactoe-cli` using the default Leiningen template. It sets up the standard project structure, including a `project.clj` file and source directories. ```bash lein new tictactoe-cli ``` -------------------------------- ### Creating Clojure Project with CLI Template Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/projects.md This shell command utilizes the Clojure CLI's `-T` option to execute the `:project/create` alias. This alias, typically powered by the `deps-new` tool, facilitates the creation of a new Clojure project from a predefined template, streamlining project setup. The command can be extended with `:name` to specify the project's name. ```shell clojure -T:project/create ``` -------------------------------- ### Creating a Clojure Project with deps-new (Bash) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/code-kata/salary-slip-generator.md This bash command utilizes the Clojure CLI with the `:project/create` alias to scaffold a new Clojure project. It specifies 'app' as the template and 'practicalli/salary-calculator' as the project name, setting up the initial directory structure for the salary slip kata. ```bash clojure -T:project/create :template app :name practicalli/salary-calculator ``` -------------------------------- ### Careful Metadata Attachment in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/clojure-design/idioms.md Highlights the importance of understanding where metadata is attached (to the var or the value) and its implications, providing examples to clarify the difference. ```Clojure ;; we attach the metadata to the var referenced by `a` (def ^:private a {}) (meta a) ;=> nil (meta #'a) ;=> {:private true} ;; we attach the metadata to the empty hash-map value (def a ^:private {}) (meta a) ;=> {:private true} (meta #'a) ;=> nil ``` -------------------------------- ### Cloning a Git Repository Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md This Git command clones the `tictactoe-cli` project repository from GitHub to the local machine. It downloads all project files and the complete version history, providing an alternative to creating a new project from scratch. ```bash git clone https://github.com/practicalli/tictactoe-cli.git ``` -------------------------------- ### Downloading Clojure Exercise with Exercism CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/index.md This command uses the Exercism CLI to download a specific Clojure exercise. It requires the exercise name and specifies the 'clojure' track. This sets up a local Clojure project with the challenge code and a test runner. ```bash exercism download --exercise=exercise-name --track=clojure ``` -------------------------------- ### Example: Calculating Length of Empty Collection in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/recursion.md This snippet demonstrates calling the `length` function with an empty collection, which correctly returns 0, illustrating the base case of the recursive function. ```Clojure (length []) ;; => 0 ``` -------------------------------- ### Creating a New Clojure Project with deps-new Source: https://github.com/practicalli/learn-clojure/blob/main/docs/small-projects/mutating-state/mutants-assemble.md This command uses the `clojure` CLI with the `:project/create` alias and `deps-new` template to initialize a new Clojure application project named `practicalli/mutants-assemble`. It sets up the basic project structure. ```bash clojure -T:project/create :template app :name practicalli/mutants-assemble ``` -------------------------------- ### Filtering Nucleotides (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md An example using `filter` in Clojure to select only the occurrences of a specific nucleotide (Adenine in this case) from a sequence of valid nucleotides, providing a more elegant way to isolate matches. ```Clojure (filter #(= % \A) valid-nucleotides)) ``` -------------------------------- ### Example: Calculating Length of Non-Empty Collection in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/recursion.md This snippet shows the `length` function being called with a collection containing three elements, resulting in the correct length of 3, demonstrating the recursive step. ```Clojure (length [0 1 2]) ;; => 3 ``` -------------------------------- ### Creating a Clojure Project with deps-new Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-kata/salary-slip-generator.md This snippet demonstrates how to use the `clojure` CLI with the `:project/create` alias to generate a new Clojure application project. It specifies `app` as the template and `practicalli/salary-calculator` as the project name, setting up the initial project structure for the salary slip kata. ```bash clojure -T:project/create :template app :name practicalli/salary-calculator ``` -------------------------------- ### Configuring Clojure Project Metadata in project.clj Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md This Clojure code defines the project configuration within a `project.clj` file, commonly used by Leiningen. It specifies the project name, version, description, GitHub URL, and updates the license to Creative Commons Attribution Share-Alike 4.0 International, while also setting the Clojure dependency to version 1.10.0. ```clojure (defproject tictactoe-cli "0.1.0-SNAPSHOT" :description "TicTacToe game played on the command line" :url "https://github.com/practicalli/tictactoe-cli" :license {:name "Creative Commons Attribution Share-Alike 4.0 International" :url "https://creativecommons.org"} :dependencies [[org.clojure/clojure "1.10.0"]]) ``` -------------------------------- ### Counting Nucleotides with Map (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md Demonstrates how to get the total count of a specific nucleotide by applying `count` to the result of mapping the DNA strand, where each matching nucleotide is represented by 1 and non-matching by 0. ```Clojure (count (map #(if (= % \A) 1 0) "GGGGGTAACCCGG")) ``` -------------------------------- ### Creating Mermaid State Transition Diagrams Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Demonstrates a Mermaid state diagram with forks and joins, representing state transitions and concurrent paths. This visualizes the different states an object or system can be in and how it moves between them. ```mermaid stateDiagram-v2 state fork_state <> [*] --> fork_state fork_state --> State2 fork_state --> State3 state join_state <> State2 --> join_state State3 --> join_state join_state --> State4 State4 --> [*] ``` -------------------------------- ### Converting a Word Example in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/small-projects/encode-decode/clacks.md This snippet demonstrates calling the `string->clacks` function with the word 'bat' to convert it into its corresponding sequence of Clacks codes. It shows how the previously defined functions are used for word conversion. ```Clojure (string->clacks "bat") ``` -------------------------------- ### Multiple Bindings with `let` (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/name-association.md This example illustrates how to define multiple local bindings within a single `let` form. It calculates `discount` and then uses it to compute `discounted-amount`, demonstrating sequential binding where subsequent bindings can refer to previously defined ones within the same `let` scope. Parameters are `amount`, `discount-percent`, and `min-charge`. ```Clojure (defn compute-discount-amount [amount discount-percent min-charge] (let [discount (* amount discount-percent) discounted-amount (- amount discount)] (if (> discounted-amount min-charge) discounted-amount min-charge))) ``` -------------------------------- ### Loading Project and Changing Namespace in Clojure REPL Source: https://github.com/practicalli/learn-clojure/blob/main/docs/games/tictactoe-cli/create-project.md These Clojure commands are executed within a running REPL. The `require` function loads the main namespace of the `practicalli/tictactoe-cli` project, and `in-ns` then switches the current REPL namespace to `practicalli/tictactoe-cli`, allowing direct interaction with the project's code. ```clojure (require 'practicalli/tictactoe-cli) (in-ns 'practicalli/tictactoe-cli) ``` -------------------------------- ### Example Usage of Initial to-rna Function Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/rna-transcription.md This snippet demonstrates calling the `to-rna` function with the DNA strand 'GCTA'. It shows the expected output as a sequence of characters, `(\C \G \A \U)`. ```clojure (to-rna "GCTA") ``` -------------------------------- ### Mapping Nucleotides for Counting (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md An example of using `map` in Clojure to transform a DNA strand into a sequence of 0s and 1s, where 1 indicates a match for a specific nucleotide (Adenine in this case) and 0 indicates no match. ```Clojure (map #(if (= % \A) 1 0) "GGGGGTAACCCGG") ``` -------------------------------- ### Downloading RNA Transcription Exercise with Exercism CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/rna-transcription.md This command uses the Exercism CLI tool to download the 'rna-transcription' exercise for the Clojure track. It's the initial step to set up the project locally. ```bash exercism download --exercise=rna-transcription --track=clojure ``` -------------------------------- ### Nested Mapping for Multiple Collections in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/list-comprehension.md Provides an example of how to achieve the same multi-collection combination using nested `map` and `mapcat` functions. This demonstrates that while possible, the `for` function often leads to more concise and easier-to-reason-about code for such scenarios. ```Clojure (mapcat (fn [number] (map (fn [letter] (str number letter))))) ``` -------------------------------- ### Submitting Clojure Solution with Exercism CLI Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/index.md This command uses the Exercism CLI to submit a completed solution file to the Exercism website. The /path/to/src-file should point to the main source file containing the solution. Submission allows for test validation on the platform and mentor feedback. ```bash exercism submit /path/to/src-file ``` -------------------------------- ### Function to Count Nucleotide with Validation (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/nucleotide-count.md Defines a function `count-of-nucleotide-in-strand` that counts the occurrences of a given `nucleotide` in a `strand`. It includes validation using `some` against `valid-nucleotides` and throws an exception if the input nucleotide is invalid. An example call is also provided. ```Clojure (defn count-of-nucleotide-in-strand [nucleotide strand] (if (some #(= nucleotide %) valid-nucleotides) (count (filter #(= nucleotide %) strand)) (throw (Throwable.)))) (count-of-nucleotide-in-strand \T "GGGGGTAACCCGG") ``` -------------------------------- ### Combining All Image Attributes in Markdown Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Demonstrates how to apply multiple image attributes simultaneously, including alignment (`align=right`), lazy loading (`loading=lazy`), and custom sizing (`style="height:64px;width:64px"`), along with theme-specific display. ```Markdown ![Kitty Logo](https://raw.githubusercontent.com/practicalli/graphic-design/live/icons/kitty-light.png#only-dark){align=right loading=lazy style="height:64px;width:64px"} ``` ```Markdown ![Kitty Logo](https://raw.githubusercontent.com/practicalli/graphic-design/live/icons/kitty-dark.png#only-light){align=right loading=lazy style="height:64px;width:64px"} ``` -------------------------------- ### Basic HTML Structure Example Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/hiccup-for-html.md This snippet shows a standard HTML structure using `div`, `h1`, and `h3` tags. It demonstrates how traditional HTML uses opening and closing tags to define the scope of elements. ```HTML

Hello World

Live reloading in the repl makes web development fun!

``` -------------------------------- ### Implementing Collapsing Admonitions - Markdown Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md These Markdown snippets illustrate how to create collapsing admonitions using the `???` syntax. This allows content to be hidden by default and expanded on click, with options for a title and for being expanded by default using `???+`. ```markdown ??? NOTE ??? NOTE "Replace with a title" ???+ NOTE "Expanded by default" ``` -------------------------------- ### Getting Current Instant in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/first-steps/date-time.md This snippet demonstrates how to obtain the current instant in time using `java.time.Instant/now` in Clojure. An `Instant` represents a point in time on the timeline, typically used for timestamps. The `java.time` namespace is available by default. ```Clojure (java.time.Instant/now) ``` -------------------------------- ### Downloading Exercism Bob Challenge - Bash Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/bob/index.md This command downloads the 'bob' exercise from the 'clojure' track using the Exercism command-line interface (CLI) tool. It's the initial step to set up the project locally for development. ```bash exercism download --exercise=bob --track=clojure ``` -------------------------------- ### Defining Common English Words Set with Threading Macro in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/small-projects/data-transformation/most-common-word.md This example redefines the `common-english-words` set using the `->` (thread-first) macro. This improves readability by showing the sequential transformation of data: slurping the file, splitting the content, and then converting it to a set. ```Clojure (def common-english-words (-> (slurp "common-english-words.csv") (clojure.string/split #",") set)) ``` -------------------------------- ### Initializing Application State with Sponsor Details - Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/app-state-section.md This snippet defines and initializes a global application state `atom` named `app-state`. It includes a `:sponsors` key with nested maps for `:current` and `:past` sponsors, allowing dynamic updates to sponsor information without hardcoding. The `:current` map holds details like name, logo, website, and a message for the active sponsor. ```Clojure (defonce app-state (atom {:text "Hello world!" :sponsors {:current {:name "Functional Works" :logo "images/functional-works-logo.svg" :website "https://functional.works-hub.com/" :message "Breaking down the barriers to hiring the right software engineers, providing a platform to managing the whole process (written in ClojureScript)."} :past {:9 {,,,}}}})) ``` -------------------------------- ### Checking if a Collection is Empty (Clojure) Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/first-taste-of-clojure.md This example uses the `empty?` predicate function to check if a given collection is empty. It returns `true` if the collection contains no elements, and `false` otherwise. This is useful for conditional logic involving collection states. ```Clojure (empty? []) ``` -------------------------------- ### Creating a ClojureScript Web Project with Figwheel and Reagent Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/study-guide-schedule.md This Leiningen command generates a new ClojureScript project using the `figwheel` template, specifically configured with `reagent`. Figwheel provides live code reloading for instant feedback during web development, while Reagent offers a React.js-style framework for building user interfaces with ClojureScript. ```shell lein new figwheel simple-website -- --reagent ``` -------------------------------- ### Example Usage of Refactored to-rna Function Source: https://github.com/practicalli/learn-clojure/blob/main/docs/code-challenges/exercism/rna-transcription.md This snippet demonstrates calling the refactored `to-rna` function with the DNA strand 'GCTA'. It shows the expected output as a string, `"CGAU"`, confirming the change in return type. ```clojure (to-rna "GCTA") ``` -------------------------------- ### Building Minified ClojureScript for Deployment Source: https://github.com/practicalli/learn-clojure/blob/main/docs/additional-projects/clojurebridge-website/github-pages-deploy.md Executes `lein clean` to remove previous build artifacts, followed by `lein fig:min` to compile and minify the ClojureScript application into a single JavaScript file, optimized for production deployment. ```shell lein clean lein fig:min ``` -------------------------------- ### Representing Keyboard Key Sequences in Markdown Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Shows how to represent a sequence of keyboard key presses in Markdown using the Pymdown Extensions. Keys in a sequence are separated by a space. ```Markdown ++spc++ ++"g"++ ++"s"++ ``` -------------------------------- ### Demonstrating Arity Exception with Clojure Functions Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/partial-functions.md This example shows the consequence of calling a Clojure function, specifically the `sum` function, with an incorrect number of arguments. Attempting to call `sum` with only one argument, when it expects two, results in a `clojure.lang.ArityException`. ```Clojure (sum 1) ;; => clojure.lang.ArityException ;; => Wrong number of args (1) passed to: functional-concepts/sum ``` -------------------------------- ### Defining a Sum Function in Clojure Source: https://github.com/practicalli/learn-clojure/blob/main/docs/thinking-functionally/partial-functions.md This snippet defines a simple `sum` function that takes two numbers and returns their sum. It serves as a foundational example to illustrate how functions are defined and called in Clojure, and later, to demonstrate arity issues. ```Clojure (defn sum "Sum two numbers together" [number1 number2] (+ number1 number2)) (sum 1 2) ;; => 3 ``` -------------------------------- ### Enabling Lazy Loading for Images in Markdown Source: https://github.com/practicalli/learn-clojure/blob/main/docs/introduction/writing-tips.md Shows how to add the `loading=lazy` attribute to an image in Markdown, instructing the browser to defer loading of the image until it is near the viewport, improving page performance. ```Markdown ![Kitty Logo](https://raw.githubusercontent.com/practicalli/graphic-design/live/icons/kitty-light.png){loading=lazy} ```