1
votes

I found the Racket documentation for the string-replace function to be vastly disparate from how the racket read-eval-print loop actually works. The docs say that you can put a keyword after String-replace to specify that you only want to replace the first instance, like so (but they don't have an example for this):

(string-replace "My Dog is a Dog" "Dog" "Cat" #:all #f)

So, according to the docs, this should output: "My Cat is a Dog" (I know it doesn't make sense, but this is just an example).

Instead, my different racket installs complain in different ways such as "procedure does not expect an argument with given keyword" or something about using the keyword as a procedure.

I think I can still do what I want with string->list, but my big gripe is that this violates the Second Law of Robotics! If something is a valid command (straight from the docs), DO IT and quit whining!

EDIT: If I change the #:all to #:all?, it then complains that the number of arguments should be 3 with an optional keyword, but 5 are given (in otherwords, it sees the #:all? #f as two separate arguments, rather than a keyword group).

EDIT2: btw, I'm using drracket here in Linux. If I use just the command "racket" at a terminal, the corrected syntax works.

1

1 Answers

2
votes

Yeah, that's a bug -- the keyword name should be #:all?, not #:all:

-> (string-replace "My Dog is a Dog" "Dog" "Cat" #:all? #f)
"My Cat is a Dog"

It is now fixed in the source.