一般问题:
我可以在运行的Racket脚本中调用当前的racket可执行文件吗?
基本上,我希望在(system "racket ...")没有返回到我目前正在使用的球拍可执行文件的路径的情况下,替换(find-executable-path "racket")。
上下文:
我真正想要的是尝试编译一些表达式,并断言它们会引发编译错误。这是用于单元测试的。
发布于 2015-12-13 05:18:09
我不认为你需要在这里走出可执行文件。试试这个:
#lang racket
(require syntax/modread)
;; define a namespace anchor to attach a namespace to:
(define-namespace-anchor anchor)
;; define a namespace for expansion:
(define target-namespace (namespace-anchor->namespace anchor))
(define program-to-compile
"#lang racket
(+ 3 4)")
;; go ahead and expand
(with-module-reading-parameterization
(λ()
(parameterize ([current-namespace target-namespace])
(expand
(read-syntax
"bogus-filename"
(open-input-string program-to-compile))))))我认为我是正确的,当我说,球拍是非常干净的,它的能力提供编译器运行程序的纪律。
发布于 2015-12-15 19:32:09
对于小型测试,还可以从convert-compile-time-error库中使用syntax/macro-testing。它将导致编译时错误的表达式转换为在计算时引发运行时错误的表达式。表达式使用发生在模块中的环境,包括本地绑定;您不必篡改名称空间和eval。
(check-exn #rx"bad syntax"
(lambda () (convert-compile-time-error (lambda))))还有convert-syntax-error (在同一个页面上)。
https://stackoverflow.com/questions/34247279
复制相似问题