1

ORIGINAL QUESTION: Write a recursive Racket function "more" that takes two lists, xs and ys, as parameters and returns true if xs has more elements than ys and false otherwise. For example (more '(1 2 3) '(1 2)) should evaluate to true while (more '(1 2 3) '(0 1 2)) should evaluate to false.

(define (more xs ys)
        (if (empty? ys)
                (if (empty? xs) #false #true)
        (if (empty? xs) #false (more (cdr xs) (cdr ys)))))
        

(writeln (more '(1 2 3) '(1 2)))
(writeln (more '(1 2 3) '(0 1 2 3)))
(writeln (more '(1 2 3) '(0 1 2)))

I get an error of ":13: empty?: unbound identifier in: empty?" How is 'empty?' an unbound identifier.

1 Answers1

1

It looks like you are using #lang racket/base (has #lang racket/base in the first line). In #lang racket/base, empty? is not provided to you by default.

Your assignment probably expects you to use a student language (click the bottom left dropdown button in DrRacket to change to, say, Beginning Student), and empty? will be provided to you be default.

Alternatively, if you really mean to use #lang racket/base, you can add (require racket/list) to make empty? available to you.

Alternatively, change #lang racket/base to #lang racket which will automatically (require racket/list) along with several other libraries.

Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28