Re: get() - i'm missing sprint()

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C0CB1A.FC1078A0
	charset="iso-8859-1"

I wrote:
> client will send something like {myname,message,other_info}.

then i wrote :
> i'll add CR after sequence, but i must send characters as numbers =
because
> sequence may contain CR too,
> like this:
> {{12,23,45},{12,34,45}}CR

i found there isn't such function to do this in eu, so I've created such =
one called sprint(). It gives the same output as print(), but the output =
is returned as a sequence of characters, rather than being sent to a =
file or device.
I think such function should be built-in. (or am I stupid and i =
overlooked some much easier way or library routine to do this?)

It may to handy for debugging in win23lib progs if you don't want =
console window with print(); in combination with value() it can be used =
for exchange of sequences between eu progs (over the net), so if this =
function is OK and working with all possibilities, Rob could add it to =
get.e

here's the code:

global function sprint(object x)
 sequence ret
 if atom(x) then=20
  return sprintf("%g",x)
 else -- its a sequence
  ret =3D "{" -- starting bracket
  for i=3D1 to length(x) do=20
   ret &=3D sprint(x[i]) -- process each element
   if i !=3D length(x) then -- no comma if it's the last element
    ret &=3D "," -- add comma
   end if=20
  end for
  ret &=3D "}"  -- ending bracket
  return ret
 end if
end function

include get.e -- value()

sequence test, val
test =3D {"name","msg",2,{{1,2,{3,4}},5,2.221,'A'}}
puts(1, sprint(test) & "\n")
print(1, test) -- output is same
val =3D value(sprint(test))
val =3D val[2]
if equal(val, test) then puts(1,"\nIt worked !") end if



------=_NextPart_000_0006_01C0CB1A.FC1078A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Arial CE" size=3D2>
<DIV><FONT face=3D"Arial CE" size=3D2>I wrote:</FONT></DIV>
<DIV><FONT face=3D"Arial CE" size=3D2><EM>&gt; client will send =
something like=20
{myname,message,other_info}.</EM></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Arial CE" size=3D2>then i wrote :<BR><EM>&gt; i'll =
add CR after=20
sequence, but i must send characters as numbers because<BR>&gt; sequence =
may=20
contain CR too,<BR>&gt; like this:<BR>&gt;=20
{{12,23,45},{12,34,45}}CR</EM></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Arial CE" size=3D2>i found there isn't such function =
to do this=20
in eu, so </FONT></FONT><FONT face=3D"Arial CE" size=3D2>I've created =
such one=20
called sprint(). It&nbsp;gives the same output as print(), but the =
output is=20
returned as a sequence of characters, rather than being sent to a file =
or=20
device.</FONT></DIV></DIV>
<DIV><FONT face=3D"Arial CE" size=3D2>I think such function should be =
built-in.=20
(or&nbsp;am I stupid and i overlooked some much easier way or library =
routine to=20
do this?)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Arial CE" size=3D2>It may to handy for debugging in =
win23lib=20
progs if you don't want console window with print(); in combination with =
value()=20
it can be used for exchange of sequences between eu progs (over the =
net), so=20
i<FONT face=3D"Arial CE" size=3D2>f this function is OK and working with =
all=20
possibilities, </FONT>Rob could add it to get.e</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Arial CE" size=3D2>here's the code:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2><FONT color=3D#0000ff>global function =

</FONT>sprint(<FONT color=3D#0000ff>object </FONT>x)<BR>&nbsp;<FONT=20
color=3D#0000ff>sequence </FONT>ret<BR>&nbsp;<FONT color=3D#0000ff>if =
</FONT><FONT=20
color=3D#008000>atom</FONT>(x) <FONT color=3D#0000ff>then <BR>&nbsp; =
return=20
</FONT>sprintf("%g",x)<BR>&nbsp;<FONT color=3D#0000ff>else </FONT><FONT=20
color=3D#ff0000>-- its a sequence</FONT><BR>&nbsp; ret =3D "{" <FONT=20
color=3D#ff0000>-- starting bracket<BR>&nbsp; </FONT><FONT =
color=3D#0000ff>for=20
</FONT>i=3D1 <FONT color=3D#0000ff>to </FONT><FONT =
color=3D#008000>length</FONT>(x)=20
<FONT color=3D#0000ff>do&nbsp;<BR>&nbsp;&nbsp; </FONT>ret &amp;=3D =
sprint(x[i])=20
<FONT color=3D#ff0000>-- process each element</FONT><BR>&nbsp;&nbsp; =
<FONT=20
color=3D#0000ff>if </FONT>i !=3D <FONT color=3D#008000>length</FONT>(x) =
<FONT=20
color=3D#0000ff>then <FONT color=3D#ff0000>-- no comma if it's the last=20
element</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>&nbsp;&nbsp;&nbsp; ret &amp;=3D "," =
<FONT=20
color=3D#ff0000>-- add comma</FONT></FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>&nbsp;&nbsp;&nbsp;<FONT =
color=3D#0000ff>end=20
if&nbsp;</FONT><FONT color=3D#ff0000><BR>&nbsp; </FONT><FONT =
color=3D#0000ff>end=20
for<BR>&nbsp; </FONT>ret &amp;=3D "}"&nbsp; <FONT color=3D#ff0000>-- =
ending=20
bracket<BR>&nbsp; </FONT><FONT color=3D#0000ff>return =
</FONT>ret<BR>&nbsp;<FONT=20
color=3D#0000ff>end if<BR>end function</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2><FONT color=3D#0000ff>include =
</FONT>get.e <FONT=20
color=3D#ff0000>-- value()</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2><FONT color=3D#0000ff>sequence =
</FONT>test,=20
val</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>test =3D=20
{"name","msg",2,{{1,2,{3,4}},5,2.221,'A'}}<BR><FONT =
color=3D#008000>puts</FONT>(1,=20
sprint(test) &amp; "\n")<BR><FONT color=3D#008000>print</FONT>(1, test) =
<FONT=20
color=3D#ff0000>-- output is same</FONT></FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>val =3D <FONT=20
color=3D#008000>value</FONT>(sprint(test))</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>val =3D val[2]</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2><FONT color=3D#0000ff>if </FONT><FONT =

color=3D#000000><FONT color=3D#008000>equal</FONT>(</FONT>val, test) =
<FONT=20
color=3D#0000ff>then </FONT>puts(1,"\nIt worked !") <FONT =
color=3D#0000ff>end=20
if</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>

------=_NextPart_000_0006_01C0CB1A.FC1078A0--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu