Add `cons-of' signature constructor to HtDP languages.
This commit is contained in:
parent
593f8588fe
commit
7304c061e3
|
@ -63,6 +63,7 @@
|
||||||
|
|
||||||
signature : -> mixed one-of predicate combined
|
signature : -> mixed one-of predicate combined
|
||||||
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
||||||
|
cons-of
|
||||||
Property
|
Property
|
||||||
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
signature : -> mixed one-of predicate combined
|
signature : -> mixed one-of predicate combined
|
||||||
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
||||||
|
cons-of
|
||||||
Property
|
Property
|
||||||
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
signature : -> mixed one-of predicate combined
|
signature : -> mixed one-of predicate combined
|
||||||
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
||||||
|
cons-of
|
||||||
Property
|
Property
|
||||||
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
signature : -> mixed one-of predicate combined
|
signature : -> mixed one-of predicate combined
|
||||||
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
||||||
|
cons-of
|
||||||
Property
|
Property
|
||||||
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
signature : -> mixed one-of predicate combined
|
signature : -> mixed one-of predicate combined
|
||||||
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
Number Real Rational Integer Natural Boolean True False String Symbol Char Empty-list Any
|
||||||
|
cons-of
|
||||||
Property
|
Property
|
||||||
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
check-property for-all ==> expect expect-within expect-member-of expect-range)
|
||||||
|
|
||||||
|
|
|
@ -223,13 +223,13 @@
|
||||||
(null empty
|
(null empty
|
||||||
"the empty list")
|
"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")
|
"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")
|
"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")
|
"to select the rest of a non-empty list")
|
||||||
(cdr ((cons Y (listof X)) -> (listof X))
|
((beginner-cdr cdr) ((cons Y (listof X)) -> (listof X))
|
||||||
"to select the rest of a non-empty list")
|
"to select the rest of a non-empty list")
|
||||||
|
|
||||||
(second ( (cons Z (cons Y (listof X))) -> Y )
|
(second ( (cons Z (cons Y (listof X))) -> Y )
|
||||||
|
|
|
@ -2882,7 +2882,8 @@
|
||||||
(provide Integer Number Rational Real Natural
|
(provide Integer Number Rational Real Natural
|
||||||
Boolean True False
|
Boolean True False
|
||||||
String Char Symbol Empty-list
|
String Char Symbol Empty-list
|
||||||
Any Unspecific)
|
Any Unspecific
|
||||||
|
cons-of)
|
||||||
|
|
||||||
(define Integer (signature/arbitrary arbitrary-integer (predicate integer?)))
|
(define Integer (signature/arbitrary arbitrary-integer (predicate integer?)))
|
||||||
(define Number (signature/arbitrary arbitrary-real (predicate number?)))
|
(define Number (signature/arbitrary arbitrary-real (predicate number?)))
|
||||||
|
@ -2909,6 +2910,9 @@
|
||||||
|
|
||||||
(define Unspecific (signature (predicate (lambda (_) #t))))
|
(define Unspecific (signature (predicate (lambda (_) #t))))
|
||||||
|
|
||||||
|
(define (cons-of car-sig cdr-sig)
|
||||||
|
(make-pair-signature car-sig cdr-sig))
|
||||||
|
|
||||||
; QuickCheck
|
; QuickCheck
|
||||||
|
|
||||||
(provide for-all ==>
|
(provide for-all ==>
|
||||||
|
|
|
@ -16,7 +16,8 @@ namespace.
|
||||||
|
|
||||||
(require mzlib/list
|
(require mzlib/list
|
||||||
mzlib/math
|
mzlib/math
|
||||||
mzlib/etc)
|
mzlib/etc
|
||||||
|
deinprogramm/signature/signature)
|
||||||
|
|
||||||
(define-syntax (define-teach stx)
|
(define-syntax (define-teach stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
|
@ -178,6 +179,18 @@ namespace.
|
||||||
(check-second 'cons a b)
|
(check-second 'cons a b)
|
||||||
(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*
|
(define-teach beginner list*
|
||||||
(lambda x
|
(lambda x
|
||||||
(check-last 'list* x)
|
(check-last 'list* x)
|
||||||
|
@ -382,6 +395,10 @@ namespace.
|
||||||
beginner-member?
|
beginner-member?
|
||||||
beginner-remove
|
beginner-remove
|
||||||
beginner-cons
|
beginner-cons
|
||||||
|
beginner-car
|
||||||
|
beginner-cdr
|
||||||
|
beginner-first
|
||||||
|
beginner-rest
|
||||||
beginner-list*
|
beginner-list*
|
||||||
beginner-append
|
beginner-append
|
||||||
intermediate-append
|
intermediate-append
|
||||||
|
|
Loading…
Reference in New Issue
Block a user