Steve Graham wrote:
> I saw this on comp.lang.smalltalk.dolphin and what struck me was how wordy
> it was. They're just trying to replace all occurrences of a substring in a
> string with another substring.
...
> How would you do it in Unicon?
I like Frank's solution a lot (it's clear and doesn't overuse the
language) but thought I'd show a slightly different version:
procedure replace(a, s1, s2)
local nA := ""
a ? {
while nA ||:= 1(tab(find(s1)),move(*s1)) || s2
return nA || tab(0)
}
end
which leads to a nice utility scanning procedure:
procedure replace(a, s1, s2)
local nA := ""
a ? {
while nA ||:= tabSkip(s1) || s2
return nA || tab(0)
}
end
procedure tabSkip(s)
suspend 1(tab(find(s)),move(*s))
end
--
Steve Wampler {[email protected]}
The gods that smiled upon your birth are laughing now. -- fortune cookie
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group