Hi folks, I'm writing a stats library (I'm sure there is already one out there; this is a learning exercise), and I'm currently implementing Kendall's Tau-a. I've got my head wrapped part of the way around contracts, but not all the way. I'd like to be able to express the following:
(tau l m) - l is a non-empty list of numbers, all greater than 0 - m is a non-empty list of numbers, all greater than 0 - l and m are of the same length Here's a stub version that does the first two checks: (define/contract (tau l m) (-> (listof (and/c integer? (>/c 0))) (listof (and/c integer? (>/c 0))) number?) 300) (tau '(8) '(9)) ;; should succeed and does (tau '(8) '(9.0)) ;; should fail (element is not integer) => SUCCEEDS?? ;; ;; not implemented ;; (tau '(8) '(9 10)) ;; should fail -- different length lists I figured I'd let the 'integer?' failure go for a minute and focus on the missing criteria (lists are of equal length). First, I wanted to make sure that I had understood the ->i syntax, so I did this: (define/contract (tau l m) (->i ([list1 (listof (and/c integer? (>/c 0)))] [list2 (list1) (and/c (listof (and/c integer? (>/c 0))))]) [result (list1 list2) number?]) 300) Okay, good, that has the same results as the one above. Now let's try to get the 'equal length' criteria working. (define/contract (tau l m) (->i ([list1 (listof (and/c integer? (>/c 0)))] [list2 (list1) (and/c (listof (and/c integer? (>/c 0))) (equal? (length list1) (length list2)))]) [result (list1 list2) number?]) (begin (println "I was called") 300)) Result => t.rkt:21:79: list2: unbound identifier in module in: list2 Nope. Unsurprisingly, 'arg2' is not available inside its own binding. At this point I faffed around with implementing the check as a precondition or in the result function, and everything else I could think of, all to no avail. How do I do this? It feels like it shouldn't be this hard. On a separate question: How do I contribute to the docs? The contract docs are nearly silent on using preconditions and postconditions, Section 7.4, "A Thorough Example of Contracts" is anything but thorough, and the docs could stand to include more examples in general. I'd love to help future Racket students understand what's going on. Dave -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.