2 ms·
> (Insert Racket example and others here). Common Lisp (via CL-PPCRE): CL-USER> (parse-string "a(?i)b(?-i)c") (:SEQUENCE #\a (:SEQUENCE (:FLAGS :CASE-
by TeMPOraL 6y ago
> (Insert Racket example and others here).
Common Lisp (via CL-PPCRE):
CL-USER> (parse-string "a(?i)b(?-i)c")
(:SEQUENCE #\a
(:SEQUENCE (:FLAGS :CASE-INSENSITIVE-P)
(:SEQUENCE #\b (:SEQUENCE (:FLAGS :CASE-SENSITIVE-P) #\c))))
You can use both notations to compile and execute regexes. Also, bonus point for any Lisp that does it: you don't have to monkey around with ".end()" and such to turn a "fluent syntax" - which is inherently linear - into something resembling a tree, because s-expressions are trees and you get that for free.
- kazinator 6y agoThe .end() occurs because the approach taken procedural construction via a "linear" path. And that's because that maps nicely to the chained.function().syntax(). That gets ugly if the terms have multiple arguments. (S (NP (N DOG)) (VP (V KICKS)) (NP (N MAN))) becomes: (S DOG.N().NP() KICKS.V().VP() MAN.N().NP()) so far not bad, but now we deal with S, that now becomes a method of DOG.(N).(NP). DOG.N().NP().S(KICKS.V().VP(), MAN.N().NP()) The main connective S is now buried in the middle. We start with DOG, a fourth-level leaf element, make a N out of it, the NP, and now we start a sentence construction, where we bring in other parts. The structure reveals the evaluation order, not the actual structure. BTW, the TXR Lisp version of this syntax is a tad more readable: DOG.(N).(N).(S KICKS.(V).(VP) MAN.(N).(N)) Even when we have obj.fun(arg) as a given, we should at least move the parenthesis before the function: obj.(fun arg).