我在Ubuntu18.04使用球拍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; ...简单地说:如何在toplevel命令行REPL上下文中加载文件并使用它们的内容?
发布于 2020-03-31 03:29:46
根据https://docs.racket-lang.org/guide/intro.html,您可以通过省略#lang声明并在REPL中使用(load <file>)来“模仿传统的Lisp环境”。当我从文件中删除#lang行时,我得到了以下交互:
> racket
Welcome to Racket 7.6.
> (load "hello.rkt")
'hello-world
> (hello)
'hello-world该页面确实“强烈反对”这种做法,而倾向于基于模块的代码。
https://stackoverflow.com/questions/60917877
复制相似问题