Brace expansion: Difference between revisions

Content added Content deleted
(template "introheader" was renamed to "task heading")
(Added PicoLisp)
Line 1,757: Line 1,757:
{a,b{1e}f
{a,b{1e}f
{a,b{2e}f</pre>
{a,b{2e}f</pre>

=={{header|PicoLisp}}==
<lang PicoLisp>(de braceExpand (Str)
(let Lst
(make
(for (Lst (chop Str) Lst)
(case (pop 'Lst)
("\\" (link (pop 'Lst)))
("{"
(recur ()
(let L
(make
(while
(case (pop 'Lst)
("\\" (link (pop 'Lst)) Lst)
("{" (recurse) Lst)
("}" NIL)
("," (link T) Lst) # Replace commata with 'T'
(T (link @) Lst) ) ) )
(if (= "}" @) # Was closing brace
(if (memq T L) # Has comma(ta)
(link (split L T))
(chain (list "{") (replace L T ",") (list "}")))
(chain (list "{") (replace L T ",")) ) ) ) )
(T (link @)) ) ) )
(recur (Lst)
(ifn (find pair Lst)
(list (pack Lst))
(let R (recurse (cdr Lst))
(mapcan
'((A) (mapcar '((B) (pack A B)) R))
(if (pair (car Lst))
(mapcan recurse (car Lst))
(list (car Lst)) ) ) ) ) ) ) )</lang>
Test:
<lang PicoLisp>(test
(quote
"~/Downloads/*.jpg"
"~/Downloads/*.gif"
"~/Downloads/*.png"
"~/Pictures/*.jpg"
"~/Pictures/*.gif"
"~/Pictures/*.png" )
(braceExpand "~/{Downloads,Pictures}/*.{jpg,gif,png}") )

(test
(quote
"Itemized, please."
"Itemize, please."
"Italicized, please."
"Italicize, please."
"Iterated, please."
"Iterate, please." )
(braceExpand "It{{em,alic}iz,erat}e{d,}, please.") )

(test
(quote
"cowbell!"
"more cowbell!"
"gotta have more cowbell!"
"gotta have\, again\, more cowbell!" )
(braceExpand "{,{,gotta have{ ,\\, again\\, }}more }cowbell!") )

(test
(quote
"{}} some }{,{\\ edge \,}{ cases, {here} \\\\\}"
"{}} some }{,{\\ edge \,}{ cases, {here} \\\\\}" )
(braceExpand "{}} some }{,{\\\\{ edge, edge} \\,}{ cases, {here} \\\\\\\\\\}") )</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==