#lang racket ;; folositi background expansion (+ o apăsare pe Check Syntax) pentru a vedea legarile (define (f a b) (if a b (λ (a c) ; λ cu Ctrl-\ (cons (a b)) ))) ; a și b parametri formali (define f2 (lambda (a b) (+ a b))) ; 1 și 2 parametri actuali (f2 1 2) (define filter-even (λ (L) (if (null? L) '() (let ((rest (filter-even (cdr L)))) (if (even? (car L)) (cons (car L) rest) rest ))))) ; (append (if (even? (car L)) (list (car L)) '()) rest) (define a 2) (define b 1) (let* ( (b a) (c (+ a b)) ) (+ b c) ) (define y (λ (flag) (if flag #t (+ x 1)))) (y #t) (define x 5) (y #f) (display '------) ;; folositi Debug si step pentru a investiga cum evolueaza evaluarea (define fEager (λ (a b c) (if a b c))) (fEager (+ 1 2) (+ 2 3) (+ 3 4)) ; evaluare aplicativă (if (+ 1 2) (+ 2 3) (+ 3 4)) ; evaluare leneșă (funcție nestrictă) (and #f something) (define (fact1 n) (if (= n 1) 1 (* n (fact1 (- n 1))) )) (fact1 3) (define (fact-tail-aux n rezultat) (if (= n 1) rezultat (fact-tail-aux (- n 1) (* n rezultat)) )) (define (fact-tail n) (fact-tail-aux n 1)) (fact-tail 3) (define (rev L) (if (null? L) '() (append (rev (cdr L)) (list (car L))) )) (rev '(1 2 3 4 5)) (define (rev-t L Res) (if (null? L) Res (rev-t (cdr L) (cons (car L) Res)))) (rev-t '(1 2 3 4 5) '()) (define (cart1-aux m1e m2) (if (null? m2) '() (cons (cons m1e (car m2)) (cart1-aux m1e (cdr m2))))) (define (cart1 m1 m2) (if (null? m1) '() (append (cart1-aux (car m1) m2) (cart1 (cdr m1) m2)) )) (cart1 '(1 2 3) '(a b)) (define (cart2-aux m1 m2 m2-copy) (cond ((null? m1) '()) ((null? m2) (cart2-aux (cdr m1) m2-copy m2-copy)) (#t (cons (cons (car m1) (car m2)) (cart2-aux m1 (cdr m2) m2-copy))) )) (define (cart2 m1 m2) (cart2-aux m1 m2 m2)) (cart2 '(1 2 3) '(a b))