Advertisement
JuanFelipeArango28

Untitled

Sep 25th, 2020
1,791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.33 KB | None | 0 0
  1. ; ;;Mascota
  2. ; nombre:simbolo
  3. ; edad:numero
  4. ; color:simbolo
  5. ; tipo: estructura tipo
  6. ; ;Tipo
  7. ; especie:simbolo
  8. ; patas:numero
  9. ; dientes:numero
  10.  
  11.  
  12. (define-struct mascota (nombre edad color tipo))
  13. (define-struct tipo (especie patas dientes))
  14.  
  15. ;Listas
  16. (define lista1 (list (make-mascota 'Paolita 18 'castaño (make-tipo 'gato 4 43))
  17.                      (make-mascota 'juan 17 'naranja (make-tipo 'gato 3 10))
  18.                      (make-mascota 'diego 25 'negro (make-tipo 'cacatua 4 43))
  19.                      (make-mascota 'cardel 50 'verde (make-tipo 'unicornio 8 99))
  20.                      (make-mascota 'matecho 30 'sinpelo (make-tipo 'panda 4 30))
  21.                      ))
  22.  
  23. ;Autor: Juan Felipe Arango Guzman
  24. ;Fecha: 25/09/20
  25. ;Contrato: filtrar-mascota: listamascotas, (mascota -> booleano) -> listamascotas
  26. ;Proposito: filtrar una lista de mascotas de acuerdo a las caracteristicas deseadas
  27. ;Ejemplos:
  28. ;Definicion:
  29. (define (filtrar-mascota lst f)
  30.   (cond
  31.     [(empty? lst) empty]
  32.     [(f (first lst)) (cons (first lst) (filtrar-mascota (rest lst)  f))]
  33.     [else (filtrar-mascota (rest lst) f)]
  34.     )
  35.   )
  36. ;filtrar por nombre
  37. ;Contrato: filtrarnombre: listamascotas, symbol -> lista filtrada
  38. ;definicion:
  39. (define (filtrarnombre lst nombre)
  40.   (filtrar-mascota lst (lambda (x)
  41.                      (equal? nombre (mascota-nombre x))))
  42.   )
  43. ;filtrar por edad
  44. ;Contrato: mayor: listamascotas, numero -> lista filtrada
  45. ;definicion:
  46. (define (mayor lst num)
  47.   (filtrar-mascota lst (lambda (x)
  48.                          (> (mascota-edad x) num)))
  49.   )
  50. ;filtrar por especie
  51. ;Contrato: animal: lst, symbol -> lista filtrada
  52. ;definicion:
  53. (define (filespecie lst espe)
  54.   (filtrar-mascota lst (lambda (x)
  55.                          (equal? (tipo-especie (mascota-tipo x)) espe)))
  56.   )
  57. ;filtrar por dientes
  58. ;Contrato: animal: lst, numero -> lista filtrada
  59. ;definicion:
  60. (define (menordientes lst numdientes)
  61.   (filtrar-mascota lst (lambda (x)
  62.                          (< (tipo-dientes (mascota-tipo x)) numdientes)))
  63.   )
  64. ;filtrar por ojos y patas
  65. ;Contrato: animal: lst, symbol, numero -> lista filtrada
  66. ;definicion:
  67. (define (ojospatas lst ojos patas)
  68.   (filtrar-mascota lst (lambda (x)
  69.                          (and (equal?  (mascota-color x) ojos)
  70.                               (equal? (tipo-patas (mascota-tipo x)) patas))))
  71.   )
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement