practicalli / clojure

Practicalli Clojure REPL Driven Development
https://practical.li/clojure/
Creative Commons Attribution Share Alike 4.0 International
89 stars 36 forks source link

Getting Started with Clojure CLI and tools.deps #39

Open practicalli-johnny opened 4 years ago

practicalli-johnny commented 4 years ago

Welcome to Practicalli, thank you for joining me.

I'm John and i'll introduce you to the Clojure CLI tools, the simplest way of running and working with a Clojure REPL and projects.

This video assumes you have installed the Clojure CLI tools and the Practicalli deps.edn configuration. See the video on installing the Clojure CLI tools if you havent done so already.

I will show you how to run a single Clojure expression so you can quickly try a little Clojure. How to run a feature rich REPL for a simple development environment.. How to create and run Clojure projects

Finally we will see how to run a REPL, which is a live Clojure environment in which you can immediately evaluate your code, so you get feedback as you write your code.

** Running Clojure code

Using the -e option with the clojure command you can evaluate a Clojure expression, an expression being any single piece of correct Clojure code.

For example clojure -e "(+ 1 2 3)"

This command prints out the value returned from evaluating the Clojure code.

You can run an existing Clojure project using the -m option. The -m option sets the main namespace, the entry point into your application

The project does need to have a -main or main function defined and have (:gen-class) in the namespace.

clojure -m simple.core

This is a very simple project and prints out "Hello World!"

** Running a Clojure REPL

Clojure development is done with a REPL. This is your live Clojure environment, where you can run your code as you write it and get immediate feedback.

There is no external compilation of code, it all happens as soon as you evaluate the expression.

Typing clojure into a command line terminal will start a Clojure REPL Although better REPL experience is provided via the clj command.

clj adds the rlwrap command, providing a readline for the Clojure REPL.

A readline library provides line-editing and history capabilities, essential for interactive command line tools such as the Clojure REPL.

[run clj in a terminal]

** Extending Clojure CLI tool with Aliases <Review the ~/.clojure/deps.edn> file from practicalli and discuss aliases.

clojure and clj commands can use aliase with the -A option, for example clojure -A:new uses the alias called :new, which in this case creates a project.

To create a Clojure project that we can run as an application, use the app template. clojure -A:new app domain/main-namespace

The domain is the top level grouping for your project, like google, cognitect, clojure.org. It could be the company you work at, the business area, application suite the project is part of or your GitHub account or organisation name for a personal or open source project.

The main-namespace is usually the name of the specific application or service you are building.

This creates a project with a standard structure

[tree of project]

Other templates can be used such as lib when building a library of functions. There are many other templates defined by the community [provide a link / create a website with a curated list of templates]

** Rebel Readline Alias Rebel Readline provides function signature information, documentation, editing styles and tools to manage the REPL, including a quit function.

Using an alias, the rebel readline library is added as a dependency and its main namespace specified so it will run when calling the clojure command.

Including an alias for rebel readline in $HOME/.clojure/deps.edn makes it available to all projects.

There are many useful aliases defined in the Practicalli deps.edn configuration.

** In summary This has covered the basics of evaluating Clojure code, running a REPL and working with projects so you have a good foundation on which to learn how to write Clojure code.

Thank you for listening and see you in the next video.

practicalli-johnny commented 4 years ago

Recorded the video. Some editing required to remove the bloopers.

practicalli-johnny commented 4 years ago

Re-recorded video with new OBS setup, with full HD and 450,000kbps bitrate.

practicalli-johnny commented 4 years ago

Edited the video to remove gaps and bloopers. Now waiting for YouTube to process the new video.

practicalli-johnny commented 4 years ago

Hmm, there is a limit to how many edits you can make via the YouTube dashboard :disappointed: