1
votes

The following line in my code is giving me an unbound identifier error.

((symbol<? x (car l)) #f)

can anybody please explain to me why i am getting this error and how I could resolve it.

Here's the whole code:

; tests membership in ordered list of symbols

(define (member? x l)
 (cond

   ((null? l) #f)
   ((symbol=? x (car l)) #t)
   ((symbol<? x (car l)) #f)
   (else (member? x (cdr l)))))
2
symbol<? does not exist in any scheme I know. You have to convert it to string.leppie
how do i convert it to a string.xmantra23

2 Answers

3
votes

There isn't a symbol<? predicate, but there is a string<? - so if we convert the symbol into a string we'll be able to perform the comparison:

(define (symbol<? s1 s2)
  (string<? (symbol->string s1)
            (symbol->string s2)))
2
votes

symbol<? doesn't exist in Scheme. I know it's a standard procedure in the racket language, but that is not Scheme but a similar dialect.

I think you can define it like this:

(define (symbol<? a b)
  (string<? (symbol->string a) 
            (symbol->string b)))