File tree Expand file tree Collapse file tree 1 file changed +69
-0
lines changed
Roadmap/02 - FUNCIONES Y ALCANCE/clojure Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change
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)
You can’t perform that action at this time.
0 commit comments