288 lines
5.7 KiB
Plaintext
288 lines
5.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Class numero quatro"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Some small remarks"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Note on immutability"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"#'user/lst-2"
|
|
]
|
|
},
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(def lst [1 2 3 4 5 6 7 8])\n",
|
|
"\n",
|
|
"(defn times-2 [n]\n",
|
|
" (* 2 n))\n",
|
|
"\n",
|
|
"(def lst-2 (map times-2 lst))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Note on lazyness"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(0 2 4 6 8 10 12 14 16 18)"
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(def all-numbers (range))\n",
|
|
"(def all-even-numbers (map times-2 all-numbers))\n",
|
|
"(take 10 all-even-numbers)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Note on comments"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(def foo 2) ;; this is a comment. We call it a \"line comment\"\n",
|
|
"\n",
|
|
"(comment (println \"This is what we call a block comment, rarely used\"))\n",
|
|
"\n",
|
|
"\n",
|
|
"#_(println \"This is another type of block comment, more often used. (used by david nolen)\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Hyperfiddle\n",
|
|
"\n",
|
|
"This is the coolest thing ever! http://www.hyperfiddle.net/"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### `if` and `when`\n",
|
|
"\n",
|
|
"Sometime, we only want to do \"stuff\" when something happen. This is moment to use `if` and `when`"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"#'user/print-odd-or-even"
|
|
]
|
|
},
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(defn print-odd-or-even [n]\n",
|
|
" (if (odd? n)\n",
|
|
" (println n \" is odd\")\n",
|
|
" (println n \" is even\")))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Doing a web page!\n",
|
|
"\n",
|
|
"* Intro html tags...\n",
|
|
"* Let's do some html trash course\n",
|
|
"* https://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml_headers\n",
|
|
"* https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_intro\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(require '[clojupyter.misc.display :as display]) ;; https://github.com/clojupyter/clojupyter"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3>We can very easely print stuff from code</h3>"
|
|
]
|
|
},
|
|
"execution_count": 38,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(display/html \"<h3>We can very easely print stuff from code</h3>\") "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 43,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"#'user/html-h1"
|
|
]
|
|
},
|
|
"execution_count": 43,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(defn html-h1 [title])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"James Reeves made a fantastic, database, library for html called [hiccup](https://github.com/weavejester/hiccup)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3>hiccup is much better</h3>"
|
|
]
|
|
},
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(display/hiccup-html [:h3 \"hiccup is much better\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"#'user/hiccup-h1"
|
|
]
|
|
},
|
|
"execution_count": 45,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(defn hiccup-h1 [title])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Dodgeball data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(def dodgeball-data\n",
|
|
" [{:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
|
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
|
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
|
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}])\n",
|
|
" \n",
|
|
" \n",
|
|
" "
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Lein-Clojure",
|
|
"language": "clojure",
|
|
"name": "lein-clojure"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".clj",
|
|
"mimetype": "text/x-clojure",
|
|
"name": "clojure",
|
|
"version": "1.9.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|