当前位置: 动力学知识库 > 问答 > 编程问答 >

scheme - eval works on command line but not in script file

问题描述:

Following simple 'eval' statement works well on command line of DrRacket (as mentioned on https://docs.racket-lang.org/guide/eval.html ):

> (eval '(+ 1 2))

3

However, if kept in the script file (main area of DrRacket) and run, it produces error:

#lang racket

(eval '(+ 1 2))

Error:

+: unbound identifier;

also, no #%app syntax transformer is bound in: +

>

Where is the problem?

网友答案:

In Racket, this is the correct way to run eval inside a script:

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))


(eval '(+ 1 2) ns)
=> 3

Please refer to the documentation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: