0
votes

I've written the following Scheme code:

(define (last-pair list1)
    (if (null? cdr list1)
        car list1
        (last-pair (cdr list1))))

(define (rev list1)
    (if (null? list1)
        list1
        (append (rev (cdr list1)) (list (car list1)))))

in a file called test.scm.

At terminal, I run:

load "test.scm"

Then I try:

(last-pair (list 1 2 3))

;Value 15: (3)

which is correct.

Then I try:

(rev (list 1 2 3))

;Unbound variable: rev
;To continue, call RESTART with an option number:
; (RESTART 4) => Specify a value to use instead of rev.
; (RESTART 3) => Define rev to a given value.
; (RESTART 2) => Return to read-eval-print level 2.
; (RESTART 1) => Return to read-eval-print level 1.

Seems that it's loading my file properly since it loads last-pair, but I'm not sure why I'm getting the above error...

Thanks!

1

1 Answers

3
votes

You will need to write

(load "test.scm")

at the repl. Just load "test.scm" probably doesn't load the file.

I think there is a builtin last-pair which makes it confusing that your last-pair example works and the rev one doesn't.