0
votes

I'm trying to run a program in racket using #lang plai-typed, but I keep getting the 'unbound identifier' errors

(define (get-fundef [n : symbol] [fds : (vector FunDefC)]) : FunDefC
  (cond [(empty? fds)
         (error 'get-fundef "reference to undefined function")]
        [(vector? fds)
         (cond [(equal? n (fdC-name (vector-ref fds 0))) (vector-ref fds 0)]
               [else (get-fundef n (vector-drop fds 1))])]))

When I run the same with 'listof' instead of 'vector' as input, adjusted to the list type, it works. With vectors I get:

'unbound identifier in module in: vector?'

Help?

1

1 Answers

1
votes

#lang plai-typed doesn't have a vector? function, for the same reason it doesn't have a list?, symbol?, or number? function: you don't need to check type of a value; the type annotations tell you.

If you meant to check whether the vector is empty or not, you could use (= 0 (vector-length fds)) and (< 0 (vector-length fds)).

But why do you want to use vectors? Lists tend to be a lot more convenient:

  • There are more utility functions for lists; in particular, filter would be helpful here.
  • Vectors are less convenient to recur over, since there's no vector-drop or vector-rest function. If you really want to iterate over a vector, you probably need to use an index.
  • Vectors are mutable, which you don't want unless you really need it.