Reputation: 1203
I saw a question which asked about a contract of a method in a pet language known as let.The language is not important but does contract means that things that the method takes as an argument and its value after evaluating?
(define extend-env*
(lambda (syms vals old-env)
(if (null? syms)
old-env
(extended-env-record
(car syms)
(car vals)
(extend-env* (cdr syms)
(cdr vals)
old-env)))))
So in here the method takes a symbol a value and an environment and I think it produces a new environment. Does that mean contract for this method is Identifier(Variable),Value,Environment = Environment ?
Upvotes: 1
Views: 80
Reputation: 31147
Your functions starts like this:
(lambda (syms vals old-env) ...)
Here sym
stand for symbol and thus syms
stands for a list of syms
aka a list of symbols
. In the same manner vals
stands for a list of values
. Finally old-env
is an environment.
This covers the input to the function. To confirm that syms
is supposed to be a list of symbols, look at how syms
is used in the body. We see thee uses: (null? syms)
, (car syms)
, and, (cdr syms)
. This means we guess correctly.
To see type of the output, look for the expression(s) that produce return values.
The simplest is old-env
which is an environment. If the function always returns the same type of value, we have determined that the output is an environment. It best to check that the other return expressions also return environments though.
To sum up: the contract seen from Racket is:
extend-env* : list-of-symbols list-of-values environment -> environment
Now in your program the symbols represent identifiers, so you could also write:
extend-env* : list-of-identifiers list-of-values environment -> environment
if you document that identifiers are represented as symbols.
Upvotes: 1