Re: RE: representation problem
- Posted by gwalters at sc.rr.com Mar 18, 2002
- 365 views
Derek, This morining I merged your code into the dump program and it seems to work like a charm... thanks a lot...The problem I was trying to solve was running into a date field in the data stream {2002,3,18}. Works nicely now. george ----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: "EUforum" <EUforum at topica.com> Subject: Re: RE: representation problem > > You might find this approach, using types, useful: > > with trace > --trace(1) > -- General string: integer values 0 - 255 > global type String(object x) > if atom(x) then > return 0 > end if > > for i = 1 to length(x) do > if not integer(x[i]) or > x[i] < 0 or > x[i] > 255 then > return 0 > end if > end for > return 1 > > end type > > -- Printable string: integer values 32 - 126, plus tab, newline, carriage-return, > -- formfeed, bell and backspace. > global type DisplayString(object x) > if atom(x) then > return 0 > end if > > for i = 1 to length(x) do > if not integer(x[i]) or > x[i] < 7 or > x[i] > 126 then > return 0 > end if > if x[i] < 32 and > x[i] > 13 then > return 0 > end if > end for > return 1 > > end type > > procedure ShowObject(integer FH, object a) > sequence temp, sign > integer l, r > > if DisplayString(a) then > printf(FH, "\"%s\"", {a}) > > elsif sequence(a) then > puts(FH, '{') > for i = 1 to length(a) do > ShowObject(FH, a[i]) > if i != length(a) then > puts(FH, ',') > end if > end for > puts(FH, '}') > > elsif integer(a) then > printf(FH, "%d", a) > > else > if a < 0 then > sign = "-" > a = -a > else > sign = "" > end if > temp = sprintf("%15.15f", a) > l = 1 > while temp[l] = '0' do > l += 1 > end while > if temp[l] = '.' then > l-=1 > end if > r = length(temp) > while temp[r] = '0' do > r -= 1 > end while > if temp[r] = '.' then > r -= 1 > end if > printf(FH, "%s", {sign & temp[l..r]}) > > end if > end procedure > > ShowObject(1, {1,2,3,4}) > puts(1,'\n') > > ShowObject(1, "1234") > puts(1,'\n') > > ShowObject(1, {"1234",-16.544,2,{"first","last"}}) > puts(1,'\n') > > --------------- > Derek. > > 18/03/2002 9:21:49 AM, bensler at mail.com wrote: > > > > >There is no distinguishable difference between the 2 except how you read > >it. > > > >a = {65,83,67,73,73} = b = "ASCII" > > > >If it's data generated by your program, then you can use the first or > >last element of the sequence as a designator. > > > >I'd use the last element, with 0 for strings and 1 for byte data. > > > >a = {65,83,67,73,73,1} -- bytes > >b = "ASCII"&0 -- string > > > >Chris > > > >gwalters at sc.rr.com wrote: > >> I'm having trouble with this problem. How do you destinguish between <snip> > >> for > >> b i need to print the string. I'm trying to modify Buddy Hyllberg data > >> dump > >> but am lost in this problem. > >> > >> sequence a,b > >> > >> a = {1,2,3,4} > >> b = "1234" > >> > >> printf(1,"len a = %d len b = %d\n",{length(a),length(b)}) > >> > >> if atom(a) then puts(1,"a is an atom\n") else puts(1,"a is a seq\n") end > >> if > >> > >> if atom(b) then puts(1,"b is an atom\n") else puts(1,"b is a seq\n") end > >> if > >> > >> > >> b = gets(0) > >> > >> george > >> > >> > --------- > Cheers, > Derek Parnell > ICQ# 7647806 > > > >