Add `cons-of' signature constructor to HtDP languages.

This commit is contained in:
Mike Sperber 2010-09-22 11:31:24 +02:00
parent 593f8588fe
commit 7304c061e3
8 changed files with 33 additions and 7 deletions

View File

@ -63,6 +63,7 @@
signature : -> mixed one-of predicate combined
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
cons-of
Property
check-property for-all ==> expect expect-within expect-member-of expect-range)

View File

@ -45,6 +45,7 @@
signature : -> mixed one-of predicate combined
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
cons-of
Property
check-property for-all ==> expect expect-within expect-member-of expect-range)

View File

@ -46,6 +46,7 @@
signature : -> mixed one-of predicate combined
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
cons-of
Property
check-property for-all ==> expect expect-within expect-member-of expect-range)

View File

@ -49,6 +49,7 @@
signature : -> mixed one-of predicate combined
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
cons-of
Property
check-property for-all ==> expect expect-within expect-member-of expect-range)

View File

@ -49,6 +49,7 @@
signature : -> mixed one-of predicate combined
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
cons-of
Property
check-property for-all ==> expect expect-within expect-member-of expect-range)

View File

@ -223,14 +223,14 @@
(null empty
"the empty list")
(first ( (cons Y (listof X)) -> Y )
((beginner-first first) ( (cons Y (listof X)) -> Y )
"to select the first item of a non-empty list")
(car ( (cons Y (listof X)) -> Y )
((beginner-car car) ( (cons Y (listof X)) -> Y )
"to select the first item of a non-empty list")
(rest ((cons Y (listof X)) -> (listof X))
((beginner-rest rest) ((cons Y (listof X)) -> (listof X))
"to select the rest of a non-empty list")
((beginner-cdr cdr) ((cons Y (listof X)) -> (listof X))
"to select the rest of a non-empty list")
(cdr ((cons Y (listof X)) -> (listof X))
"to select the rest of a non-empty list")
(second ( (cons Z (cons Y (listof X))) -> Y )
"to select the second item of a non-empty list")

View File

@ -2882,7 +2882,8 @@
(provide Integer Number Rational Real Natural
Boolean True False
String Char Symbol Empty-list
Any Unspecific)
Any Unspecific
cons-of)
(define Integer (signature/arbitrary arbitrary-integer (predicate integer?)))
(define Number (signature/arbitrary arbitrary-real (predicate number?)))
@ -2909,6 +2910,9 @@
(define Unspecific (signature (predicate (lambda (_) #t))))
(define (cons-of car-sig cdr-sig)
(make-pair-signature car-sig cdr-sig))
; QuickCheck
(provide for-all ==>

View File

@ -16,7 +16,8 @@ namespace.
(require mzlib/list
mzlib/math
mzlib/etc)
mzlib/etc
deinprogramm/signature/signature)
(define-syntax (define-teach stx)
(syntax-case stx ()
@ -178,6 +179,18 @@ namespace.
(check-second 'cons a b)
(cons a b)))
(define-teach beginner car
(lambda (p) (checked-car p)))
(define-teach beginner first
(lambda (p) (checked-car p)))
(define-teach beginner cdr
(lambda (p) (checked-cdr p)))
(define-teach beginner rest
(lambda (p) (checked-cdr p)))
(define-teach beginner list*
(lambda x
(check-last 'list* x)
@ -382,6 +395,10 @@ namespace.
beginner-member?
beginner-remove
beginner-cons
beginner-car
beginner-cdr
beginner-first
beginner-rest
beginner-list*
beginner-append
intermediate-append