Re: Stupid Newbie-sounding question.

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

Juergen Luethje wrote:
> 
> 
> Irv wrote:
> 
> > Michelle wrote:
> > 
> >> but the problem with that is that it prints "John" as a string of the ascii
> >> codes,
> >> instead of an easily editable "John"..
> >>   if i add if sequence() it counts "John" as a sequence, just like the
> >>   sequence
> of
> >> flags..
> >> so my question is...
> >> how i can (within a loop) tell it to evaluate whether to puts or print?
> >> 
> >> bah..told you it was a stupid newbie question
> >> 
> >> Michelle Rogers
> > 
> > Not stupid at all. 
> > What the Eu docs call "flexible", I call a design flaw.
> > Euphoria cannot tell the difference between "John" and {74,111,104,110}
> > where the latter might be a series of integers or flags or whatever.
> 
> [snip]
> 
> Yes, like "integer" is a special type of atom, there definitely should
> be a "string" datatype, which is a special type of sequence.
> 
> At the first glance, it might look as if an additional data type would
> make Euphoria more complicated, but (latest) at the second glance it
> is clear that Euphoria would become *much* more flexible (see Michelle's
> problem here), simpler, safer, and better readable.
> 
> Regards,
>    Juergen
> 
Well, I can see your problem, and I agree that that adding "string" would
do so, I must say something.  There is a way to tell if it is a string or
not.  In your program, ""'s and {},s mean the same thing, so they reccomend
using ""'s for text(a string of typeable characters), and {}'s for other
sequences.  However, for a way to find out, you can make two types, like this:
type char(object x)
    if integer(x) then
        if (x >= 'a' and x <= 'z') or        -- all lowercase characters
           (x >= 'A' and x <= 'Z') or        -- all uppercase characters
           (x >= '0' and x <= '9') or        -- all numericial characters
           find(x, "?<>,./\\|[]{}`" &            --\ all of the other symbols
                   "~!@#$%^&*()-=_" &            --- that you can type, even
                   "+:\'\"\t\r\n" & {32}) then   --/ with "Shift" held down.
            return 1 -- return true, since only one char. is checked.
        end if
    elsif sequence(x)    -- if x is not an integer
        return (length(x) = 1 and char(x[1]))
    end if
end type

global type string(sequence x)
    for elem = 1 to length(x) do
        if not char(x[elem]) then
            return 0
        end if
    end for
    return 1
end type

-------------------------------------------------
|         Name:         | Nicholas Koceja       |
|      Occupation:      | Computer genius       |
|     Programs  in:     | BASIC, HTML, Euphoria |
|  Programs Completed:  | 3-5                   |
| Programs  Incomplete: | 20-30                 |
|   Operating System:   | Windows XP            |
-------------------------------------------------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu