plragde
2019-5-8 11:29:00

The definition of add-element you have given does not match its contract. It looks like the contract specifies two parameters (though your notation is a bit inconsistent, and you might think about that as well) but your implementation only has one parameter. I think if you are careful about your data definition and then use it properly in the design recipe, you might see where you are going wrong.


diallo.ms
2019-5-8 13:31:11

ok, I’ll work on it. Thanks !


diallo.ms
2019-5-8 15:38:27

@plragde @dan153 Hello,

I “think” I finally understand my confusions:

  1. My interpretation of the data definition was ~wrong~ not the right one:
; A set is a function:
; A [Set X] is [X -> Boolean]
; Interpretation: if s is a set and x an element, (s x) produces #t if x belongs to s, ; #f otherwise.
; *MEANS is a given element in the set ? It is preferable to: can I add the  ;element to the set ?* (this "flawed" interpretation led me to thinking about ;storing elements in sets).
; (Strange how the brain can sometimes go astray...)


; Number -> Boolean
; Set of even numbers.
(check-expect (even-numbers 5) #f)
(check-expect (even-numbers 8) #t)

(define even-numbers
  (lambda (n) (even? n)))


; [Set X] X -> [Set X]
; Adds an element elt to a set s.
(check-expect [(add-element even-numbers 5) 5] #f)
(check-expect [(add-element even-numbers 5) 6] #f)
(check-expect [(add-element even-numbers 6) 6] #t)
(check-expect [(add-element even-numbers 6) 5] #f)

(define (add-element s elt)
  (lambda (x) (and (equal? x elt)
                  (s x))))
  1. My understanding of the purpose of lambdas is not as good as I thought it was. I have to rework the chapter.

Thank you all !


plragde
2019-5-8 15:57:55

@diallo.ms Good! In your defence, lambdas have diverse uses, and it takes some experience to realize just how much one can do with them.


benjamin.boles
2019-5-8 16:56:44

@benjamin.boles has joined the channel