问题
I am trying out Parenscript. While trying to experiment with regex function, I get unexpected output. for example, the reference manual shows:
(regex "foobar")
/foobar/;
(regex "/foobar/i")
/foobar/i;
However in my repl I get error that function (parenscript:regex..) is undefined.
The function parenscript:regex is undefined.
[Condition of type undefined-function]
Restarts:
0: [continue] Retry using regex.
1: [use-value] Use specified function
2: [retry] Retry SLIME REPL evaluation request.
3: [*abort] Return to SLIME's top level.
4: [abort] abort thread (#<thread "repl-thread" running {1002319B63}>)
Backtrace:
0: (sb-impl::retry-%coerce-name-to-fun regex nil)
1: (sb-int:simple-eval-in-lexenv (regex "foobar") #<NULL-LEXENV>)
2: (eval (regex "foobar"))
--more--
I tried changing namespace to cl-user,ps, etc, nothing worked. OTOH, just for checking, I tried using functions sin, random, etc., and that worked. I mean, typing (sin 0.1) in repl yielded expected output.
Any help will be of great help.
回答1:
In a SBCL read-eval-print-loop:
CL-USER> (in-package "PS")
#<PACKAGE "PARENSCRIPT">
PS> (ps (regex "foobar"))
"/foobar/;"
PS> (in-package "CL-USER")
#<package "COMMON-LISP-USER">
cl-user> (ps:ps (ps:regex "foobar"))
"/foobar/;"
PS:PS
is the Parenscript compiler as a macro operator.
来源:https://stackoverflow.com/questions/62042025/using-regex-regular-expressions-in-parenscript