简体   繁体   中英

Using custom libraries from top level in Scheme (Racket 6.3)

Following the instructions in http://www.scheme.com/csug8/libraries.html , I could build a library smcho.ss .

(library (smcho simple (1))
    (export hello factorial)
    (import (rnrs (6)))

    (define (hello x)
      (+ x 10))

    (define (factorial n)
        (cond
            [(<= n 0) 1]
            [else (* n (factorial (- n 1)))]))
)

Then, install it with plt-r6rs --install smcho.ss ( http://lists.racket-lang.org/users/archive/2009-September/035465.html ).

However, when I tried to use it in top_level.ss,

(import (smcho simple) (rnrs (6)))    
(print (factorial 10))

I have error messages

scheme> plt-r6rs top_level.sc 
get-module-code: no such file: #<path:/Users/smcho/Desktop/scheme_lib/top_level.sc>
  context...:

What might be wrong? I checked that the ~/Library/Racket/6.3/collects directory stores correctly compiled library, so the issue should not be from the library.

The issue was that I should have used (display (factorial 10)) not print . Furthermore, In DrRacket GUI, I needed to add #lang r6rs to run in it.

I'm not sure why display is OK when print or pr causes an issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM