我在使用Racket 7.6的Ubuntu 18.04上。我创建了这个文件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上下文中加载文件并使用它们的内容?
根据https://docs.racket-lang.org/guide/intro.html,您可以通过省略#lang
声明并(load <file>)
在REPL中使用来“模仿传统的Lisp环境” 。当我从文件中删除#lang行时,我得到了以下交互:
> racket
Welcome to Racket 7.6.
> (load "hello.rkt")
'hello-world
> (hello)
'hello-world
该页面确实“强烈建议”该做法,而偏向基于模块的代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句