Question

Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter.

I need some String functions (string-replace to be exact), so I copied from 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?

Was it helpful?

Solution

You don't need to manually copy and paste items from SRFI 13: it is built into Racket. In fact, most of the major SRFI libraries are bundled with 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:

(#%require srfi/13)

The strange-looking #%require is a Racket-specific hook that allows an r5rs program to load library modules from Racket.

So an r5rs program in Racket would be something like this:

(#%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. Here's a small program in #lang racket that does the same as the previous program:

#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:

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. Simplify by loading the entire library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top