Brace expansion: Difference between revisions

m
deleting J entry while work through spec change issues
m (tiny clarification)
m (deleting J entry while work through spec change issues)
Line 153:
^D
bracex: <stdin>: hGetLine: end of file</pre>
 
=={{header|J}}==
 
Caution: task ambiguity - see talk page.
 
<lang J>legit=: 1,_1}.4>(3;(_2[\"1".;._2]0 :0);('\';a.);0 _1 0 1)&;:
2 1 1 1
2 2 1 2
1 2 1 2
)
 
comma=: legit * =&','
left=: legit * =&'{'
right=: legit * =&'}'
 
expand=:3 :0
candidates=: i.0 2
for_check.I. comma y do.
begin=. >./I. left check{. y
end=. check+<./I. right check}. y
if. (#y)>:end-begin do. candidates=. candidates,begin,end end.
end.
if. 0=#candidates do.,<y return. end.
'begin end'=. candidates{~(i.>./) -/"1 candidates
options=. (<;._1~ comma) ',',(1+begin)}.end{.y
;expand each (<begin{.y),each options,each <(1+end)}.y
)</lang>
 
Example use:
 
<lang j> >expand '~/{Downloads,Pictures}/*.{jpg,gif,png}'
~/Downloads/*.jpg
~/Pictures/*.jpg
~/Downloads/*.gif
~/Pictures/*.gif
~/Downloads/*.png
~/Pictures/*.png
> expand 'It{{em,alic}iz,erat}e{d,}, please.'
Itemized, please.
Iterated, please.
Italicized, please.
Iterated, please.
Itemize, please.
Iterate, please.
Italicize, please.
Iterate, please.
>expand '{,{,gotta have{ ,\, again\, }}more }cowbell!'
cowbell!
more cowbell!
cowbell!
gotta have more cowbell!
cowbell!
more cowbell!
cowbell!
gotta have\, again\, more cowbell!
>expand '{}} some {\\{edge,edgy} }{ cases, here\\\}'
{}} some {\\edge }{ cases, here\\\}
{}} some {\\edgy }{ cases, here\\\}</lang>
 
=={{header|Perl}}==
6,962

edits