Skip to content

Commit 47b174f

Browse files
committed
Reto mouredev#2 - Clojure
1 parent 8d87705 commit 47b174f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
(defn without-return [a b]
2+
(println (+ a b)))
3+
4+
(defn with-return [c d]
5+
(+ c d))
6+
7+
(defn without-parameters []
8+
(println "This is a function without parameters"))
9+
10+
(defn with-parameters [e]
11+
(println "This is the parameter to print: " e))
12+
13+
(defn inner-function []
14+
(defn second-function []
15+
(println "hello"))
16+
(second-function))
17+
18+
19+
(defn recursive [g]
20+
(if (not= g 10)
21+
(do
22+
(println g)
23+
(recursive (inc g)))
24+
(println "final")))
25+
26+
(defn local [w]
27+
(let [local 10]
28+
(println (+ w local))))
29+
30+
31+
32+
; Extra
33+
(defn extra [text1 text2]
34+
(doseq [item (range 1 100)]
35+
(cond
36+
(and (= (mod item 3) 0) (= (mod item 5) 0)) (println item text1 text2)
37+
(= (mod item 5) 0) (println item text2)
38+
(= (mod item 3) 0) (println item text1)
39+
:else (println item))))
40+
41+
42+
(do
43+
(without-return 2 2)
44+
(println (with-return 2 2))
45+
46+
(without-parameters)
47+
(with-parameters "hello")
48+
49+
(inner-function)
50+
(recursive 1)
51+
52+
(println (count [1 2 3]))
53+
54+
(println local)
55+
(local 2)
56+
57+
(extra "one" "two"))
58+
59+
(def global-variable 10)
60+
61+
(defn more-example-local []
62+
(let [local-variable 5]
63+
(println "Local variable:", local-variable))
64+
(println "Global variable:", global-variable))
65+
66+
; Calling the function
67+
(more-example-local)
68+
69+
(println "Global variable outside the function:", global-variable)

0 commit comments

Comments
 (0)