[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Txr-users] fail to use a function as the <replacement> object in @(regs

From: 苏灵
Subject: [Txr-users] fail to use a function as the <replacement> object in @(regsub <regex> <replacement> <string>)
Date: Sat, 13 Jul 2013 11:28:31 +0800

See below for my script and the error message.I can't find what is wrong. Did I
misunderstand the usage of  regsub?


> E:\TXR>cat -n r.txr
>     1  @(do
>     2  (defun cite-ref (str)
>     3          (cat-str '("<span class=\"cite-ref\"><sup>" ,str 
> "</sup></span>")))
>     4  )
>     5  @(bind line "The way is long and hard, that out  \
>     6   of hell leads up to light.[^113] People are \
>     7   searching for food and God.")
>     8  @(output)
>     9  @(cite-ref "fun.")
>    10  @(cite-ref line)
>    11  @(regsub  #/foo/ upcase-str line)
>    12  @(regsub  #/[\[][\^][0-9,\-]+[\]]/  cite-ref line)
>    13  @(end)
> E:\TXR>txr-65-MinGW-1.0.17-i686.exe r.txr
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
><span class="cite-ref"><sup>fun.</sup></span>
> <span class="cite-ref"><sup>The way is long and hard, that outof hell leads 
> up to light.[^113] People aresearching for food and God.</sup></span>
> e:\TXR\txr-65-MinGW-1.0.17-i686.exe: unhandled exception of type eval-error:
> e:\TXR\txr-65-MinGW-1.0.17-i686.exe: (r.txt:11) unbound variable upcase-str


On the other hand, there is a mistake in the collection of TXR Solutions.
(http://www.nongnu.org/txr/rosetta-solutions-main.html#Regular expressions)

> @(collect :vars ())
> @line
> @(output)
> @(regsub line #/foo/ "bar")
> @(end)
> @(end)

The order of regsub's arguments is wrong!

Also, in the documentation, the example for regsub:

> [regsub #/[eo]/ upcase-str "Hello world!"] -> "HEllO wOrld!"

Using "[ ]" instead of "( )". Is this another typo or you do this on purpose?

Thanks to you and your amazing TXR. Have a good day!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]