### Namespace Setup for Live Examples Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-spec/functions/documentation.md Define a namespace and require `clojure.repl` and `clojure.spec.alpha` for live documentation examples. ```clojure (ns practicalli.clojure (:require [clojure.repl :as repl] [clojure.spec.alpha :as spec])) ``` -------------------------------- ### Donut System Configuration Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-startup.md Example of a system configuration for the Practicalli Gameboard Service using Donut, intended for starting the service with an environment profile. ```clojure ;; --------------------------------------------------------- ;; practicalli.gameboard ;; ;; TODO: Provide a meaningful description of the project ;; ;; Start the service using donut configuration and an environment profile. ;; --------------------------------------------------------- ``` -------------------------------- ### Install Conjure Tutorial Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/index.md Installs the Conjure interactive tutorial for Neovim. This is a quick way to get started with Clojure REPL development in Neovim. ```shell curl -fL conjure.fun/school | sh ``` -------------------------------- ### Hotload Libraries for Web Server and Page Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-reloaded.md This example demonstrates hotloading http-kit and hiccup libraries to create a simple web server and generate an HTML page. It shows how to define a welcome page, start the server, and then redefine the page to use a Hiccup template. ```clojure (comment ;; Require if not automatically loaded by the REPL tooling, ie. Rebel Readline #_(require '[clojure..deps.repl :refer [add-lib add-libs sync-deps]]) ;; hotload the libraries required for the server (add-libs '{http-kit/http-kit {:mvn/version "2.5.1"}}) (require '[org.httpkit.server :as app-server]) ;; Discover which http-kit functions are available (ns-publics (find-ns 'org.httpkit.server)) ;; Define an entry point for the application (defn welcome-page [request] {:status 200 :body "Welcome to the world of Clojure CLI hotloading" :headers {}}) ;; Start the application server (app-server/run-server #'welcome-page {:port (or (System/getenv "PORT") 8888)}) ;; Visit http://localhost:8888/ to see the welcome-page ;; Hotload Hiccup to generate html for the welcome page (add-libs '{hiccup/hiccup {:mvn/version "2.0.0-alpha2"}}) (require '[hiccup.core :as hiccup]) (require '[hiccup.page :as hiccup-page]) (defn page-template [content] (hiccup-page/html5 {:lang "en"} [:head (hiccup-page/include-css "https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css")] [:body [:section {:class "hero is-info"} [:div {:class "hero-body"} [:div {:class "container"} [:h1 {:class "title"} (:title content) ] [:p {:class "subtitle"} (:sub-title content)]]]]])) ;; Check the page template returns HTML (page-template {:title "Hotload Libraries in the REPL" :sub-title "REPL driven development enables experimentation with designs"}) ;; redefine the welcome page to call the page template (defn welcome-page [request] {:status 200 :body (page-template {:title "Hotload Libraries in the REPL" :sub-title "REPL driven development enables experimentation with designs"}) :headers {}}) ) ; End of rich comment block ``` -------------------------------- ### Start Console Publisher for mulog Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-reloaded.md Start a mulog publisher to view events. This example uses the console publisher. ```clojure (mulog/start-publisher! {:type :console}) ``` -------------------------------- ### Start REPL with Chained Aliases Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/execution-options.md Chain multiple aliases together with the `-A` flag; their configurations will be merged. This example includes `:env/dev` and `:lib/hotload`. ```shell clojure -A:env/dev:lib/hotload ``` -------------------------------- ### Project Configuration Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/package/tools-build.md A detailed example of a Clojure project configuration map, including dependencies, aliases, and build settings. ```clojure { :library-name practicalli/clojure-app-template, :main-namespace practicalli/clojure-app-template, :project-version "1.0.16", :class-directory "target/classes", :project-basis { :paths ["src" "resources"], :deps #:org.clojure{clojure #:mvn{:version "1.11.1"}}, :aliases { :deps {:replace-paths [], :replace-deps #:org.clojure{tools.deps.cli #:mvn{:version "0.9.10"}}, :ns-default clojure.tools.deps.cli.api, :ns-aliases {help clojure.tools.deps.cli.help}}, :test {:extra-paths ["test"], :extra-deps {org.clojure/test.check #:mvn{:version "1.1.1"}, io.github.cognitect-labs/test-runner #:git{:tag "v0.5.0", :sha "48c3c67"}}}, :env/build {:extra-paths ["."}}, :run {:main-opts ["-m" "practicalli.clojure-app-template"]}, :greet {:ns-default practicalli.clojure-app-template, :exec-fn greet, :exec-args {:name "Clojure"}}, :build {:replace-paths [""], :replace-deps #:io.github.clojure{tools.build #:git{:tag "v0.9.4", :sha "76b78fe"}}, :ns-default build}}, :mvn/repos { "central" {:url "https://repo1.maven.org/maven2/"}, "clojars" {:url "https://repo.clojars.org/"}}, :libs #:org.clojure{clojure {:mvn/version "1.10.3", :deps/manifest :mvn, :parents #{[]}, :paths ["/home/practicalli/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar"]}, spec.alpha {:mvn/version "0.2.194", :deps/manifest :mvn, :dependents [org.clojure/clojure], :parents #{[org.clojure/clojure]}, :paths ["/home/practicalli/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar"]}, core.specs.alpha {:mvn/version "0.2.56", :deps/manifest :mvn, :dependents [org.clojure/clojure], :parents #{[org.clojure/clojure]}, :paths ["/home/practicalli/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar"]}}, :classpath-roots ["src" "resources" "/home/practicalli/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar" "/home/practicalli/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar" "/home/practicalli/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar"], :classpath { "src" {:path-key :paths}, "resources" {:path-key :paths}, "/home/practicalli/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar" {:lib-name org.clojure/clojure}, "/home/practicalli/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar" {:lib-name org.clojure/core.specs.alpha}, "/home/practicalli/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar" {:lib-name org.clojure/spec.alpha}}, :basis-config {:user nil}}, :jar-file "target/clojure-app-template-1.0.16.jar", :uberjar-file "target/clojure-app-template-1.0.16-standalone.jar"} ``` -------------------------------- ### Windows PowerShell - Scoop Setup Source: https://github.com/practicalli/clojure/blob/main/docs/install/clojure-cli.md Configure the PowerShell shell for installing Clojure related tools using scoop.sh. This involves downloading and executing the scoop installer and setting the execution policy. ```powershell iwr -useb get.scoop.sh | iex Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force ``` -------------------------------- ### Clojure CLI Install deps.edn Configuration Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/index.md This is an example of the default deps.edn configuration included with the Clojure CLI install. It sets default paths, Clojure version, and defines aliases for tools.deps.cli. ```clojure {:paths ["src"] :deps { org.clojure/clojure {:mvn/version "1.11.1"} } :aliases { :deps {:replace-paths [] :replace-deps {org.clojure/tools.deps.cli {:mvn/version "0.9.10"}} :ns-default clojure.tools.deps.cli.api :ns-aliases {help clojure.tools.deps.cli.help}} :test {:extra-paths ["test"]} } :mvn/repos { "central" {:url "https://repo1.maven.org/maven2/"} "clojars" {:url "https://repo.clojars.org/"} } } ``` -------------------------------- ### Start REPL with :performance/benchmark alias Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/practicalli-config.md Use the `-M` flag with the `:performance/benchmark` alias combined with `:repl/basic` to start a REPL configured for performance testing. ```shell clojure -M:performance/benchmark:repl/basic ``` -------------------------------- ### Start Mount Components Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-startup.md Defines a function to start all necessary Mount components for the application, including environment, database connection, business app, and nREPL. ```clojure (defn start [] (with-logging-status) (mount/start #'practicalli.app.conf/environment #'practicalli.app.db/connection #'practicalli.app.www/business-app #'practicalli.app.service/nrepl)) ``` -------------------------------- ### Example deps.edn Configuration File Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/index.md This example shows a comprehensive deps.edn configuration file, including paths, dependencies, and various aliases for running services, executing functions, setting up test environments, running tests, and building the project. ```clojure { :paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.11.1"} http-kit/http-kit {:mvn/version "2.6.0"} metosin/reitit {:mvn/version "0.5.13"} com.brunobonacci/mulog {:mvn/version "0.9.0"}} :aliases {;; Clojure.main execution of application :run/service {:main-opts ["-m" "practicalli.donuts.service"]} ;; Clojure.exec execution of specified function :run/greet {:exec-fn practicalli.donuts.service/greet :exec-args {:name "Clojure"}} ;; Add libraries and paths to support additional test tools :test/env {} ;; Test runner - local and CI ;; call with :watch? true to start file watcher and re-run tests on saved changes :test/run {:extra-paths ["test"] :extra-deps {lambdaisland/kaocha {:mvn/version "1.85.1342"}} :main-opts ["-m" "kaocha.runner"] :exec-fn kaocha.runner/exec-fn :exec-args {:randomize? false :fail-fast? true}} ;; tools.build `build.clj` built script :build {:replace-paths ["."] :replace-deps {io.github.clojure/tools.build {:git/tag "v0.9.4" :git/sha "76b78fe"}} :ns-default build}}} ``` -------------------------------- ### Clone Practicalli Leveraging Spec Project Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-spec/add-spec-to-projects.md Clone the 'practicalli/leveraging-spec' project from GitHub to get a project pre-configured with Clojure Spec examples. ```shell https://github.com/practicalli/leveraging-spec.git ``` -------------------------------- ### Start REPL with Rebel Readline Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/index.md Navigate to your project directory and start a REPL using Rebel Readline to test if the project runs. ```shell cd playground && clojure -M:repl/rebel ``` -------------------------------- ### Start Basic Clojure REPL Source: https://github.com/practicalli/clojure/blob/main/docs/alternative-tools/clojure-cli/basic-repl.md Use the `clj` command to start a Clojure REPL with command history support via rlwrap. This command can be run from any directory. ```shell clj ``` -------------------------------- ### Install MkDocs Plugins Source: https://github.com/practicalli/clojure/blob/main/README.md Install the required MkDocs plugins using pip. These are also used in the GitHub Actions workflow. ```shell pip3 install mkdocs-material mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects pillow cairosvg ``` -------------------------------- ### Aero Configuration Example Source: https://github.com/practicalli/clojure/blob/main/docs/testing/test-runners/aero.md Example of an Aero configuration in EDN format, demonstrating profile-specific database settings using the #profile reader literal. ```clojure {:port 8000 :database #profile {:prod "datomic:dev://localhost:4334/my-prod-db2" :test "datomic:dev://localhost:4334/my-test-db" :default "datomic:dev://localhost:4334/my-db"} :known-users [{:name "Alice"} {:name "Betty"}]} ``` -------------------------------- ### Install Java Docs and Sources on Debian Source: https://github.com/practicalli/clojure/blob/main/docs/install/java.md Install optional Java documentation and source packages for enhanced Java interop support in Clojure. ```shell sudo apt install openjdk-21-doc openjdk-21-source ``` -------------------------------- ### Install zprint Binary Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/clojure-style.md Download and install the zprint binary for Linux or MacOSX. Ensure the binary is executable and in your system's PATH. ```shell mv ~/Downloads/zprintl-1.2.5 ~/.local/bin/zprint chmod a+x ~/.local/bin/zprint ``` -------------------------------- ### Dependency Tree Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/built-in-commands.md An example output of the `clojure -X:deps tree` command, illustrating the dependency structure of the Practicalli Service project template. ```shell ❯ clojure -X:deps tree org.clojure/clojure 1.11.1 . org.clojure/spec.alpha 0.3.218 . org.clojure/core.specs.alpha 0.2.62 http-kit/http-kit 2.6.0 metosin/reitit 0.5.13 X metosin/reitit-core 0.5.13 :superseded X meta-merge/meta-merge 1.0.0 :parent-omitted X metosin/reitit-dev 0.5.13 :use-top . metosin/reitit-spec 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/spec-tools 0.10.5 X org.clojure/spec.alpha 0.2.187 :older-version . metosin/reitit-malli 0.5.13 X metosin/reitit-core 0.5.13 :older-version X metosin/malli 0.3.0 :older-version . metosin/reitit-schema 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/schema-tools 0.12.3 . prismatic/schema 1.1.12 . metosin/reitit-ring 0.5.13 X metosin/reitit-core 0.5.13 :older-version . ring/ring-core 1.9.1 . ring/ring-codec 1.1.3 . commons-codec/commons-codec 1.15 . commons-io/commons-io 2.6 . commons-fileupload/commons-fileupload 1.4 X commons-io/commons-io 2.2 :older-version . crypto-random/crypto-random 1.2.0 X commons-codec/commons-codec 1.6 :older-version . crypto-equality/crypto-equality 1.0.0 . metosin/reitit-middleware 0.5.13 . metosin/reitit-ring 0.5.13 . lambdaisland/deep-diff 0.0-47 . mvxcvi/puget 1.1.2 X mvxcvi/arrangement 1.2.0 :older-version X fipp/fipp 0.6.17 :older-version X fipp/fipp 0.6.17 :older-version . org.clojure/core.rrb-vector 0.0.14 . tech.droit/clj-diff 1.0.1 X mvxcvi/arrangement 1.2.0 :older-version . metosin/muuntaja 0.6.8 . metosin/jsonista 0.3.1 . com.cognitect/transit-clj 1.0.324 . com.cognitect/transit-java 1.0.343 X com.fasterxml.jackson.core/jackson-core 2.8.7 :older-version . org.msgpack/msgpack 0.6.12 . com.googlecode.json-simple/json-simple 1.1.1 . org.javassist/javassist 3.18.1-GA X commons-codec/commons-codec 1.10 :older-version . javax.xml.bind/jaxb-api 2.3.0 . metosin/spec-tools 0.10.5 . metosin/reitit-http 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/reitit-ring 0.5.13 . metosin/reitit-interceptors 0.5.13 . metosin/reitit-ring 0.5.13 . lambdaisland/deep-diff 0.0-47 . metosin/muuntaja 0.6.8 . metosin/reitit-swagger 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/reitit-swagger-ui 0.5.13 . metosin/reitit-ring 0.5.13 . metosin/jsonista 0.3.1 X com.fasterxml.jackson.core/jackson-core 2.12.0 :older-version X com.fasterxml.jackson.core/jackson-databind 2.12.0 :older-version . com.fasterxml.jackson.datatype/jackson-datatype-jsr310 2.12.0 X com.fasterxml.jackson.core/jackson-annotations 2.12.0 :older-version X com.fasterxml.jackson.core/jackson-core 2.12.0 :older-version X com.fasterxml.jackson.core/jackson-databind 2.12.0 :older-version . metosin/ring-swagger-ui 3.36.0 . metosin/reitit-frontend 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/reitit-sieppari 0.5.13 X metosin/reitit-core 0.5.13 :older-version . metosin/sieppari 0.0.0-alpha13 . com.fasterxml.jackson.core/jackson-core 2.12.1 . com.fasterxml.jackson.core/jackson-databind 2.12.1 . com.fasterxml.jackson.core/jackson-annotations 2.12.1 . com.fasterxml.jackson.core/jackson-core 2.12.1 metosin/reitit-dev 0.5.18 . metosin/reitit-core 0.5.18 :newer-version . meta-merge/meta-merge 1.0.0 . com.bhauman/spell-spec 0.1.2 . expound/expound 0.9.0 . fipp/fipp 0.6.25 com.brunobonacci/mulog 0.9.0 . amalloy/ring-buffer 1.3.1 com.brunobonacci/mulog-adv-console 0.9.0 X com.brunobonacci/mulog 0.9.0 :use-top . com.brunobonacci/mulog-json 0.9.0 X com.brunobonacci/mulog 0.9.0 :use-top . com.cnuernber/charred 1.010 aero/aero 1.1.6 party.donut/system 0.0.202 . aysylu/loom 1.0.2 . org.clojure/data.priority-map 0.0.5 . tailrecursion/cljs-priority-map 1.2.1 . org.clojure/clojurescript 1.7.170 ``` -------------------------------- ### Install Emacs on Ubuntu/Debian Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/index.md Install Emacs using the apt package manager on Ubuntu or Debian systems. This command installs the default version available in the repositories. ```shell sudo apt install emacs ``` -------------------------------- ### Start Basic Terminal UI REPL Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl/index.md Use the `:repl/basic` alias with the Clojure CLI to start a REPL process that includes an nREPL connection for editor integration. ```shell clj -M:repl/basic ``` -------------------------------- ### Install MkDocs Material Source: https://github.com/practicalli/clojure/blob/main/README.md Install MkDocs Material version 9 using pip. This is a prerequisite for local development. ```shell pip install mkdocs-material=="9.5" ``` -------------------------------- ### Check Clojure LSP Installation Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/clojure-lsp/index.md Verify that the Clojure LSP server is installed and accessible from the command line by checking its version. ```shell clojure-lsp --version ``` -------------------------------- ### Start Basic Terminal REPL Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/index.md Starts a basic terminal UI REPL. This is the default command for interactive Clojure development. ```bash clojure ``` ```bash clj ``` -------------------------------- ### Install Java Runtime with Chocolatey on Windows Source: https://github.com/practicalli/clojure/blob/main/docs/install/java.md Install the Java Runtime Environment (JRE) using the Chocolatey package manager on Windows. ```shell choco install javaruntime ``` -------------------------------- ### Web Server from Scratch with Hotloaded Libraries Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/add-libraries.md This example demonstrates building a web server incrementally by hotloading libraries as needed. It shows how to load http-kit and hiccup, define handlers, and serve dynamic HTML content without restarting the REPL. ```clojure (comment ;; run REPL with :lib/hotload alias (require '[clojure.tools.deps.alpha.repl :refer [add-libs]]) ;; hotload the libraries required for the server (add-libs '{http-kit/http-kit {:mvn/version "2.5.1"}}) ;; => (http-kit/http-kit) ;; Require the namespace from the http-kit library (require '[org.httpkit.server :as app-server]) ;; Define a handler for http requests (defn welcome-page [request] {:status 200 :body "Welcome to the world of Clojure CLI hotloading" :headers {}}) ;; Start the application server with the handler (app-server/run-server #'welcome-page {:port (or (System/getenv "PORT") 8888)}) ;; Visit http://localhost:8888/ to see the welcome-page ;; Hotload Hiccup to generate html for the welcome page (add-libs '{hiccup/hiccup {:mvn/version "2.0.0-alpha2"}}) (require '[hiccup.core :as hiccup]) (require '[hiccup.page :as hiccup-page]) ;; Create a page template (defn page-template [content] (hiccup-page/html5 {:lang "en"} [:head (hiccup-page/include-css "https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css")] [:body [:section {:class "hero is-info"} [:div {:class "hero-body"} [:div {:class "container"} [:h1 {:class "title"} (:title content) ] [:p {:class "subtitle"} (:sub-title content)]]]]])) ;; Check the page template returns HTML (page-template {:title "Hotload Libraries in the REPL" :sub-title "REPL driven development enables experimentation with designs"}) ;; redefine the welcome page to call the page template (defn welcome-page [request] {:status 200 :body (page-template {:title "Hotload Libraries in the REPL" :sub-title "REPL driven development enables experimentation with designs"}) :headers {}}) ;; Visit http://localhost:8888/ and refresh the page to see the new welcome-page ) ``` -------------------------------- ### Install VisualVM on Ubuntu Source: https://github.com/practicalli/clojure/blob/main/docs/reference/jvm/profile-tools.md Install VisualVM on Ubuntu or Debian systems using the apt package manager. VisualVM is a profiling tool bundled with the JDK. ```shell sudo apt install visualvm ``` -------------------------------- ### Run REPL Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/practicalli/application.md Starts the Clojure REPL with Rebel UI and Portal integration. An nREPL server is also started for editor connections. ```shell make repl ``` -------------------------------- ### Start Headless REPL Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl/index.md Execute the Clojure CLI command with the `:repl/headless` alias to start a REPL process with an nREPL connection, without an interactive REPL prompt. ```shell clj -M:repl/headless ``` -------------------------------- ### Go Function for Mount Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-startup.md The 'go' function initiates the application startup by calling the 'start' function and signals that all components are ready. ```clojure (defn go "Start all states defined by defstate" [] (start) :ready) ``` -------------------------------- ### Start REPL with Portal Only Source: https://github.com/practicalli/clojure/blob/main/docs/data-inspector/portal.md Starts a Clojure REPL with only the Portal data inspector. Use this command in your terminal when you don't need other features like reloading. ```shell clojure -M:inspect/portal:repl/rebel ``` -------------------------------- ### Example: Single Boolean Conversion using `get` Source: https://github.com/practicalli/clojure/blob/main/docs/simple-projects/encode-decode/convert-boolean-values.md Illustrates retrieving the integer representation for the boolean value `true` from a hash map using the `get` function. ```clojure (get {false 0 true 1} true) ``` -------------------------------- ### Clojure CLI User Configuration Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/index.md A basic example of a user-level deps.edn configuration for the Clojure CLI. This configuration adds aliases for creating new projects and setting up test environments. ```clojure {:aliases { :test/env {:extra-paths ["test"]} :project/new {:extra-deps {seancorfield/clj-new {:mvn/version "1.0.199"}} :main-opts ["-m" "clj-new.create"]} } :mvn/repos { "central" {:url "https://repo1.maven.org/maven2/"} "clojars" {:url "https://repo.clojars.org/"} }} ``` -------------------------------- ### Start Enhanced Terminal REPL Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/index.md Starts an enhanced terminal UI REPL with additional features like Portal, namespace reloading, and library hotload. Requires Practicalli aliases. ```bash clojure -M:repl/rebel ``` ```bash clojure -M:repl/reloaded ``` -------------------------------- ### Configuring Portal on REPL startup Source: https://github.com/practicalli/clojure/blob/main/docs/data-inspector/portal.md Projects created with Practicalli Project Templates can include Portal configuration in `dev/user.clj` and `dev/portal.clj`. This ensures Portal opens automatically when the REPL starts, providing immediate access to evaluation results. ```clojure ;; dev/user.clj (require '[portal.api :as p]) (defn start-dev-portal [] (p/open) (add-tap #'p/tap)) ``` -------------------------------- ### Install Emacs Snapshot on Ubuntu/Debian Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/index.md Install the latest nightly build of Emacs using the 'emacs-snapshot' package. Be aware that nightly builds may be unstable. ```shell sudo apt install emacs-snapshot ``` -------------------------------- ### Install OpenJDK on Ubuntu Source: https://github.com/practicalli/clojure/blob/main/docs/development-environments/java.md Install the OpenJDK 8 JRE on Ubuntu systems using the apt-get package manager. This provides the necessary Java runtime environment for Clojure. ```bash sudo apt-get install openjdk-8-jre ``` -------------------------------- ### Log Mulog Event Source: https://github.com/practicalli/clojure/blob/main/docs/data-inspector/portal.md Example of logging a mulog event. Events are now sent to portal when evaluated after the publisher is started. ```clojure (mulog/log ::repl-state ::ns (ns-publics *ns*)) ``` -------------------------------- ### Install a Clojure Tool with an Alias Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/execution-options.md Installs the `antq` tool using the `-Ttools` command and assigns it the alias `antq`. The `:as` directive specifies the name under which the tool will be available for execution. ```shell clojure -Ttools install com.github.liquidz/antq '{:git/tag "1.3.1"}' :as antq ``` -------------------------------- ### Example: Decode Single Clacks Code Source: https://github.com/practicalli/clojure/blob/main/docs/simple-projects/encode-decode/clacks.md Demonstrates calling `declacksify` with a specific Clacks code to get its corresponding character. ```clojure (declacksify [1 0 0 1 1 1]) ;; => "t" ``` -------------------------------- ### Run Local Development Server Source: https://github.com/practicalli/clojure/blob/main/README.md Start a local development server from the root of the cloned project to preview the website. The website will be accessible at http://localhost:8000. ```shell make docs ``` -------------------------------- ### Create a Project with Specific Templates Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/index.md Create a new project specifying the template and name using the :project/create alias. This example uses the practicalli/application template and names the project practicalli/random-function. ```shell clojure -T:project/create :template practicalli/application :name practicalli/random-function ``` -------------------------------- ### Start Clojure REPL with nrepl-jack-in Source: https://github.com/practicalli/clojure/blob/main/notes-for-clojure-practicalli.org Use the nrepl-jack-in command to start a new REPL and connect to it. This command is typically called by Leiningen to read project configuration. ```Emacs Lisp M-x nrepl-jack-in ``` -------------------------------- ### Example: Convert Multiple Clacks Codes to String Source: https://github.com/practicalli/clojure/blob/main/docs/simple-projects/encode-decode/clacks.md Demonstrates calling `clacks->string` with a list of Clacks codes to get a sequence of character names. ```clojure (clacks->string [[0 0 1 0 1 0] [0 1 0 0 0 1] [1 0 0 1 1 1]]) ;; => ("b" "a" "t") ``` -------------------------------- ### Creating a Project with clj-new and Default Arguments Source: https://github.com/practicalli/clojure/blob/main/docs/reference/clojure-cli/example-alias-definitions.md Example command to create a new project using `clj-new` with an alias that has default arguments pre-configured. ```shell clojure -M:project/new :name practicalli/awesome-webapp ``` -------------------------------- ### Getting the Class Name with Java Interop Source: https://github.com/practicalli/clojure/blob/main/docs/reference/clojure-syntax/strings.md Access Java String class methods using interop. This example retrieves the name of the String class. ```clojure (.getName String) ``` -------------------------------- ### Run Clojure with :repl/rebel alias Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/index.md Use the -M flag with an alias to start a REPL with specific development dependencies. This example assumes the :repl/rebel alias is configured in your deps.edn. ```shell clojure -M:repl/rebel ``` -------------------------------- ### Clojure CLI REPL Build System for Sublime Text Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/index.md Configure Clojure Sublime Text to start a Clojure CLI REPL with an nREPL server. Assumes Java and Clojure CLI are installed. ```shell {"env": {"JAVA_HOME": "/path/to/java"}, "cmd": ["/usr/local/bin/clojure", "-Sdeps", "{:deps {nrepl/nrepl {:mvn/version \"1.0.0\"}}}", "-M", "-m", "nrepl.cmdline"]} ``` -------------------------------- ### Basic Portal Configuration Source: https://github.com/practicalli/clojure/blob/main/docs/data-inspector/portal.md This snippet demonstrates basic Portal configuration: opening the inspector with a dark theme and adding Portal as a tap> target over an nREPL connection. It also includes commented-out examples for clearing and closing the inspector. ```clojure (ns user (:require [portal.api :as inspect])) ;; --------------------------------------------------------- ;; Open Portal window in browser with dark theme (inspect/open {:portal.colors/theme :portal.colors/gruvbox}) ;; Add portal as a tap> target over nREPL connection (add-tap #'portal.api/submit) ;; --------------------------------------------------------- (comment (inspect/clear) ; Clear all values in the portal inspector window (inspect/close) ; Close the inspector ) ; End of rich comment block ``` -------------------------------- ### Alias Chaining Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/defining-aliases.md Demonstrates how multiple aliases can be chained together on the command line to merge their configurations. ```shell clojure -M:task/path:task/deps:build/options ``` -------------------------------- ### Example Alias Definitions for REPL Reloaded Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-reloaded.md Defines aliases for starting a REPL process with an nREPL server, Rebel rich terminal UI, and tools for hotloading libraries, reloading namespaces, and running the Portal data inspector. Includes paths for custom REPL startup, unit test code, and a test runner. ```clojure :repl/reloaded {:extra-paths ["dev" "test"] :extra-deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.30.0"} com.bhauman/rebel-readline {:mvn/version "0.1.4"} djblue/portal {:mvn/version "0.35.1"} org.clojure/tools.namespace {:mvn/version "1.4.1"} org.slf4j/slf4j-nop {:mvn/version "2.0.6"} com.brunobonacci/mulog {:mvn/version "0.9.0"} lambdaisland/kaocha {:mvn/version "1.77.1236"} org.clojure/test.check {:mvn/version "1.1.1"} ring/ring-mock {:mvn/version "0.4.0"} criterium/criterium {:mvn/version "0.4.6"}} :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,portal.nrepl/wrap-portal]" "--interactive" "-f" "rebel-readline.main/-main"]} :dev/reloaded {:extra-paths ["dev" "test"] :extra-deps {djblue/portal {:mvn/version "0.35.1"} org.clojure/tools.namespace {:mvn/version "1.4.1"} org.slf4j/slf4j-nop {:mvn/version "2.0.6"} com.brunobonacci/mulog {:mvn/version "0.9.0"} lambdaisland/kaocha {:mvn/version "1.77.1236"} org.clojure/test.check {:mvn/version "1.1.1"} ring/ring-mock {:mvn/version "0.4.0"} criterium/criterium {:mvn/version "0.4.6"}}} ``` -------------------------------- ### Prepare Source Dependencies Configuration Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/built-in-commands.md Configure dependencies that require a preparation step before being used on the classpath. This example shows how to set up a build alias and ensure a target directory. ```clojure {:paths ["src" "target/classes"] :deps/prep-lib {:alias :build :fn compile :ensure "target/classes"}} ``` -------------------------------- ### Linux Script Install - Unattended/Alternative Location Source: https://github.com/practicalli/clojure/blob/main/docs/install/clojure-cli.md For unattended installs or to use an alternative location, use the --prefix option with the Linux install script. This is useful when permissions are not available or for automating the install without a password prompt. ```shell curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh && \ chmod +x linux-install.sh && \ ./linux-install.sh --prefix $HOME/.local/ ``` -------------------------------- ### Linux Script Install Source: https://github.com/practicalli/clojure/blob/main/docs/install/clojure-cli.md Use the Linux script installer from Clojure.org to install or update to the latest stable release of the Clojure CLI. ```shell curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh && \ chmod +x linux-install.sh && \ sudo ./linux-install.sh ``` -------------------------------- ### Create Clojure Project Source: https://github.com/practicalli/clojure/blob/main/docs/simple-projects/data-transformation/most-common-word.md Use the Practicalli Clojure CLI config to create a new project with the 'app' template and name it 'practicalli/common-words'. ```shell clojure -T:project/create :template app :name practicalli/common-words ``` -------------------------------- ### Run an Installed Clojure Tool Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/execution-options.md Executes the `outdated` function of the installed `antq` tool. This command assumes the `antq` tool has already been installed. ```shell clojure -Tantq outdated ``` -------------------------------- ### Install Emacs with Msys2 Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-editors/index.md Install the 64-bit build of Emacs on a system using Msys2. This command uses the pacman package manager to install Emacs. ```shell pacman -S mingw-w64-x86_64-emacs ``` -------------------------------- ### Access Character Information using `get` Source: https://github.com/practicalli/clojure/blob/main/docs/designing-data-structures/with-maps-of-maps.md Retrieve all details for a specific character using the `get` function. Wrap `get` to access nested values. ```clojure (get star-wars-characters :luke) ``` ```clojure (get (get star-wars-characters :luke) :fullname) ``` -------------------------------- ### Create a new landing page project Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/practicalli/landing-page.md Use the clojure CLI to create a new project from the landing-page template. Replace 'practicalli/website-name' with your desired project name. ```shell clojure -T:project/create :template landing-page :name practicalli/website-name ``` -------------------------------- ### Create a service project with Donut System components Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/practicalli/index.md Generate a 'practicalli/service' project template, specifying the project name and the 'donut' component management. This is useful for creating production-level web services. ```shell clojure -T:project/create :template practicalli/service :name practicalli/todo-list :component :donut ``` -------------------------------- ### Accessing Nested Map Values with `get` Source: https://github.com/practicalli/clojure/blob/main/docs/data-structures/hash-maps/accessing-nested-hash-maps.md Use the `get` function to retrieve values from nested hash-maps. Chain `get` calls for deeper nesting. ```clojure (get star-wars-characters :luke) (get (get star-wars-characters :luke) :fullname) ``` -------------------------------- ### Install Oracle Java 8 on Ubuntu Source: https://github.com/practicalli/clojure/blob/main/notes-for-clojure-practicalli.org Installs Oracle Java 8 on Ubuntu systems. Requires removing existing OpenJDK installations and adding a PPA. ```bash sudo apt-get purge openjdk* sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer ``` -------------------------------- ### REPL Help menu for custom user namespace Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/repl-startup.md Defines a 'help' function to display available commands and their descriptions on REPL startup. Add '(help)' to your user namespace to display this menu. ```clojure ;; --------------------------------------------------------- ;; Help (println "---------------------------------------------------------") (println "Loading custom user namespace tools...") (println "---------------------------------------------------------") (defn help [] (println "---------------------------------------------------------") (println "System components:") (println "(start) ; starts all components in system config") (println "(restart) ; read system config, reloads changed namespaces & restarts system") (println "(stop) ; shutdown all components in the system") ;; (println "(system) ; show configuration of the running system") ;; (println "(config) ; show system configuration") (println) (println "Hotload libraries: ; Clojure 1.12.x") (println "(add-lib 'library-name)") (println "(add-libs '{domain/library-name {:mvn/version "v1.2.3"}})") (println "(sync-deps) ; load dependencies from deps.edn") (println "- deps-* lsp snippets for adding library") (println) (println) (println "Portal Inspector:") (println "- portal started by default, listening to all evaluations") (println "(inspect/clear) ; clear all values in portal") (println "(remove-tap #'inspect/submit) ; stop sending to portal") (println "(inspect/close) ; close portal") (println) (println "(help) ; print help text") (println "---------------------------------------------------------")) (help) ;; End of Help ;; --------------------------------------------------------- ``` -------------------------------- ### REPL namespace management examples Source: https://github.com/practicalli/clojure/blob/main/notes-for-clojure-practicalli.org Demonstrates various syntaxes for requiring namespaces and functions in the REPL, including aliasing and importing specific functions. ```clojure (require 'hyperion.api.set-ds! 'hyperion.api.new-datastore) ``` ```clojure (require '(hyperion.api set-ds! new-datastore)) ``` ```clojure (require '[hyperion.api.set-ds! :as ds]) ``` ```clojure (require ['hyperion.api.set-ds! :as 'ds]) ``` ```clojure (use '[hyperion.api :only [new-datastore]]) ``` -------------------------------- ### Conforming Data Structure Example Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-spec/data/hierarchical-specifications.md An example of data that conforms to the hierarchical ::user-account specification. ```clojure {::user-id #uuid "97bda55b-6175-4c39-9e04-7c0205c709dc" ::customer-details {::first-name "Jenny" ::last-name "Jetpack" ::residential-address "Earth"}} ``` -------------------------------- ### Create Service Project with Donut System Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/practicalli/service.md Include Donut system configuration and REPL functions by specifying the :component :donut argument. ```shell clojure -T:project/create :template practicalli/service :component :donut ``` -------------------------------- ### Example Hierarchical Data Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-spec/data/hierarchical-specifications.md An example of nested data structure that can be validated by hierarchical specifications. ```clojure {:top-level-key {:nested-key "value"}} ``` -------------------------------- ### JavaScript Partial Application Example Source: https://github.com/practicalli/clojure/blob/main/GLOSSARY.md Shows how to use `bind` in JavaScript for partial application of a function. ```javascript let sum = (a, b) => a + b; // partially applying `a` to `40` let partial = sum.bind(null, 40); // Invoking it with `b` partial(2); //=> 42 ``` -------------------------------- ### Sample LightTable User Behaviours Configuration Source: https://github.com/practicalli/clojure/blob/main/docs/development-environments/lighttable.md A sample configuration file for LightTable's user behaviors, allowing customization of editor and IDE features. ```clojure ;; Sample user behaviours file for LightTable ;; Enable auto-completion for Clojure [:editor.auto-complete :enable true] ;; Set the default font size [:editor.font-size 12] ;; Enable minimap [:editor.minimap true] ;; Configure keybindings (example: rebind save to Ctrl+Shift+S) [:editor.key-bindings {"ctrl-shift-s" :editor.save}] ;; Enable inline errors for Clojure [:linters.clojure :enable true] ;; Set the default theme to Light [:editor.theme :light] ;; Enable bracket matching [:editor.bracket-match true] ;; Enable auto-indentation [:editor.auto-indent true] ;; Configure project-specific settings (example: disable auto-completion for a specific project) ;[:project.my-project :editor.auto-complete false] ``` -------------------------------- ### Windows PowerShell - Scoop Install Clojure Tools Source: https://github.com/practicalli/clojure/blob/main/docs/install/clojure-cli.md Install Clojure related tools using scoop.sh in PowerShell. This includes adding necessary buckets and installing essential tools like git, Java, and the Clojure CLI. ```powershell scoop bucket add extras scoop bucket add java scoop bucket add scoop-clojure https://github.com/littleli/scoop-clojure scoop install git 7zip pshazz temurin-lts-jdk clj-deps leiningen clj-kondo vscode coreutils windows-terminal ``` -------------------------------- ### Create Service Project with Integrant System Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/projects/templates/practicalli/service.md Include Integrant system configuration and REPL functions by specifying the :component :integrant argument. ```shell clojure -T:project/create :template practicalli/service :component :integrant ``` -------------------------------- ### Install zprint-clj NPM Package Source: https://github.com/practicalli/clojure/blob/main/docs/clojure-cli/clojure-style.md Install the zprint-clj NPM package globally for use in Node.js environments. ```shell sudo --install --global zprint-clj ``` -------------------------------- ### Install OpenJDK 21 with Homebrew Source: https://github.com/practicalli/clojure/blob/main/docs/install/java.md Install OpenJDK version 21 on macOS using the Homebrew package manager. ```shell brew install openjdk@21 ``` -------------------------------- ### Create a new Clojure project Source: https://github.com/practicalli/clojure/blob/main/docs/simple-projects/split-the-bill.md Use the `:project/create` alias from Practicalli Clojure CLI Config to create a new Clojure project for splitting the bill. ```shell clojure -T:project/create :template app :name practicalli/split-the-bill ``` -------------------------------- ### Get First Character of a String Source: https://github.com/practicalli/clojure/blob/main/docs/designing-data-structures/modeling-name-generation-map.md Demonstrates how to get the first character of a string in Clojure by treating the string as a collection. ```clojure (first "Strings also act as collections") ```