⚡gringo ~/me/c/rebel/src $: make
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-symbol.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-math.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-list.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-liststr.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-string.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-filesys.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-sock.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-import.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-xml-json.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-web.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-matrix.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-debug.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI rebel-utf8.c
cc -m64 -Wall -fno-strict-aliasing -O2 -c -g -I/usr/local/include -DREADLINE -DREBEL64 -DSUPPORT_UTF8 -D_BSD -DFFI pcre.c
cc rebel.o rebel-symbol.o rebel-math.o rebel-list.o rebel-liststr.o rebel-string.o rebel-filesys.o rebel-sock.o rebel-import.o rebel-xml-json.o rebel-web.o rebel-matrix.o rebel-debl
ld: warning: rebel-web.c:1389(rebel-web.o:(handleHTTPcgi)): warning: random() may return deterministic values, is that what you want?
strip rebel
⚡gringo ~ $: rebel -n
rebeL v.0.1 64-bit on BSD IPv4/6 UTF-8 libffi, options: rebel -h
>
. I remember Interlisp having square brackets as "meta parentheses" so as to avoid strings of stopping parentheses; the two forms interoperated so that ']' closed all '(' to match prior balancing '[', and likewise ')' closed all '[' to match prior balancing '('.(define (factorial n)
[if (zero? n)
1
(* n (factorial (- n 1 ] )Perhaps it's clearer? But the reader has to know the syntax in any case.> (define (regex-all EXP STR OPT ALL)
(let ((i 0)
(move-i (fn (X) (setq i (+ (X 1) (if ALL 1 (X -1)))) X)))
(collect (if (regex EXP STR OPT i) (move-i $it)))))
> (setq a "AAAaBAAAABcADccAAAB")
> (regex-all "[A]{3}" a 0)
(("AAA" 0 3) ("AAA" 5 3) ("AAA" 15 3))
> (regex-all "[A]{3}" a 0 true)
(("AAA" 0 3) ("AAA" 5 3) ("AAA" 6 3) ("AAA" 15 3))
(define (regex-all regexp str all)
"Find all occurrences of a regex in a string"
(let ( (out '()) (idx 0) (res nil) )
(setq res (regex regexp str 64 idx))
(while res
(push res out -1)
(if all
(setq idx (+ (res 1) 1)) ; contiguos pattern (overlap)
(setq idx (+ (res 1) (res 2)))) ; no contiguos pattern
(setq res (regex regexp str 64 idx)))
out))
(setq a "AAAaBAAAABcADccAAAB")
(regex "[A]{3}" a)
;-> ("AAA" 0 3)
(regex-all "[A]{3}" a)
;-> (("AAA" 0 3) ("AAA" 5 3) ("AAA" 15 3))
(regex-all "[A]{3}" a true)
;-> (("AAA" 0 3) ("AAA" 5 3) ("AAA" 6 3) ("AAA" 15 3))