ssubst on long strings



You appear to have written a program that takes time N^2 where N is the
length of the string.
1. Why do you construct a string? If you are communicating with a program in
another language, can you just write the text to a file or send to a pipe?
2. Could you instead send each row separately, so 50 shorter strings?
3. Why not just do the computation in Maxima's ordinary form?
RJF
 

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Fabrizio Caruso
> Sent: Monday, September 17, 2007 7:25 AM
> To: maxima at math.utexas.edu
> Subject: ssubst on long strings
> 
> Hi again,
> 
> I have implemented longssubst which
> does what ssubst does and works on strings
> larger than 5 kilobytes.
> 
> Unfortanately my code is much slower.
> 
> Could someone tell me why?
> 
> 
> 
> longssubst(nsub,osub,str) :=
>    block([out,len,nlen,olen,item,i],
>    len : slength(str),
>    nlen : slength(nsub),
>    olen : slength(osub),
>    out : "",
>    for i : 1 thru len-(olen-1) do
>      (
>      item : substring(str,i,i+olen),
>      if item=osub then
>         (
>         out : concat(out,nsub),
>         i : i + olen-1
>         )
>      else
>         (
>         out : concat(out,substring(str,i,i+1))
>         )
>      ),
>    for i : len-(olen-1)+1 thru len do
>      (
>      out : concat(out,substring(str,i,i+1))
>      ),
>    return(out)
>    );
> 
> 
>     Fabrizio
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>