首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在命令行的REPL中加载和使用.rkt文件?

如何在命令行的REPL中加载和使用.rkt文件?
EN

Stack Overflow用户
提问于 2020-03-29 17:11:27
回答 1查看 737关注 0票数 3

我在Ubuntu18.04使用球拍7.6。我创建了这个文件,hello.rkt:

代码语言:javascript
复制
#lang racket

(define (hello) 'hello-world)
(hello)

然后我引用了它:

代码语言:javascript
复制
> racket hello.rkt
'hello-world

好的。接下来,我尝试将代码加载到REPL中并使用它:

代码语言:javascript
复制
> 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上下文中加载文件并使用它们的内容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-31 03:29:46

根据https://docs.racket-lang.org/guide/intro.html,您可以通过省略#lang声明并在REPL中使用(load <file>)来“模仿传统的Lisp环境”。当我从文件中删除#lang行时,我得到了以下交互:

代码语言:javascript
复制
> racket
Welcome to Racket 7.6.
> (load "hello.rkt")
'hello-world
> (hello)
'hello-world

该页面确实“强烈反对”这种做法,而倾向于基于模块的代码。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60917877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档