PasteRack.org
Paste # 93794
2022-11-21 18:17:55

Fork as a new paste.

Paste viewed 1421 times.


Embed:

  1. #lang racket
  2.  
  3. ;;;;  =========================================================================
  4. ;;;;
  5. ;;;;  Author: Claudine WEBER
  6. ;;;;  Student ID: 22015228
  7. ;;;;  Last updated: Novembre 20th 2022
  8. ;;;;  Homework 2
  9. ;;;;
  10. ;;;;  =========================================================================
  11.  
  12. (import (scheme base) (pfa utilities))
  13.  
  14. ; Pour de petits tests unitaires.
  15. (#%require schemeunit)
  16.  
  17. (define (create-account init owner authorised-people)
  18.   (let ((historique '(list created init)))
  19.     (list init owner (list authorised-people))
  20.     ;(balance init)
  21.  
  22.  ;     (let*
  23. ;          (balance (
  24. ;             (lambda (amount)
  25. ;               (and amount
  26. ;                    (>= amount
  27. ;       (cdr (assq 'additional-account min-dest-alist)))
  28. ;   amount))
  29. ;             )
  30. ;        (dest-alist
  31. ;         (list
  32. ;          (cons 'current-account init)
  33. ;          (withdrawal
  34. ;           (lambda (amount from)
  35. ;             (let ((association (assq from dest-alist)))
  36. ;               (and association
  37. ;                    (let* ((balance (cdr association))
  38. ;                           (new-balance-presumed (- balance amount)))
  39. ;                      (and (>= new-balance-presumed
  40. ;                               (cdr (assq from min-dest-alist)))
  41. ;                           (begin
  42. ;                             (set-cdr! association
  43. ;                                       new-balance-presumed)
  44. ;                             new-balance-presumed))))))))
  45.   ;      )
  46.              ;;
  47.              (lambda (log)
  48.                (cond
  49.                 ((eq? log 'name) (lambda () owner))
  50.                 ((eq? log 'balance (lambda () init))
  51.                 ((eq? log 'get))
  52.                 ((eq? log 'withdrawal) )
  53.         ))
  54. )
  55.    )
  56. )
  57.  
  58. ; Tests
  59. ; J'ai repris et complété les tests proposés dans l'énoncé du DM2.
  60.  
  61. (define Sulitzer-account (create-account 500 'Sulitzer '(Ewa)))
  62. (writeln/return Sulitzer-account)
  63. ;(writeln/return ((Sulitzer-account 'name)))
  64. (writeln/return ((Sulitzer-account 'balance)))
  65. ;((Sulitzer-account 'balance) 'Ewa)
  66. ;((Sulitzer-account 'get) 100)
  67. ;((Sulitzer-account 'withdrawal) 1200 'Sulitzer)
  68. ;((Sulitzer-account 'withdrawal) 200 'Sulitzer)
  69. ;((Sulitzer-account 'log) 'Sulitzer)

=>