-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurrying.rkt
More file actions
52 lines (42 loc) · 802 Bytes
/
currying.rkt
File metadata and controls
52 lines (42 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#lang racket
(define (curry2 f)
(lambda(x)
(lambda(y)
(f x y))))
(define (curry3 f)
(lambda(x)
(lambda(y)
(lambda(z)
(f x y z)))))
(define (uncurry2 f)
(lambda (x y)
((f x) y)))
(define (uncurry3 f)
(lambda (x y z)
(((f x) y) z)))
; ((mult 2) 3)
;6
(define mult
(lambda (a)
(lambda (b)
(* a b))))
;(increase-all '(4 2 9 6) 2)
; '(6 4 11 8)
(define (increase-all lst delta)
(map (lambda (x) (+ x delta)) lst))
;; es mayor a?
;; no currificado
;> (greater? 10 30)
;#t
(define (greater? n x) (> x n))
; ((greater-curry? 10) 5)
; #f
(define (greater-curry? n)
(lambda (x) (> x n)))
; ((merge list 5 4) 3 2)
; '(5 4 3 2)
; ((merge list 1 2 3) 4 5 6)
;'(1 2 3 4 5 6)
(define merge
(lambda (f . c)
(lambda x (apply f (append c x)))))