>> I have a fairly simple question on how the 'null?' expression >> should work. The rule for it that is given in the book makes it look like >> it should only attempt anything when given a list and send an error >> otherwise. If this is the case, then null?(2) should be an error, >> null?(list(1,2)) should be false and the only way it is true is >> null?(emptylist) correct??? Not quite. The following expressions should also return a true value: let x = emptylist in null?(x) (proc(x : listof int)null?(x) emptylist) let x = list(1) in null?(cdr(x)) or any of the infinitely many ways in which an empty list could be passed as the argument to null? .
A student wrote:
> I have my type checker working well, but my interpreter seems to get
> "confused" sometimes when parsing syntax.. This seems rather strange and
> I'm not sure why it's happening. Has anyone had similiar problems or any
> advice about what might be going on? An example is illustrated below..
>
> > (scan&parse "emptylist")
> (a-program (emptylist-exp))
> > (run "emptylist")
> () ; as expected
>
> > (scan&parse "cons(1,emptylist)")
> (a-program (cons-exp (lit-exp 1) (emptylist-exp)))
> > (run "cons(1,emptylist)")
> ((lit-exp 1) emptylist-exp) ; what's this?
>
> It must have something to do with the way I'm representing the emptylist,
> right? Should emptylist just be a list of nothing or a separate type
> altogether? But if it's just a list of nothing, how can type be stored and
> later determined? Whew... Thnx for any help/advice :-)
And another student replied:
I think you forgot to use eval-expression in your cons-exp interpreter. You
should write it like this:
(cases expression exp
.....................
(cons-exp (exp1 exp2)
(cons (eval-expression exp1 env)
(...)))
.....)
>> Dear Professor Wand, >> In the way that i designed my code for lists, if i say: >> (type-check "let true = zero?(0) in list(1,true)") >> I get: >> Error reported by check-equal-type!: >> Types didn't match: int != bool in >> (true-exp) >> Is this error message good enough or i should i give another type of >> error. Yes, that is exactly the kind of message you should be producing.
>> In type checker part, should car and cdr take emptylist as other >> expressions, or they should rise an error? >> for example: >> car(emptylist) >> Should this have a type or should it be an error Taking the car or cdr of the empty list is a non-type error. So saying TypeOf( car(emptylist), tenv) = t is a correct prediction for any t. But at runtime it should raise an error. The test item or items for this example should reflect this behavior.
>> What about the list operator? >> list(emptylist) >> the result should be : (list (list t007)) >> is that right? Yes.
> Are we expected to modify sloppy to expval to handle our > list-representation? Yes.
Last modified: Tue Oct 27 16:10:54 -0400 2009