Re: problem
- Posted by mistertrik at hotmail.com Oct 12, 2003
- 506 views
I'm not quite sure what you mean george.... the string "123" is identical to {49,50,51}, not {1,2,3} If sequence a = {1,2,{2002,12,30}}, and you want sequence b to be {1,2,"2002-12-30"} then you can write it as b = a[1..2] & {sprintf( "%4d-%02d-%02d", a[3] )} If you wanted a generic function to turn sequences into a string (though just why you want to do it escapes me) then look at the pretty_print function. At the moment, there is the procedure printf, which allows you to put variables into a string in a particular format, and print them out. There is also a function sprintf (used above), which is identical, except that it returns a string containing that formatted data. Rather than reinventing the wheel, how about adapting pretty_print to become spretty_print? Last I heard, it was in misc.e ===================================================== .______<-------------------\__ / _____<--------------------__|=== ||_ <-------------------/ \__| Mr Trick >From: George Walters <gwalters at sc.rr.com> >Reply-To: EUforum at topica.com >To: EUforum <EUforum at topica.com> >Subject: problem >Date: Sun, 12 Oct 2003 10:21:41 -0400 > > >I'm trying to write a functon to convert a sequence (of numbers and >strings) to a long string sequence. >i.e {1,2,{2002,12,30}} to "(1,2,"2002-12-30")" > >the problem is to distinguish between the string "123" and the sequence >{1,2,3}. >they both have a length of 3 and all their elements are atoms. > >can you improve on this? as it stands it has problems. >-- would be how it is used. > for i = 1 to length(s) do > if atom(s[i]) then > out &= str(s[i]) else ---<- this "str" function I >wrote to convert a number to a string > if length(s[i]) = 3 then > if atom(s[i][1]) and atom(s[i][2]) and atom(s[i][3]) then > out &= "\"" & s[i] & "\", " > end if > end if > end for > out[length(out)] = ')' > return out >end function > >thanks for any suggestions > >george > > > >TOPICA - Start your own email discussion group. FREE! > >