Using regex (Regular Expressions) in Parenscript

混江龙づ霸主 提交于 2020-06-09 05:29:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!