On this page:
all
top
up

8Data DefinitionsπŸ”— i

syntax

( defdata nametype)

type = singleton
| simple-type
| (enum lst-expr)
| (oneof typetype)
| (range numeric-typerange-constraints)
| (list type...)
| (cons typetype)
| (listof type)
| (record (field-name. type)...)
simple-type = all
| symbol
| string
| tl
| numeric-type
numeric-type = rational
| nat
| pos
range-constraints = (num-exprlt_ltnum-expr)
| (num-exprlt_)
| (_ltnum-expr)
lt = <
| <=
Defines the function namep as a recognizer for the given type.

Singletons:
> (defdata one1)
> (onep1)

t

List Types:
> (defdata natlist(listof nat ))
> (natlistpnil )

t

> (natlistp(list 2358))

t

> (natlistp(list 23-58))

nil

type

all

type

( enum lst-expr)

> (defdata traffic-light(enum (list 'red'yellow'green)))
> (traffic-lightp'red)

t

> (traffic-lightp'green)

t

> (traffic-lightp'blue)

nil

type

( oneof type...)

> (defdata intstr(oneof integer string ))
> (intstrp5)

t

> (intstrp-2)

t

> (intstrp"oconto")

t

> (intstrp'watermelon)

nil

> (intstrp"watermelon")

t

> (defdata spiral(oneof nil (cons spiralspiral)))
> (spiralpnil )

t

> (spiralp(cons nil nil ))

t

> (spiralp(cons (cons nil (cons nil nil ))nil ))

t

> (spiralp(cons (cons (cons nil (cons nil nil ))
(cons (cons nil (cons nil nil ))nil ))))

t

> (spiralp(cons (cons nil (cons "watermelon"nil ))nil ))

nil

type

( range numeric-typerange-constraints)

numeric-type = rational
| integer
| nat
| pos
range-constraints = (num-exprlt_ltnum-expr)
| (num-exprlt_)
| (_ltnum-expr)
lt = <
| <=
> (defdata probability(range rational(0<= _<= 1)))
> (probabilityp1/2)

t

> (probabilityp2)

nil

> (probabilityp0)

t

> (probabilityp1)

t

> (defdata big-nat(range integer(24601< _)))
> (big-natp4)

nil

> (big-natp3827)

nil

> (big-natp13372462)

t

type

( record (field-name. type)...)

> (defdata fullname
(record (first . string )(last. string )))
> (defconst *x*(fullname"David""Smith"))
> *x*

(fullname "David" "Smith")

> (fullnamep*x*)

t

> (fullnamep"David")

nil

> (fullname-first*x*)

"David"

> (fullname-last*x*)

"Smith"

> (equal *x*(fullname"David""Smith"))

t

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /