18. (recursividad f xs #{})))
=> (cfilter (fn [x] (pos? x))#{10 -20 30})
#{30 10}
(defn smap [f xs]
(letfn [(recursividad [g ys zs]
(if (empty? ys)
zs
(recursividad g
(rest ys)
(str zs (g (first ys)))
)))]
(recursividad f xs "")))
(defn en-mayuscula [c] ({a A e E i I o O u U} c))
(defn en-mayusculas [c]
(let [mayusculas {a A e E i I o O u U} ]
(if (nil? (mayusculas c))
c
(mayusculas c))))
(smap en-mayuscula "aaaeee iiiooouuu")
AAAEEEIIIOOOUUU
=> (smap en-mayusculas "aa ee")
AA EE
28. => (let [x 10 y 20]
(+ x y))
30
=> (let [ a 10 b 20 c 30]
(* (+ a a) (+ b b) (+ c c))
)
48000
=> (let [x [ 10 20 30]
y [ 40 50 60]]
(+ (first x) (first y))
)
50
=> (let [x [10 20]
y [ 30 40]]
{:x x :y y})
{:x [10 20], :y [30 40]}
=> (let [x [50 60 70]
y (first x)] x)
[50 60 70]
=> (let [x [50 60 70]
y (first x)] y)
50
=> (let [x [ 50 60 70]
y [10 20 30]]
{:x x :y y :first-x (first x) :first-y (first y)})
{:x [50 60 70],
:y [10 20 30],
:first-x 50,
:first-y 10}
=> (let [a (+ 2 3)
b (* 2 3)
c (+ a b)]
{:a a :b b :c c})
{:a 5, :b 6, :c 11}
=> (let [x [ 50 60 70]
y [10 20 30]]
{:x x :y y :first-x (first x) :first-y (first y)})
{:x [50 60 70],
:y [10 20 30],
:first-x 50,
:first-y 10}
29. => (let [a true b true c true]
(and a b c))
true
=> ((fn [x]
(let [a 10 b 20 x 30]
(+ a b x)))24)
60
=> ((fn [x]
(let [a 10 b 20 c 30]
(+ a b x)))24)
54
=> (if false
(let [x 10]
(* 2 x))
(let [x 20]
(* 5 x)))
100
((fn [x]
(if (>= x 0)
(let [ y 1]
(* y x))
(let [y -1]
(* y x))))
-65)
65
=> (let [x -4]
(if (>= x 10)
(let [y (* x x)]
y)
(let [ y ( + x x)]
y)))
-8
(let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))]
(f ( g 5)))
30
//aplicar a f con el resultado de g de 5
30. => (let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))
h (f (g 7))]
h)
42
=> (let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))
h (f (g 7))
i (fn [x] {:resultado-final x})]
(i h) )
{:resultado-final 42}
recursividad---
=> ((fn [x]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g 0 x 0 0))) 5)
15
=> ((fn [x y]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g x y x x))) 0 5)
15
=> ((fn [n] ((fn [x y]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g x y x x))) 0 n)) 5)
15
=> ((fn [x y]
(letfn [ (g [ ei ef c a ]
(if (== ei ef)
a
(g (inc ei) ef c(+ a c))))]
(g 0 x y 0))) 5 20)
100
=> (rest [ 10 20 30])
32. => (let [x 10 y 20]
(+ x y))
30
=> (let [ a 10 b 20 c 30]
(* (+ a a) (+ b b) (+ c c))
)
48000
=> (let [x [ 10 20 30]
y [ 40 50 60]]
(+ (first x) (first y))
)
50
=> (let [x [10 20]
y [ 30 40]]
{:x x :y y})
{:x [10 20], :y [30 40]}
=> (let [x [50 60 70]
y (first x)] x)
[50 60 70]
=> (let [x [50 60 70]
y (first x)] y)
50
=> (let [x [ 50 60 70]
y [10 20 30]]
{:x x :y y :first-x (first x) :first-y (first y)})
{:x [50 60 70],
:y [10 20 30],
:first-x 50,
:first-y 10}
=> (let [a (+ 2 3)
b (* 2 3)
c (+ a b)]
{:a a :b b :c c})
{:a 5, :b 6, :c 11}
=> (let [x [ 50 60 70]
y [10 20 30]]
{:x x :y y :first-x (first x) :first-y (first y)})
{:x [50 60 70],
:y [10 20 30],
:first-x 50,
:first-y 10}
33. => (let [a true b true c true]
(and a b c))
true
=> ((fn [x]
(let [a 10 b 20 x 30]
(+ a b x)))24)
60
=> ((fn [x]
(let [a 10 b 20 c 30]
(+ a b x)))24)
54
=> (if false
(let [x 10]
(* 2 x))
(let [x 20]
(* 5 x)))
100
((fn [x]
(if (>= x 0)
(let [ y 1]
(* y x))
(let [y -1]
(* y x))))
-65)
65
=> (let [x -4]
(if (>= x 10)
(let [y (* x x)]
y)
(let [ y ( + x x)]
y)))
-8
(let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))]
(f ( g 5)))
30
//aplicar a f con el resultado de g de 5
34. => (let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))
h (f (g 7))]
h)
42
=> (let [f (fn [x] (* 2 x))
g (fn [x] (* 3 x))
h (f (g 7))
i (fn [x] {:resultado-final x})]
(i h) )
{:resultado-final 42}
recursividad---
=> ((fn [x]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g 0 x 0 0))) 5)
15
=> ((fn [x y]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g x y x x))) 0 5)
15
=> ((fn [n] ((fn [x y]
(letfn [ (g [ ei ef i a ]
(if (> i ef)
a
(g ei ef (inc i) (+ a i))))]
(g x y x x))) 0 n)) 5)
15
=> ((fn [x y]
(letfn [ (g [ ei ef c a ]
(if (== ei ef)
a
(g (inc ei) ef c(+ a c))))]
(g 0 x y 0))) 5 20)
100
=> (rest [ 10 20 30])