cours  |  td  |  examens  |  doc  |  liens  |  horaires
 Scheme

Université de Caen - UFR de Sciences
Deug MIAS-MASS
Marc Chemillier

Scheme - TD n° 4
15 mars 2000

Fonctions




  • Exercices : (1h1/2)

    1. Soit la fonction :
      (define (truc l1 l2)
        (cons (cons (car l1) (cdr l2)) (cons (car l2) (cdr l1))))
      Evaluer :
      > (truc '(1 b c) '(a 2 3)) 
      ((1 2 3) a b c)
      
      > (truc '(the voiture) '(la car)) 
      ((the car) la voiture)
      
      > (truc '(ja ca va) '(oui es geht)) 
      ((ja es geht) oui ca va)
      
    2. Faire une fonction (reverse3 l) qui inverse une liste à trois éléments.
      (define (reverse3 l)
        (list (caddr l) (cadr l) (car l)))
      
    3. Faire une fonction (permut3 l) qui donne la liste des permutations d'une liste à trois éléments.
      (define (permut3 l)
          (let ((a (car l)) (b (cadr l)) (c (caddr l)))
            (list (list a b c) (list b c a) (list c a b)
      	    (list b a c) (list a c b) (list c b a))))
      
    4. Soit les fonctions :
      (define (f x) (x x)) 
      (define (g y) y)
      Evaluer :
      > (g g) 
      #<procedure:g>
      
      > (g f) 
      #<procedure:f>
      
      > (f g) 
      #<procedure:g>
      
      > (f f) 
      ... pas de réponse !
      
    5. Soit la fonction :
      (define (truc a b c d e f)
        (if (= a 0) (list a b c d e f) (truc b c d e f a)))
      Evaluer (Partiel 94) :
      > (truc 2 1 0 8 9 3) 
      (0 8 9 3 2 1)
      
      > (truc 2 9 7 8 5 1) 
      ... pas de réponse !
      
    6. Soit la fonction :
      (define (f x) 
        (if (< x 1) 0 (f (- (log x) 1))))
      Evaluer :
      > (f 1) 
      0
      
      > (f 0) 
      0
      
      > (f 100) 
      0
      

  • Avec machines : (1h1/2) Jeu du nombre mystérieux


    cours  |  td  |  examens  |  doc  |  liens  |  horaires
     Scheme