Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
c68a38c
Merge pull request #2 from inclojure-org/master
adityaathalye Jul 20, 2018
d2bd0cb
Merge pull request #3 from inclojure-org/master
adityaathalye Jul 21, 2018
9cb904f
Refactor ex00. Quickly intro all key concepts like
adityaathalye Oct 25, 2018
c9aba95
Refactor ex01. Add destructuring, collections, and
adityaathalye Oct 25, 2018
6b1d8f1
WIP: Tighten ex02
adityaathalye Oct 25, 2018
e895bb0
Extract functions, lexical scope from ex02 to ex01
adityaathalye Oct 25, 2018
28f6cf3
Replace ex03 with totally refactored variant
adityaathalye Oct 25, 2018
368bc96
Limit ex02 to domain as data, remove destructuring
adityaathalye Oct 29, 2018
a6ac84d
Simplify ex03, avoid destructuring & fancy HoFs
adityaathalye Oct 29, 2018
c82b34e
Make ex04 about function API design, destructuring
adityaathalye Oct 29, 2018
09e5780
Rename utils to fun, because it is so...
adityaathalye Dec 1, 2018
93bba3f
Fix typo in fn name (thanks Mayank Pahwa)
adityaathalye Dec 1, 2018
b881d34
Tweak some copy and comment forms in ex02
adityaathalye Dec 1, 2018
ebe8a2e
Don't use not-empty in ex03, explore stdlib later
adityaathalye Dec 1, 2018
31537f4
Bump clj version, fix deps, drop lighttable compat
adityaathalye Dec 1, 2018
8fb1365
Add fun way to reformat ex code for in-class use
adityaathalye Dec 1, 2018
2cb9e07
ex04 to teach API design with simple destructuring
adityaathalye Dec 1, 2018
81d4e52
Improve ex00 copy & add commentary for home use
adityaathalye Dec 30, 2018
dc5a9d2
Add recap section to ex00
adityaathalye Jan 5, 2019
b059719
Exercisify ex01 & improve questions, commentary
adityaathalye Jan 5, 2019
2a5aabd
Exercisify ex02 and improve explanations
adityaathalye Jan 5, 2019
9c55e43
Bump Clojure version to 1.10.0
adityaathalye Jan 5, 2019
f3734d5
Update README for IntelliJ + Cursive instead of
adityaathalye Jan 5, 2019
549e711
gitignore IntelliJ-generated .idea directory
adityaathalye Jan 5, 2019
1e4d5d7
Exercisify ex03; intended as a reading exercise to
adityaathalye Jan 6, 2019
97f1eae
Improve ex01 explanation of lexical scope
adityaathalye Jan 7, 2019
0e8f18c
Fix ex04 explanations, & include multiple arities
adityaathalye Jan 7, 2019
735b355
Refactor ex05; retain only immutability + FP and
adityaathalye Jan 7, 2019
de1143c
Fixup ex06 & make corresponding fixes in ex07
adityaathalye Jan 7, 2019
559aa81
Ignore iml files generated by IntelliJ
adityaathalye Jan 7, 2019
1973240
Reorder ex06 comment to un-break workshop_fmt.clj
adityaathalye Jan 7, 2019
91e0b71
Merge pull request #9 from inclojure-org/refactor-workshop
adityaathalye Jan 8, 2019
ecca672
Fix minor README typos
jysandy Jan 8, 2019
5181d30
Add README instructions to switch to ns & load file
adityaathalye Jan 14, 2019
7472e26
Add table of contents
adityaathalye Jan 14, 2019
ccd32cd
Fix annoying typos, improve some copy
adityaathalye Feb 24, 2019
7390239
Link to Kim Hirokuni's Clojure By Example
adityaathalye Feb 25, 2019
b49e4cd
Introduce a subtle and insidious bug to practice debugging
jysandy Dec 17, 2019
b185004
WIP: Write up debugging walkthrough
jysandy Dec 17, 2019
80c9664
First draft of debugging walkthrough
jysandy Dec 29, 2019
7da8510
Add final testing step in debugging walkthrough
jysandy Dec 29, 2019
d03ab54
Merge pull request #10 from inclojure-org/revamp-ex-03
jysandy Jan 4, 2020
9d6773a
Add local m2 to let us zip & share the repo standalone
adityaathalye Feb 8, 2020
4b8cc89
Merge pull request #11 from adityaathalye/master
jysandy Feb 10, 2020
5e560ec
Make Java and Leiningen setup optional
jysandy Feb 11, 2020
a5c91ae
Add 4clojure problems before and after exercises
Jan 8, 2020
8d4d6ce
Revise recap copy to pose 4clojure probs @mihil added
adityaathalye Feb 11, 2020
b8cbd59
Fix broken ns declaration in ex07
adityaathalye Feb 11, 2020
395e32d
Fix how Hirokuni Kim's name appears with reference
adityaathalye Feb 11, 2020
9a4c193
ex01 clarify why map returns things in round parens
adityaathalye Feb 24, 2020
3726e86
Clarify a previously implicit goal of the workshop
adityaathalye Jun 2, 2020
5be14f3
Fix stale instructions in Ex07. Thanks @Grazfather.
adityaathalye Mar 14, 2021
4b8ca16
Fix dead links
ayush000 May 26, 2021
0cc34c3
Add intro to Clojure, the language. Thanks Lars Wirzenius <liw@liw.fi>
adityaathalye Aug 15, 2021
6390163
Fix links to 4clojure problem sets. The OG site was
adityaathalye Aug 26, 2021
c8d1507
Link to alternative setups for VSCode and Vim
adityaathalye Sep 2, 2021
47eb98f
Move to tools.deps i.e. deps.edn
kirankulkarni Nov 22, 2023
fe12e0e
Remove the dev alias and add all dependencies to default
kirankulkarni Nov 23, 2023
c414670
Add VSCode + Calva section in README.md
kirankulkarni Nov 23, 2023
50a611e
Update - Simplify setup instructions
Nov 24, 2023
2d2be66
Add calva generated directories to gitignore
0niket Nov 25, 2023
30bfce9
Fix typos. Replace redundant reference to VSCode, now
adityaathalye Mar 4, 2024
189d847
Deduplicate Java install instruction. Move it above IDE
adityaathalye Mar 4, 2024
50854a6
Consistently period-terminate bullet points, as we are
adityaathalye Mar 4, 2024
a76d055
Tighten Java install instructions
adityaathalye Mar 4, 2024
37e5c09
Fix copyright notice, up to 2024
adityaathalye Mar 4, 2024
0375b25
Fix bullet point line space rendering. The blank line
adityaathalye Mar 4, 2024
e3e3f65
Merge pull request #15 from adityaathalye/master
adityaathalye Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ pom.xml.asc
.hg/
.setup.sh
profiles.clj
.idea
.m2-for-inclojure
*.iml
.lsp
.cpcache
.clj-kondo
.calva
203 changes: 95 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,138 +1,125 @@
# Clojure By Example
- [Introduction](#introduction)
- [Intended usage](#intended-usage)
- [Contributions](#contributions)
- [Workshop Goals](#workshop-goals)
- [Workshop Anti-Goals](#workshop-anti-goals)
- [Suggested learning mindset](#suggested-learning-mindset)
- [Setup Instructions](#setup-instructions)
- [Course Design Philosophy](#course-design-philosophy)
- [Credits](#credits)
- [Copyright and License](#copyright-and-license)

What could one do with just a _little_ bit of Clojure?

## Intended usage
- Support a 1-day guided workshop for programmers new to Clojure (not absolute programming beginners).
- Also function as at-home learning material for said programmers.
- The `master` branch is heavily commented, for at-home use
- A `solutions` branch will be available, as a companion to `master`.
But don't peek at it in advance!
- Ignore the `workshop-code` branch. It is only for workshop use,
and subject to deletion/re-creation.

## Contributions
- If you find bugs or errors, please send a PR (but please
don't change the course structure or pedagogy).

## Workshop Goals
- Acquire a "feel" of Clojure, for further self-study/exploration.
- Learn how Clojurists usually think with Clojure to solve problems.
- See how it's not so hard to do surprisingly powerful things with a
mere handful of "primitive" functions, data structures, and ideas.

## Workshop Anti-Goals
- Try to explain Functional Programming theory or Clojure's innards.
(Many free and paid tutorials and books do so very well.)
- Try to fully cover Clojure primitives/features. (That's homework!)
- Devolve into language wars, editor wars, syntax wars, type wars...
(Life's too short, people.)
- Focus too much on tooling or operational things. (At least not
while there's fun to be had!)
# Introduction

This workshop aims to get your brain and fingers accustomed to just enough of
the [Clojure](https://clojure.org) programming language to start doing useful things with it.

# Suggested learning mindset
- Think of this as an exercise in "constrained creativity".
- Ignore details, achieve much with as little know-how as possible.
- Focus on what things do; not what they are, or why they are.
- Inform your _intuition for doing things_, and then use that to
dive deeper into all the juicy details at your own pace, later.
In other words, "What could one do with just a _little_ bit of Clojure?".

Take what is useful, discard the rest.
## What is Clojure?

Clojure is an interactive functional programming language that can run on many platforms
like the [JVM](https://clojure.org/about/jvm_hosted), [.NET CLR](https://clojure.org/about/clojureclr), [Javascript](https://clojurescript.org/) (browsers, nodeJS, React Native), as [native binaries](https://github.com/BrunoBonacci/graalvm-clojure) via Graalvm, and even as [shell scripts](https://babashka.org/)!

# Setup Instructions
It is [used by software teams worldwide](https://clojure.org/community/success_stories#) to deliver
high-value software systems at giant companies like Apple, Walmart, to "decacorns"
like GoJek, Nubank, to a wide array of startups, and one-person businesses like Partsbox.com.

It's a liiitle bit of work. But not too bad.
Its interactivity and dynamism foster a sense of playfulness that attracts all manner
of [creative makers](http://radar.oreilly.com/2015/05/creative-computing-with-clojure.html)---hobbyist as well as serious artists and musicians.

Just do the following one by one, and you should be fine.
A small but vibrant [global community](https://clojure.org/community/user_groups) is [busy building amazing things](https://github.com/trending/clojure?since=monthly) with the language.

## Java 8
## Intended usage

You will need Java to work with this Clojure workshop content.
- Support a 1-day guided workshop for programmers new to Clojure (not absolute programming beginners).
- Also function as at-home learning material for said programmers.
- The `master` branch is heavily commented, for at-home use.
- A `solutions` branch will be available, as a companion to `master`.
But don't peek at it in advance!
- You may see a `workshop-code` branch. Ignore it. It is meant only for
workshop use, and is subject to deletion/re-creation.
- Incidentally, if you landed here while searching for Hirokuni Kim's
"[Clojure By Example](https://kimh.github.io/clojure-by-example/)", well, follow the link!

First, make sure you have Java 8.
## Contributions

- Run `java -version` in your terminal.
- If Java is not installed, please [download and install Java 8 from here](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
- Once you are done, `java -version` should show you a Java 1.8.x version.
- If you find bugs or errors, please send a PR (but please
don't change the course structure or pedagogy).

Notes:
## Workshop Goals

- If you have Java 9, that should be OK too.
- The LightTable editor is known to break with Java 9. Use Java 8 instead.
- We have not tested this project with Java 7.
- Acquire a "feel" of Clojure, for further self-study/exploration.
- Learn how Clojurists usually think with Clojure to solve problems.
- See how it's not so hard to do surprisingly powerful things with a
mere handful of "primitive" functions, data structures, and ideas.
- Get you started with a good development setup and workflow that will
serve you well if (when) you continue to program with Clojure, as a
hobby, or at work!

## Workshop Anti-Goals

## Leiningen
- Try to explain Functional Programming theory or Clojure's innards.
(Many free and paid tutorials and books do so very well.)
- Try to fully cover Clojure primitives/features. (That's homework!)
- Devolve into language wars, editor wars, syntax wars, type wars...
(Life's too short, people.)
- Focus too much on tooling or operational things. (At least not
while there's fun to be had!)

Follow [Leiningen setup instructions here](https://leiningen.org/).
# Suggested learning mindset

### Fire up a REPL
- Think of this as an exercise in "constrained creativity".
- Ignore details, achieve much with as little know-how as possible.
- Focus on what things do; not what they are, or why they are.
- Inform your _intuition for doing things_, and then use that to
dive deeper into all the juicy details at your own pace, later.

- Clone this project
- Open your terminal, and do the following.
- `cd` into this project's root directory
- Use `lein repl` command to start a REPL with Leiningen.
- Wait for it... the REPL will start and print out a message with some
useful information
- Locate the `port` and `host` information in the message. We will need this information soon.
Take what is useful, discard the rest.

Note:
# Setup Instructions

- [Boot](http://boot-clj.com/) should be fine too, but we have not tested this project with it.
Just do the following one by one, and you should be fine.

## Java

## Code Editor and Tooling
You need Java installed.

Set up an editor and figure out how to evaluate Clojure code with it.
- Run `java -version` in your terminal.
- If Java is not installed, please [download and install Java from here](https://adoptopenjdk.net/).
- Any version should do, but prefer Java 8 or higher. We have not tested
this project with Java 7.
- Once you are done, `java -version` should show you a Java version.

### LightTable
## VSCode + Calva

We used LightTable for our workshop. We suggest you do so too, unless of course, you have already set up your favourite editor for Clojure development. Avoid [bikeshedding](http://catb.org/jargon/html/B/bikeshedding.html) editors. Just complete the workshop first!
We support VSCode + Calva IDE in the classroom for this workshop. We suggest you use this setup, unless of course, you have already configured your favourite editor for Clojure development. We've listed alternate starter kits below (IntelliJ, Vim, Emacs, Atom), _but_ please avoid [bikeshedding](http://catb.org/jargon/html/B/bikeshedding.html) editors. Just complete the workshop first!

- You may install LightTable from the [official website](http://lighttable.com/).
- But you must have Java 8. LightTable breaks with Java 9.
- On Mac OS, you may have to allow running the app in your security preferences to be able to open it.
- Download and Install [VSCode](https://code.visualstudio.com/).
- Open VSCode and complete the initialization process.
- Open the "Extensions" Tab and search for "Calva", Install the "Calva:
Clojure & ClojureScript Interactive Programming" extension.
- Alternatively you can visit the [Calva page](https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva) to install it.

Once installed:

- Use LightTable's file menu to open this project.
- In the left pane, navigate down to the first file `ex00...`, under the `src` folder.
- Under `View` menu, click `Connections`. A right pane should open.
- Under `Add Connection`, click `Clojure (remote REPL)` and complete the port number. Recall host:port information was printed to the terminal when you fired up a REPL in the previous section.
- In the `ex00..` file, scroll down a little, till you see `(+ 1 2)`.
- Place your cursor after the closing parenthesis `)` and hit Ctrl+Enter (Win/Linux), or Cmd+Enter (Mac).
- You should see `3` appear in-line. This means you successfully connected and evaluated an expression.
- Now you may start from the top of ex00 and work through the material.

Also keep [LightTable's documentation](http://docs.lighttable.com/tutorials/full/) handy in case you need editor help, as you solve the workshop material.


Optionally, add Parinfer for easier editing:

- In LightTable, go to View -> Plugin Manager and search for "parinfer".
- Install the Parinfer plugin by Maur�cio Szabo.
- Parinfer is an editing system for Clojure that makes it easy for you to move Clojure code around without unbalancing parentheses.
- We recommend going through the [Parinfer documentation here](https://shaunlebron.github.io/parinfer/). But don't get stuck there, just keep it handy.
- Clone the repository on your machine.
- In VSCode Use File > Open Folder... and open the cloned folder.
- Notice that Calva activates.
- Open the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) in VSCode using `⇧⌘P` on Mac or `Ctrl+Shift+P` on other systems.
- Type "Calva: Start Project REPL" and choose "Calva: Start a Project REPL and Connect (aka Jack-In)" from the list.
- Select `deps.edn` when prompted for Project type. We are using [tools.deps](https://clojure.org/guides/deps_and_cli) for managing the project. You don't need to worry about it's details for this workshop.
- VSCode will create a new pane called 'output.calva-repl' and you will see `clj꞉user꞉>` prompt in that screen.
- You have a working REPL now!
- Keep the [Paredit guide](https://calva.io/paredit/) handy, editing code will require some understanding of paredit.


### Alternative Starter Kits:

If you can't use LightTable for some reason (like can't downgrade to Java 8 from Java 9). You may try one of these. Although we haven't tested with these setups, the workshop material should work fine.

- A [snazzy setup with Atom](https://medium.com/@jacekschae/slick-clojure-editor-setup-with-atom-a3c1b528b722).
- Brave Clojure walks you through [a basic Emacs setup for learning Clojure](https://www.braveclojure.com/basic-emacs/).


### Your favourite editor:
## Your favourite editor:

You may find instructions for your favourite editor at one of these pages. But there are only so many choices. Ultimately, you must pick your poison and run with it:

- ["IDEs and Editors" at dev.clojure.org](https://dev.clojure.org/display/doc/IDEs+and+Editors)
- ["Essentials" at clojure-doc.org](http://clojure-doc.org/articles/content.html#essentials)
- [Christopher Bui says...](https://cb.codes/what-editor-ide-to-use-for-clojure/)

- ["Clojure Tools" at clojure.org](https://clojure.org/community/tools)
- ["Essentials" at clojure-doc.org](http://clojure-doc.org/articles/content.html#essentials)
- [Christopher Bui says...](https://web.archive.org/web/20181223213500/https://cb.codes/what-editor-ide-to-use-for-clojure/)

# Course Design Philosophy

Expand All @@ -149,17 +136,17 @@ satisfies and empowers us deeply.
So, may you stay small and achieve important things.

Live long, and prosper.
\\\\//_

\\\\//\_

# Credits
- [clj-pune](https://github.com/clj-pune) people, especially [kapilreddy](https://github.com/kapilreddy), and [jaju](https://github.com/jaju) for critique while making ["pratham"](https://github.com/clj-pune/pratham), the precursor to this project.
- [adityaathalye](https://github.com/adityaathalye), [jysandy](https://github.com/jysandy), and [kapilreddy](https://github.com/kapilreddy) for course design, code reviews, critique, commits, and being the core teaching staff at the first edition of this workshop at IN/Clojure 2018.
- All the workshop participants, and the many Clojurists who generously donated their time to make it successful.
- [inclojure-org](https://github.com/inclojure-org) for being the umbrella under which this work happened.

- [clj-pune](https://github.com/clj-pune) people, especially [kapilreddy](https://github.com/kapilreddy), and [jaju](https://github.com/jaju) for critique while making ["pratham"](https://github.com/clj-pune/pratham), the precursor to this project.
- [adityaathalye](https://github.com/adityaathalye), [jysandy](https://github.com/jysandy), and [kapilreddy](https://github.com/kapilreddy) for course design, code reviews, critique, commits, and being the core teaching staff at the first edition of this workshop at IN/Clojure 2018.
- All the workshop participants, and the many Clojurists who generously donated their time to make it successful.
- [inclojure-org](https://github.com/inclojure-org) for being the umbrella under which this work happened.

## Copyright and License

Copyright 2017-2018 [IN/Clojure](http://inclojure.org/).
Copyright © 2017-2024 [IN/Clojure](http://inclojure.org/).

Distributed under the [MIT license](https://github.com/inclojure-org/clojure-by-example/blob/master/LICENSE).
5 changes: 5 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:paths ["src" "resources"],
:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/data.json {:mvn/version "0.2.6"}
enlive/enlive {:mvn/version "1.1.6"}
rewrite-clj/rewrite-clj {:mvn/version "0.6.1"}}}
13 changes: 0 additions & 13 deletions project.clj

This file was deleted.

66 changes: 66 additions & 0 deletions src/clojure_by_example/data/planets.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(ns clojure-by-example.data.planets)

(def target-planets
[{:pname "Mercury"
:mass 0.055
:radius 0.383
:moons 0
:gravity 0.378
:surface-pressure 0
:surface-temp-deg-c {:low -170 :high 449}
:rocky? true
:atmosphere {}} ; empty hash map means no atmosphere

{:pname "Venus"
:mass 0.815
:radius 0.949
:moons 0
:gravity 0.907
:surface-pressure 92
:surface-temp-deg-c {:low 465 :high 465}
:rocky? true
:atmosphere {:carbon-dioxide 96.45 :nitrogen 3.45
:sulphur-dioxide 0.015 :traces 0.095}}

{:pname "Earth"
:mass 1
:radius 1
:moons 1
:gravity 1
:surface-pressure 1
:surface-temp-deg-c {:low -89 :high 58}
:rocky? true
:atmosphere {:nitrogen 78.08 :oxygen 20.95 :carbon-dioxide 0.4
:water-vapour 0.10 :argon 0.33 :traces 0.14}}

{:pname "Mars"
:mass 0.107
:radius 0.532
:moons 2
:gravity 0.377
:surface-pressure 0.01
:surface-temp-deg-c {:low -125 :high 20}
:rocky? true
:atmosphere {:carbon-dioxide 95.97 :argon 1.93 :nitrogen 1.89
:oxygen 0.146 :carbon-monoxide 0.056 :traces 0.008}}

{:pname "Chlorine Planet"
:mass 2.5
:radius 1.3
:moons 4
:gravity 1.5
:surface-pressure 1
:surface-temp-deg-c {:low -42 :high 24}
:rocky? true
:atmosphere {:chlorine 100.0}}

{:pname "Insane Planet"
:mass 42
:radius 4.2
:moons 42
:gravity 10
:surface-pressure 420
:surface-temp-deg-c {:low 750 :high 750}
:rocky? false
:atmosphere {:sulphur-dioxide 80.0 :carbon-monoxide 10.0
:chlorine 5.0 :nitrogen 5.0}}])
Loading