Renato
unread,Apr 17, 2009, 4:15:26 PM4/17/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to HTDP Brasil
Então, estou numa parte do HTDP onde passamos funções como parametros
por exemplo:
;; Exercise 21.2.2. Use map to define the following functions:
;; 1. convert-euro, which converts a list of U.S. dollar amounts into
;; a list of euro amounts based on an exchange rate of 1.22 euro for
each dollar
;; 2. convertFC, which converts a list of Fahrenheit measurements to a
list of Celsius measurements;
;; (define (map f lon)
;; (cond
;; [(empty? lon) empty]
;; [else (cons (f (first lon))
;; (map f (rest lon)))]))
;; convert-euro-from-map : (listof numbers) -> (listof numbers)
(define (convert-euro-from-map lon)
(map convert-euro lon))
;; convert-euro : number -> number
(define (convert-euro number)
(* 1.22 number))
;; convert-fahrenheit-from-map : (listof numbers) -> (listof numbers)
(define (convert-fahrenheit-from-map lon)
(map convert-euro lon))
;; convert-euro : number -> number
(define (convert-fahrenheit number)
(* 1.8 number))
Como da pra ver, utilizo "f" para passar uma função como parametro
dentro da construção de uma lista:
;; (define (map f lon)
;; (cond
;; [(empty? lon) empty]
;; [else (cons (f (first lon)) <--------
;; (map f (rest lon)))])) <--------
;; convert-euro-from-map : (listof numbers) -> (listof numbers)
(define (convert-euro-from-map lon)
(map convert-euro lon))
Agora no exercicio 21.2.3, tenho que passar como parametro uma função
que vai fazer a validação de uma condicional.
Exercise 21.2.3. Here is the version of filter that DrScheme
provides:
;; filter : (X -> boolean) (listof X) -> (listof X)
;; to construct a list of X from all those items on alon
;; for which predicate? holds
(define (filter predicate? alon)
(cond
[(empty? alon) empty]
[else (cond
[(predicate? (first alon)) <---------------
(cons (first alon) (filter predicate? (rest alon)))]
<---------------
[else (filter predicate? (rest alon))])])) <------------
Use filter to define the following functions:
1. eliminate-exp, which consumes a number, ua, and a list of toy
structures (containing name and price) and produces a list of all
those descriptions whose price is below ua;
2. recall, which consumes the name of a toy, called ty, and a list
of names, called lon, and produces a list of names that contains all
components of lon with the exception of ty;
3. selection, which consumes two lists of names and selects all
those from the second one that are also on the first.
Simplesmente não to conseguindo pensar criativamente com relação a
isso, eu ja fiz umas ideias rodarem, mas elas nao fazem o que
realmente é pedido.
I need air support, can you engage?
Valeu raça!
Abraço!