Advertisement
cardel

FDP 22 Marzo 2

Mar 22nd, 2021
2,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.18 KB | None | 0 0
  1. ;.
  2.  
  3. (define-struct producto (nombre valor))
  4.  
  5. ;;Autor: Carlos A Delgado S.
  6. ;;Fecha: 22 de Marzo de 2021
  7. ;;Contrato: filtro: lista de productos, (producto,numero,(numero,numero->booleano)->booleano),(numero,numero->booleano) -> lista de productos
  8. (define (filtro lst f valor g)
  9.   (cond
  10.     [(empty? lst) empty]
  11.     [else
  12.      (local
  13.        (
  14.         (define primero (first lst))
  15.         (define resto  (filtro (rest lst) f valor g))
  16.         )
  17.        (cond
  18.          [(f primero valor g)  (cons primero resto)]
  19.          [else resto]
  20.          )
  21.        )
  22.     ]
  23.     )
  24.   )
  25.  
  26. ;;Diseñar filtros: mayor a un valor, menor a un valor y así ......
  27. (define (comparar-producto prod cant g)
  28.   (g (producto-valor prod) cant))
  29.  
  30.  
  31. ;(define (producto-cafe prod)
  32. ;  (symbol=? (producto-nombre prod) 'cafe))
  33.  
  34.  
  35. (define listaP
  36.   (list (make-producto 'cafe 4000)
  37.         (make-producto 'soya 3000)
  38.         (make-producto 'ajo 200)
  39.         (make-producto 'cafe 5000)
  40.         (make-producto 'cafe 6000)
  41.         (make-producto 'arepa 500)))
  42.  
  43. (filtro listaP comparar-producto 3000 >)
  44. (filtro listaP comparar-producto 3000 <)
  45. (filtro listaP comparar-producto 5000 =)
  46. ;(filtro listaP producto-cafe)
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement