Curry in the pattern

I have this function curry:

(define curry
(lambda (f) (lambda (a) (lambda (b) (f a b)))))

I think this is how (define curry (f a b)).

my purpose is to write a function consElem2Allusing currythat should work like

(((consElem2All cons) 'b) '((1) (2 3) (4)))
>((b 1) (b 2 3) (b 4))

I wrote this function in the usual way:

(define (consElem2All0 x lst) 
  (map (lambda (elem) (cons x elem)) lst))

but still don’t know how to convert it using curry. Can anybody help me?

early

bearzk

+6
source share
3 answers

You should start by reading about curry. If you do not understand what curry is, it can be very difficult to use ... In your case, http://www.engr.uconn.edu/~jeffm/Papers/curry.html can be a good one.

, Reduce Map ( ).

!

(define curry2 (lambda (f) (lambda (arg1) (lambda (arg2) (f arg1 arg2)))))
(define curry3 (lambda (f) (lambda (arg1) (lambda (arg2) (lambda (arg3) (f arg1 arg2 arg3))))))

:

(define mult (curry2 *))
(define double (mult 2))

(define add (curry2 +))
(define increment (add 1))
(define decrement (add -1))

/:

(define creduce (curry3 reduce))
(define cmap (curry2 map))

:

(define sum ((creduce +) 0))
(sum '(1 2 3 4)) ; => 10

(define product (creduce * 1))
(product '(1 2 3 4)) ; => 24

:

(define doubles (cmap double))
(doubles '(1 2 3 4)) ; => (2 4 6 8)

(define bump (cmap increment))
(bump '(1 2 3 4)) ; => (2 3 4 5)

, ...

+4

, , :

(define (cons a b) ...)

-, :

(define my-cons (curry cons))
((my-cons 'a) '(b c)) ; => (cons 'a '(b c)) => '(a b c)

, . curry3, 3- , - :

(define (consElem2All0 the-conser x lst) ...)

( , -, !)

:

(define consElem2All (curry3 consElem2All0))

curry3. , , , "", . :

(define (consElem2All0 the-conser)
  (lambda (x lst) ...something using the-conser...))
(define (consElem2All the-conser)
  (curry (consElem2All0 the-conser)))

, , , , . x cons, , ?...

+1
(define (consElem2All0 x lst) 
  (map ((curry cons) x) lst))
-1
source

All Articles