1. Distinction between string and sequence

I'd like print sequences and strings.
If the members in sequence are smaller then ascii_max
the sequence prinoutt and string printout are equal.
----------
include Misc.e

procedure the_end() puts(1, "\nPress Enter to continue\n") if atom(gets(0)) then end if abort(0) end procedure

without warning - sequence seq

seq={{52,49,53},"415"}

pretty_print(1, seq, {2,5})

puts(1,"\n")

the_end() }}}

-------
The result: { "415" < I'd like hier to see: {52,49,53} "415" }


Thanks for help!

Attila Kondor }}}

new topic     » topic index » view message » categorize

2. Re: Distinction between string and sequence

> seq={{52,49,53},"415"}

>     "415"    <-- I'd like hier to see: {52,49,53}
>     "415"

Unfortunately, {52,49,53} and "415" are the same internally (to the
interpreter). You have to determine when a sequence is a string and
when it is plain data. You'd have to do something like this:

sequence a

a = {52,49,53}

print(1, a)              -- outputs {52,49,53}
printf(1, "%s", {a})  -- outputs "415"


new topic     » goto parent     » topic index » view message » categorize

3. Re: Distinction between string and sequence

Greg Haberek wrote:
> 
> > seq={{52,49,53},"415"}
> 
> >     "415"    <-- I'd like hier to see: {52,49,53}
> >     "415"
> 
> Unfortunately, {52,49,53} and "415" are the same internally (to the
> interpreter). You have to determine when a sequence is a string and
> when it is plain data. You'd have to do something like this:
> 
> }}}
<eucode>
> sequence a
> 
> a = {52,49,53}
> 
> print(1, a)              -- outputs {52,49,53}
> printf(1, "%s", {a})  -- outputs "415"
> 
> </eucode>
{{{

> 
> 

This should do it also...

--    Disiguish a string from a sequence

include get.e
include misc.e
constant COUT = 1

integer halt
sequence elem elem = {{52,49,53},"415"}
sequence val val = value(elem[1])
sequence str str = {val[2], elem[2]}

print(COUT, reverse(str))
halt = wait_key()


Vincent

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu