Skip to content

Commit 64f5745

Browse files
committed
update tutorial for 2023
1 parent 58b9c32 commit 64f5745

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

content/guides/getting_started.adoc

+25-28
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ Now change the generated `project.clj` file to include the Typed Clojure checker
2626

2727
[source,clojure]
2828
----
29-
(defproject org.my-domain/my-project "1.0.0-SNAPSHOT"
30-
:dependencies [[org.clojure/clojure "1.10.3"]
31-
[org.typedclojure/typed.clj.checker "1.0.17"]]
29+
(defproject org.my-domain/my-project "0.1.0-SNAPSHOT"
30+
:dependencies [[org.clojure/clojure "1.11.1"]
31+
;; annotation macros like t/ann
32+
[org.typedclojure/typed.clj.runtime "1.1.5"]]
33+
:profiles {:dev {:dependencies [;; the full type checker, only needed at dev-time
34+
[org.typedclojure/typed.clj.checker "1.1.5"]]}}
3235
:repl-options {:init-ns org.my-domain.my-project})
3336
----
3437

@@ -37,7 +40,7 @@ Typed Clojure requires type annotations to check your code. Let's create a simpl
3740
[source,clojure]
3841
----
3942
(ns org.my-domain.my-project
40-
(:require [clojure.core.typed :as t]))
43+
(:require [typed.clojure :as t]))
4144
4245
(t/ann welcome-string [t/Str :-> t/Str])
4346
(defn welcome-string [a-name]
@@ -52,15 +55,10 @@ Now, we can check the namespace. Start a REPL and call https://api.typedclojure.
5255
[source,clojure]
5356
----
5457
$ lein repl
55-
Clojure 1.10.3
56-
org.my-domain.my-project=> (t/check-ns)
57-
Initializing core.typed ...
58-
Building core.typed base environments ...
59-
Finished building base environments
60-
"Elapsed time: 9154.355686 msecs"
61-
core.typed initialized.
58+
Clojure 1.11.1
59+
org.my-domain.my-project=> (t/check-ns-clj)
6260
Start checking org.my-domain.my-project
63-
Checked org.my-domain.my-project in 170.536377 msecs
61+
Checked org.my-domain.my-project in 32.836713 msecs
6462
:ok
6563
----
6664

@@ -70,7 +68,7 @@ Leave your REPL open---we're going to add a type error to the file and see what
7068
[source,clojure]
7169
----
7270
(ns org.my-domain.my-project
73-
(:require [clojure.core.typed :as t]))
71+
(:require [typed.clojure :as t]))
7472
7573
(t/ann welcome-string [t/Str :-> t/Str])
7674
(defn welcome-string [a-name]
@@ -79,11 +77,11 @@ Leave your REPL open---we're going to add a type error to the file and see what
7977
(welcome-string nil)
8078
----
8179

82-
Save the file and call https://api.typedclojure.org/latest/typed.clj.runtime/clojure.core.typed.html#var-check-ns[check-ns] again.
80+
Save the file and call https://api.typedclojure.org/latest/typed.clj.runtime/typed.clojure.html#var-check-ns-clj[check-ns-clj] again.
8381

8482
[source,clojure]
8583
----
86-
org.my-domain.my-project=> (t/check-ns)
84+
org.my-domain.my-project=> (t/check-ns-clj)
8785
Start checking org.my-domain.my-project
8886
Type Error (file:/Users/ambrose/Projects/typedclojure.org/example-projects/my-project/src/org/my_domain/my_project.clj:10:1)
8987
Function welcome-string could not be applied to arguments:
@@ -117,30 +115,29 @@ In Typed Clojure, `nil` is not a `String`. In most cases, `nil` must be specifie
117115
(t/ann welcome-string [(t/U nil t/Str) :-> t/Str])
118116
----
119117

120-
By the way, use https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/doc[doc] to find out more about the namespace-qualified types. Let's see what https://api.typedclojure.org/latest/typed.clj.runtime/clojure.core.typed.html#var-U[U] and `Str` mean.
118+
By the way, use https://api.typedclojure.org/latest/typed.clj.runtime/typed.clojure.html#var-doc-clj[doc-clj] to find out more about the namespace-qualified types. Let's see what `U` and `Str` mean.
121119

122120
[source,clojure]
123121
------------------------------
124-
org.my-domain.my-project=> (doc t/U)
125-
-------------------------
126-
clojure.core.typed/U
127-
(U type*)
128-
U represents a union of types
122+
org.my-domain.my-project=> (t/doc-clj t/U)
123+
Special type: typed.clojure/U
124+
U represents a union of types
125+
Forms: [(U type*)]
126+
129127
nil
130-
org.my-domain.my-project=> (doc t/Str)
131-
-------------------------
132-
clojure.core.typed/Str
133-
quote
134-
[Str]
135-
A string
128+
org.my-domain.my-project=> (t/doc-clj t/Str)
129+
Type alias typed.clojure/Str
130+
String
131+
Metadata:
132+
{:doc "A string", :forms '[Str], :file "typed/ann/clojure.cljc"}
136133
nil
137134
------------------------------
138135

139136
Ok, now since `welcome-string` allows `nil`, it should type check again (don't forget to save the file after updating the annotation!).
140137

141138
[source,clojure]
142139
------------------------------
143-
org.my-domain.my-project=> (t/check-ns)
140+
org.my-domain.my-project=> (t/check-ns-clj)
144141
Start checking org.my-domain.my-project
145142
Checked org.my-domain.my-project in 32.831593 msecs
146143
:ok
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
(defproject org.my-domain/my-project "0.1.0-SNAPSHOT"
2-
:dependencies [[org.clojure/clojure "1.10.3"]
3-
[org.typedclojure/typed.clj.checker "1.0.17"]]
2+
:dependencies [[org.clojure/clojure "1.11.1"]
3+
;; annotation macros like t/ann
4+
[org.typedclojure/typed.clj.runtime "1.1.5"]]
5+
:profiles {:dev {:dependencies [;; the full type checker, only needed at dev-time
6+
[org.typedclojure/typed.clj.checker "1.1.5"]]}}
47
:repl-options {:init-ns org.my-domain.my-project})

example-projects/my-project/src/org/my_domain/my_project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns org.my-domain.my-project
2-
(:require [clojure.core.typed :as t]))
2+
(:require [typed.clojure :as t]))
33

44
(t/ann welcome-string [(t/U nil t/Str) :-> t/Str])
55
(defn welcome-string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns org.my-domain.my-project-test
2+
(:require [clojure.test :refer [deftest is]]
3+
[typed.clojure :as t]))
4+
5+
(deftest type-check
6+
(is (t/check-ns-clj 'org.my-domain.my-project)))

0 commit comments

Comments
 (0)