[racket] Why no string function to replace substring based on content in Racket

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Tue Feb 7 20:19:20 EST 2012

Harry Spier wrote at 02/07/2012 08:05 PM:
> I have Python programs which convert Indian language book length
> etexts from one transliteration scheme to another so I'm calling the
> Python  replace function hundreds of thousands of times per e-text and
> doing multiple replaces with each call.

What about doing all these substitutions in a single pass of reading the 

You could do it by hand, using reading primitives and/or perhaps using 
regexps just to tokenize.  Or you could try using the regexp engine 
more, perhaps by programmatically assembling a single regexp that 
matches any of your terms to replace, and then doing a table lookup to 
find the substitution.

> I'd like to convert these programs to Racket, but using regular
> expressions might be too slow.  Is  writing a C foreign function.
> extension my only alternative or is there such a function in some
> Racket package..

A clever implementation in pure Racket code might be faster than a 
less-clever implementation in C.


Posted on the users mailing list.