Re: justifying compare

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

On Fri, 6 Nov 1998, Irv Mullins wrote:

> On Fri, 6 Nov 1998 00:57:34 -0800, David Cuny <dcuny at LANSET.COM> wrote:
>
> >Here's a question for Robert:
> >
> >Can you get rid of the 'compare' statement from Euphoria? If not, why?
> >...
> >The 'compare' seems to be the major stumbling block for beginners. It
> >certainly was for me.
> >...
> I concur wholeheartedly.

Yeah, but English (wonderful language) has its idiosyncracies too. "Cough"
and "Bough" for instance. Bad spellers use "alot" to mean "a lot".
Are you suggesting we get rid of the major stumbling blocks in English
too? :| :)

Soh wee get rid ov ze stumbling blox and looz alot ov comprihensibiliti.
Not gud orr priti iz it? :)

> >Is there a compelling reason for Euphoria to use the 'compare' statement?
>
> In a similar vein, the other big stumbling block is getting input
> from the keyboard. Specifically the linefeed that has to be removed,
> and perhaps the SUCCESS flag. Neither are needed or meaningful if
> the source of the input is device 0.
> Maybe I've missed something here?

Word processors allow bad spelling, so maybe we should allow [within
reason] some form of bad coding.

Maybe someone could write a "beginner.e" for all early coders to use.

I'll even start it off:

include get.e

global type char(integer x)
    return x >= 0 and x <= 255
end type

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

global function equal(object a, object b)
    return compare({a},{b})=0
end function

global function input(object of_output_type, string prompt)
    -- Usage: o1 = input(o1, s)
    object out

    out = gets(0)
    out = out[1..length(out)-1]

    if string(of_output_type) then
        return out
    else
        out = value(out)
        out = out[2] -- Assumes 0 on GET_FAIL

        if integer(of_output_type) then
            return floor(out)
        else--atom *or* sequence!
            return out
        end if
        -- use the if-statement so that it functions correctly if someone
        -- [mis]uses input() like this: a1 = input(i1, s)
    end if
end function

global procedure put(object a)
    if string(a) then
        puts(1, a)
    elsif sequence(a) then
        print(1, a)
    elsif integer(a) then
        printf(1, "%d", {a})
    else--if atom(a) then
        printf(1, "%1.12g, {a})
    end if
end procedure

global procedure put_line(object a)
    put(a)
    puts(1, "\n")
end procedure

--
Carl R White -- Final Year Computer Science at the University of Bradford
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
URL......: http://www.bigfoot.com/~cyrek/
Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr -- B.Q.Vgesa

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

Search



Quick Links

User menu

Not signed in.

Misc Menu