Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ;;Mascota
- ; nombre:simbolo
- ; edad:numero
- ; color:simbolo
- ; tipo: estructura tipo
- ; ;Tipo
- ; especie:simbolo
- ; patas:numero
- ; dientes:numero
- (define-struct mascota (nombre edad color tipo))
- (define-struct tipo (especie patas dientes))
- ;Listas
- (define lista1 (list (make-mascota 'Paolita 18 'castaño (make-tipo 'gato 4 43))
- (make-mascota 'juan 17 'naranja (make-tipo 'gato 3 10))
- (make-mascota 'diego 25 'negro (make-tipo 'cacatua 4 43))
- (make-mascota 'cardel 50 'verde (make-tipo 'unicornio 8 99))
- (make-mascota 'matecho 30 'sinpelo (make-tipo 'panda 4 30))
- ))
- ;Autor: Juan Felipe Arango Guzman
- ;Fecha: 25/09/20
- ;Contrato: filtrar-mascota: listamascotas, (mascota -> booleano) -> listamascotas
- ;Proposito: filtrar una lista de mascotas de acuerdo a las caracteristicas deseadas
- ;Ejemplos:
- ;Definicion:
- (define (filtrar-mascota lst f)
- (cond
- [(empty? lst) empty]
- [(f (first lst)) (cons (first lst) (filtrar-mascota (rest lst) f))]
- [else (filtrar-mascota (rest lst) f)]
- )
- )
- ;filtrar por nombre
- ;Contrato: filtrarnombre: listamascotas, symbol -> lista filtrada
- ;definicion:
- (define (filtrarnombre lst nombre)
- (filtrar-mascota lst (lambda (x)
- (equal? nombre (mascota-nombre x))))
- )
- ;filtrar por edad
- ;Contrato: mayor: listamascotas, numero -> lista filtrada
- ;definicion:
- (define (mayor lst num)
- (filtrar-mascota lst (lambda (x)
- (> (mascota-edad x) num)))
- )
- ;filtrar por especie
- ;Contrato: animal: lst, symbol -> lista filtrada
- ;definicion:
- (define (filespecie lst espe)
- (filtrar-mascota lst (lambda (x)
- (equal? (tipo-especie (mascota-tipo x)) espe)))
- )
- ;filtrar por dientes
- ;Contrato: animal: lst, numero -> lista filtrada
- ;definicion:
- (define (menordientes lst numdientes)
- (filtrar-mascota lst (lambda (x)
- (< (tipo-dientes (mascota-tipo x)) numdientes)))
- )
- ;filtrar por ojos y patas
- ;Contrato: animal: lst, symbol, numero -> lista filtrada
- ;definicion:
- (define (ojospatas lst ojos patas)
- (filtrar-mascota lst (lambda (x)
- (and (equal? (mascota-color x) ojos)
- (equal? (tipo-patas (mascota-tipo x)) patas))))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement