Reputation: 110
i'm trying to make predicates functions
datatype definition
(define-datatype expression expression?
(const-exp (num number?))
(var-exp (var symbol?))
(zero?-exp (exp1 expression?))
(diff-exp (exp1 expression?)
(exp2 expression?)))
if argument is #2(struct:const-exp 7) then print #t
if argument is #2(struct:var-exp x) then print #f
(define const-exp? ... )
it would be honor if you help me
Upvotes: 0
Views: 1084
Reputation: 18917
So my guess is that you are studying Essentials of Programming Languages and probably use Racket as your environment.
If that is true, you should probably use cases here:
(define (const-exp? e)
(cases expression e
(const-exp (num) #t)
(else #f)))
then
> (const-exp? (const-exp 7))
#t
> (const-exp? (var-exp 'x))
#f
Upvotes: 2