1. smart_print() [was Re: split() function]
- Posted by Gabriel Boehme <gabrielboehme at HOTMAIL.COM>
May 03, 2000
-
Last edited May 04, 2000
Jiri wrote:
>Pete's smart_print is a nice, compact alternative to Gabriel's
>print.e.
I agree, it's a nifty little thing, less cumbersome than my print.e library
and far better-suited for display purposes. The only real problems I found
with it is that it's rather slow, and doesn't handle the double-quote
character properly: smart_print("\"") displays """.
Not the end of the world, to be sure, but I trust that Pete won't mind if I
take up these minor problems as "an exercise for the reader."
function smart_print_string(sequence s)
-- faster, I think, as a function
object x
for i = 1 to length(s) do
x = s[i]
if not integer(x) or x < ' ' or x > 255 or x = '"' then
return 0
end if
end for
return 1
end function
procedure smart_print_recursive(object o)
if atom(o) then
printf(1, "%g", {o})
elsif length(o) = 0 then
puts(1, "{}")
elsif smart_print_string(o) then
printf(1, "\"%s\"", {o})
else
puts(1, "{ ")
smart_print_recursive(o[1])
for i = 2 to length(o) do
puts(1, ", ")
smart_print_recursive(o[i])
end for
puts(1, " }")
end if
end procedure
procedure smart_print(object o)
smart_print_recursive(o)
puts(1, "\n")
end procedure
smart_print({"one", "two", 3}) -- displays { "one", "two", 3 }
smart_print("\"") -- displays { 34 }
Enjoy,
Gabriel
----------
"Punctuation. It's what keeps all the words in a sentence from happening at
once. Period."
Tom Golden (a line from "Romana 'n Dave", episode 47)
----------
______________________________________________________
PLEASE IGNORE ANY ADS YOU MAY SEE BELOW THIS LINE.
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
2. Re: smart_print() [was Re: split() function]
Pete, I did not insist, but many thanks anyway :).
And thanks to you too, Gabriel. jiri