【发布时间】:2020-07-10 01:46:21
【问题描述】:
我在 Ubuntu 18.04 上使用 Racket 7.6。我创建了这个文件,hello.rkt:
#lang racket
(define (hello) 'hello-world)
(hello)
然后我调用它:
> racket hello.rkt
'hello-world
很好。接下来我尝试将代码加载到 REPL 中并使用它:
> racket -i hello.rkt
Welcome to Racket v7.6.
> (hello) ; the function is unavailable here
; hello: undefined;
; cannot reference an identifier before its definition
; in module: top-level
; [,bt for context]
> (load "hello.rkt") ; load gives no error, but ...
> (hello) ; the function is unavailable here
; hello: undefined; ...
> (require "hello.rkt") ; require gives no error ...
'hello-world ; and runs (hello), but ...
> (hello) ; the function is unavailable here
; hello: undefined; ...
> (include "hello.rkt") ; include gives no error, but ...
> (hello) ; the function is unavailable here
; hello: undefined; ...
> (enter! "hello.rkt") ; enter! gives no error, but ...
"hello.rkt"> (enter! "other.rkt") ; if I enter! another file ...
"other.rkt"> (hello) ; the hello function is unavailable here
; hello: undefined; ...
简而言之:如何在顶级命令行 REPL 上下文中加载文件并使用它们的内容?
【问题讨论】:
-
你是问是否可以
enter!在同一个REPL中同时使用多个文件的环境? -
在 MIT Scheme 的 REPL 中,当我 (load "hello.scm") 和 (load "other.scm") 时,两个文件中的函数都可以立即在顶层使用。我希望能够在 Racket 中做类似的事情。
标签: file include racket external read-eval-print-loop