简体   繁体   English

方案R5RS定义语法被忽略了吗?

[英]Scheme R5RS define-syntax ignored?

Just started learning Scheme. 刚开始学习Scheme。 I'm using Dr. Racket as my compiler/interpreter. 我正在使用Racket博士作为我的编译器/解释器。

I need some String functions (string-replace to be exact), so I copied from SRFI 13 . 我需要一些String函数(确切地说是string-replace),所以我是从SRFI 13复制的。

When I test it, it shows.. 当我测试它时,它显示..

reference to undefined identifier: let-string-start+end

That's defined with 定义为

define-syntax let-string-start+end

It seems that it's being ignored? 看来它被忽略了吗? What's actually happening? 实际发生了什么?

You don't need to manually copy and paste items from SRFI 13: it is built into Racket. 您无需从SRFI 13中手动复制和粘贴项目:它内置在Racket中。 In fact, most of the major SRFI libraries are bundled with Racket: http://docs.racket-lang.org/srfi/index.html 实际上,大多数主要的SRFI库都与Racket捆绑在一起: http ://docs.racket-lang.org/srfi/index.html

If you are using the r5rs language in Racket, you can pull in SRFI 13 with the following line: 如果您在Racket中使用r5rs语言,则可以通过以下行插入SRFI 13:

(#%require srfi/13)

The strange-looking #%require is a Racket-specific hook that allows an r5rs program to load library modules from Racket. 看起来很奇怪的#%require是一个特定于Racket的挂钩 ,它允许r5rs程序从Racket加载库模块。

So an r5rs program in Racket would be something like this: 因此,在Racket中使用r5rs程序是这样的:

(#%require srfi/13)
(display (string-replace "foo world" "hello" 0 3))
(newline)

If, instead of using the basic r5rs language, you use the full-fledged #lang racket instead, importing SRFI 13 would look similar. 如果不是使用基本的r5rs语言,而是使用功能r5rs #lang racket ,则导入SRFI 13看起来很相似。 Here's a small program in #lang racket that does the same as the previous program: 这是#lang racket中的一个小程序,与先前的程序相同:

#lang racket
(require srfi/13)
(string-replace "foo world" "hello" 0 3)

Unfortunately, the error you're reporting doesn't have enough information to accurately diagnose the problem. 不幸的是,您要报告的错误没有足够的信息来准确诊断问题。 I suspect an incomplete copy-and-pasting somewhere, since you mention that you copied from SRFI 13. One reason why I think you may have mis-copied the code is that you mention defining it with: 我怀疑某个地方的复制粘贴不完整,因为您提到您是从SRFI 13复制的。我认为您可能误复制了代码的原因之一是您提到了使用以下内容进行定义:

define-syntax let-string-start+end

and that line is actually missing some crucial parentheses; 该行实际上缺少一些关键的括号; in the original source, there's a leading paren at the front of that line. 在原始资料中,该行的前面有一个前置的括号。

But you shouldn't try to cull bits and pieces out of the SRFI implementation by hand, at least not until you're more familiar with Scheme. 但是,您不应该尝试手工剔除SRFI实现中的点点滴滴,至少直到您对Scheme更加熟悉为止。 Simplify by loading the entire library. 通过加载整个库来简化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM