Advertisement
Pop-Ady

Rezolvare problema 1 [Lab. 3]

Mar 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.44 KB | None | 0 0
  1. #lang racket
  2. (define (uncurry->curry f)
  3.   (lambda (x)
  4.     (lambda (y)
  5.       (f x y))))
  6.  
  7. (define (combine L1 L2 f)
  8.   (foldl (λ (e A) (append A (map ((uncurry->curry f) e) L2))) '() L1))
  9.  
  10. (define (cartesian L1 L2)
  11.   (combine L1 L2 cons))
  12.  
  13. (combine '(2 3) '(4 8) +) ; '(6 10 7 11)
  14. (combine '(2) '(1 2 3 4 5) *) ; '(2 4 6 8 10)
  15. (cartesian '(1 2) '(a b c)) ; '((1 a) (1 b) (1 c) (2 a) (2 b) (2 c))
  16. (cartesian '(a) '(X Y)) ; '((a . X) (a . Y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement