I'm using Chicken Scheme 4.9.0.1 on a Cloud9 hosted workspace, built from source.
I was trying it out with this (I mostly code with python, so I apologize for the weird parens syntax):
(define load-module
(lambda (filepath)
(begin
(load filepath)
)
)
)
(define print
(lambda (command)
(begin
(display command)
(newline)
)
)
)
(load-module "../src/Basics.scm")
(print (exponent 5 2))
where exponent was:
(define (exponent num pow)
(if (equal? pow 1)
num
(* num (exponent num (- pow 1))
)
)
)
But it gives me the following error:
Started /home/ubuntu/workspace/test.scm
CHICKEN
(c) 2008-2014, The Chicken Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.9.0.1 (stability/4.9.0) (rev 8b3189b)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
bootstrapped 2014-06-07
; loading /home/ubuntu/workspace/project1/src/test.scm ...
; loading ../src/Basics.scm ...
Error: unbound variable: pow
Call history:
<eval> [append] (cons item (reverse target))
<eval> [append] (reverse target)
<eval> [append] (reverse (cons item (reverse target)))
<eval> [append] (cons item (reverse target))
<eval> [append] (reverse target)
<eval> [append] (reverse (cons item (reverse target)))
<eval> [append] (cons item (reverse target))
<eval> [append] (reverse target)
<eval> [append] (reverse (cons item (reverse target)))
<eval> [append] (cons item (reverse target))
<eval> [append] (reverse target)
<syntax> (print (exponent 5 2))
<syntax> (exponent 5 2)
<eval> (print (exponent 5 2))
<eval> (exponent 5 2)
<eval> [exponent] (equal? pow 1) <--
I tried the same procedure on a different scheme implementation (biwascheme, using their online REPL) and it worked. When I added the code directly into the file that i was working on without loading it from a separate file, then it works.
Why does it give that unbound variable error only when it loads from a separate file?