L.Tomei wrote:
>
> Ok, Roger's approach, with the use of amend, is definitively the fastest
> one.
> Anyway I put here a full-tacit version, for multiple replacements:
>
> sr=: 13 : '(#>{:x)}. ; ({:x) , each (<:#>{.x)}. each
> ((>{.x)E.(>{.x),y)<;._1 (>{.x),y'
> f=: 13 : '(2}.>{.y) ; (2{.>{.y) sr >{:y'
> t=: 13 : '1<#>{.y'
> stringreplace=: 13 : '>{: f^:t^:_ (,x);y'f.
>
> Just a train of 108 primitives!
>
> [...]
>
>
But if you look at your train, you'll notice that some sub-trains repeat
themselves over and over, so the whole train could be made shorter, first by
finding shorter tacit expressions, like by converting
] ,~ [:>[:{.[
into
>@:{.@:[ , ]
then by taking out these expression by replacing them with a single letter,
which is of course done by assignment:
f=:>@:{.@:[ , ]
What you should notice here is that whenever you define a tacit expression
like f, a mention of f inserts the whole expressions in its stead, in
parentheses:
f 3
is not
>@:{.@:[ , ] 3
but
(>@:{.@:[ , ]) 3
As if parentheses are added automatically by the interpreter. That way we
can write any J code without a single parenthesis as long as we have enough
assignments defined, which is the
exact opposite of what you did with 13 :
--
View this message in context:
http://www.nabble.com/tacit-stringreplace-tp20476004s24193p20503901.html
Sent from the J Programming mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm