Question

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)))))
Was it helpful?

Solution

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)))

OTHER TIPS

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)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top