1. Re: EUPHORIA Digest - 21 Jun 1998 to 22 Jun 1998 (#1998-36)

>error 1: =3D --> this is because you enable "quoted printable" in your
mailer.
>error 2: close file_i --> need (), so: close(file_i)
>error 3: return exits --> have to rephrase (otherwise file's not closed!
>    you get only 12 files with Euphoria)
>
>read the previous digest, I have posted a supposedly-working function (for
>an "rb"-opened file) that does not change the file position.

Opening a file when you only want its length is asking for a lot of
irritating behaviour.
What about file sharing (), maximum files open, cache slowdown, etc.
Try this:

-- Clean approuch getting file length of an unopened file:
-- And it uses (as you suggested) dir to get the info of *one* file..

include file.e

function file_length(sequence fname)
sequence dirinfo
    dirinfo = dir (fname)
    if length(dirinfo) then
        return dirinfo[1][D_SIZE]
    else
        return -1    -- File not found!
    end if
end function

-- End of code

>>Short-circuit evaluation is a very sensible optimization. ...
>
>Agreed!!!!! smile))

It is not sensible anyway IMHO.
1) The speed gain is *very* little.
2) You can optimize it yourself (see the rest of the mail) at those places
where you can even speak of a measurable speed gain.
3) It could also be done by a preproccesor
4) It would break existing code
5) It would be less consistent ("sometimes my function is called and
sometimes it isn't, I really don't understand what I do wrong!", an reaction
from a newcomer on the list you can expect if RDS implents this.)
6) Optimizing your code yourself is actually a lot clearer:

    if.. this and that... is true.. then you should see... if... this and
that... is true then you do this..

    if THIS and THAT then if THIS and THAT then
        do (THIS)
    end if end if

    Just read the above statement block out loud.

>Actually, since you only found THREE programs, it wouldn't be hard to make
>the program run as intended with the short circuit function, again I
suggest:
>
>a and b = (a * b) != 0
>a or b  = ((a != 0) + (b != 0)) != 0
>
>it works with objects too!!!!

I thought you wanted optimization.
Plus with short circuit this too wouldn't work. They would be broken
forever, unless you do something like this:

--
a = a_function_needs_to_be_called_anyway1 ()
b = a_function_needs_to_be_called_anyway2 ()

if a and b then
-- Even if it short-circuited, both functions were called!
end if

Its a workaround needed for existing programs when we optimize euphoria, so
a few programmers who didn't want to optimize it themselves get a 0.0001 %
better optimized code.. ???!!!??

Is it just me?

>>I'm going to take a harder look at this. I'm starting to think
>>that the implementation won't be that difficult. Also,
>>I could issue a warning in cases where old
>>code might break, i.e. where a function with
>>side-effects is called to the right of "and" or "or"
>>in a boolean expression.
>
>yay!! finally smile))

Whenever it will break your code, it will warn ya, that *is* nice.
But why, I already warned you *now*, don't implent this! blink

>btw, how about the ?: operator? ppwsot? (pretty please with sugar on top)

Not needed. Only types a bit shorter, just like the short-circuit trick.
If you are having trouble typing a lot try the macro function of David's
Euphoria Editor.
Off course you could always try C. It has the ? and the short-circuit and
you don't need to type a lot. (you only need to track a couple of bugs down
for the next 20 hours.. blink)
And a typing cursus could help also, I even have a program for that
somewhere. (its shareware.. quicktype its called)

>>-- This is short-circuited 3 -times
>>if 1 then if 1 then if 1 then
>>    puts (1,"I'm in a short circuited if-statement, aint that nice ?\n")
>>end if end if end if
>
>that's "if 1 and 1 and 1 then", implemented in SEVEN statements.
>Aligned properly you get:

    Properly ?
    It was aligned to look in such way its usage it is most obvious.
    There is no proper and non proper way.
    Indentation style is a personal choice.

    And yes seven statements. Yet it will be as fast as your short-circuit
trick.
    It'll only need a little bit more typing.
    We can get over that, can't we ?

>Tell me how you would code the above if the "elsif" above with the current
>Euphoria version. Since I noted above x can be changed, you may not use

-- Voila!
elsif y[1] = GET_SUCCES and integer(y[2]) then if y[2] >= 1 and y[2] <=
length(x) the if x[y] < 31 then
    puts (1, "Thank you.\n")
end if end if else
    puts (1, "That is not a valid month!\n\n")
end if
-- Was that so hard ?

>    elsif y[1] != GET_SUCCESS or not find(y[2], {2, 4, 6, 9, 11}) then
>
>which should work since get() always returns a 2-element sequence.

allowed_values = {}
for index = 1 to length(x) do
    if x[index] < 31 then allowed_values = append(allowed_values, index) end
if
end for

elsif y[1] != GET_SUCCESS or not find (y[2],  allowed_values) then
end if

-- Would also work!

Off course in real life allowed_values would be hard-coded as a sequence,
like x is.
And i'm use if I knew the precize

>Even better is to include a test if sequence(y) and length(y) = 2 and ...,
>but that isn't currently necessary.

if sequence (y) then if length(y) = 2 and ..  then

end if end if

-- Also to avoid using else and elsif: (if you there clumbsy)

for doesntmatter = 1 to 1 do

    if this and that then
        do (that)
        exit
    end if
    if that and this then     -- elsif
        do (this)
        exit
    end if
    do (this and that)    -- else

end for


>>    The file size function a few people were requestion was regarding the
>>files they already opened. And then dos () will not return the right file
>>size. Euphoria cashes I/O for speed.
>
>dos()???
>
>>Preciously, most things can be done through the use of routines.
>
>precisely: the point is
>preciously: expensively (?)

Yes, why not have a quake function, that can be given a set of sprites and
levels and have it built-in ??
Then we can all *program* quake clones... "hey, mom, look, _I_ made this
smile)"

A program language is *not* effictively combining other people's code, if
you want that you should use Visual Basic.
In any sophisiticated programming language you will get the building blocks,
and make an applications.
And the more trivial the building blocks the more powerfull the programming
language.
A file length function is not a trivial building block! Don't you agree ?
A dir () function is!! And it provides the file length at 99% of the
performance a library routine for file length would have.

See the function at top of this mail, its pretty fast!
Plus, its always expensive, it it has its own code, the size of ex.exe will
increase.
So its always a choice.

>>I suppose Euphoria simply gets a lot slower handling a long sequence.
>
>eh? I hope that is not right!!! sad

At least in a linear relation, logically.

>Warning: Advertisement follows!
>
><advertisement>
>Perl has flexilength sequences as well (though it's used differently), and

More clumbsy is the word blink

>it has built-in hashes, not to mention the always-necessary standard

See the comment above about trivial and non-trivial building blocks.
Plus, there is no such thing as an universal hash function anyway.
At the RDS page you will find hash-code though. You can set your own
hash-functions.
Don't come with expensive again, euphoria custom coded hash-functions are
still at least 5 to 10 times faster than Perl's built-in.

>file-manipulation commands exist as built-in commands (unlink, mkdir, etc).
>
>Perl can read entire file at once, simply by
>    undef $/;
>    $x = <FILE>;
>while $x = <FILE> is normally translated to "x = gets(x)", and $/ is '\n'.
>That means we can define our own end-of-line string.

function perl_gets (integer fh, integer eol)
sequence ret
    ret = {getc(fh)}
    while ret[length(ret)] != -1 and ret[length(ret)] != eol do
        ret = append(ret, getc(fh)
    end while
    if ret[length(ret)] = -1 then
        return ret[1..length(ret)-1]
    else
        return ret
    end if
end function

Another problem solved in 10 easy to write, easy to read, fast executed
lines.

>Perl can do C-like commands like
>    $i += 3;
>    $j++;

Another.. I have to type so much.. get a typing cursus..or get Perl, C, ASM
(very short commands blink
Yes, Euphoria code, when programmed right is almost always shorter, safer,
and faster executed compared to Perl. Thats what the 'powerful' stands for
in 'powerful 32-bit programming language' blink

>and has a non-block shape of control structure (saving an "end ..." from
>being counted by the 300 statement limiter) which works when you place the
>control statement at the end of the command, e.g.
>    print "right!" if (3 < 5);

'end if' are not statements:

if this () and this ()  then
    do (that)
end if

Are 1) if-block 2) this () 3) this () 4) do (that) statements
Thus 4 statements.
End if is part of the if-statement.
Plus, the 300 statement limit is not a feature. It makes people with less
time pay for quicker program development and more easy. Robert has to live
and be able to buy new C++ compilers as well smile

>Perl allows to modify file attributes and date/time with built-in commands.

Use interrupts. See the stuff about 'trivial building blocks again'
And there is now a library for this as well.

>Perl allows assignments like
>    ($a, $b, $c) = (3, 5, 2); # this means $a = 3; $b = 5; $c = 2;

Ok, I do like the:

{ a, b, c } = {3, 5, 2}

Robert should consider this.
This is a *useful* speed optimization. And it makes things clearer, shorter
and safer.
Consider this:

s = {3, 5, 2}
a = s[1]
b = s[2]
c = s[3]

1) It gets copied twice!
2) If s has more than 3 elements it will not crash!
3) We need to declare s
4) Its less readable
5) Its more code

Perl wins at this point, I'm afraid.

>Perl allows command output capturing, as in
>    $diffout = `diff -w oldfile newfile 2>&1`;
>        # 2>&1 in unix means stderr should be redirected to stdout
>    if ($? >> 8) { # if errorlevel is not zero
>        print "Changes:\n";
>        print $diffout;
>    }
>    else {
>        print "No changes\n";
>    }
>
>etc. Euphoria, stuck with the 20k tracer installed in it, can't do that...

1) I don't  understand the code, way to unreadable (point to Euphoria)
2) Catching input and output is possible:

Just replace all I/O routines:

    function old_print (integer fh, object x)
        print (fh, x)
    end function

    function print (integer fh, object x)
        if fh = 2 then -- st_err
                fh = 1 -- st_out
        end if
        old_print (fh, x)
    end function

-- And do this for all I/O

>Perl can open as many files as your system allows. Euphoria limits you to
>only 12.

You don't know that, ever tried setting files = 1000000000 and opening half
of the files.
But true, the 12 is way to little for serieus applications.

>Perl allows you to have a Perl code embedded as string, and execute it, and
>tell you if it worked or if it has an error. Codes are run in the current
>context, has access to the current variables, and can even define new
>subroutines. Euphoria has no self-embedding capability. Example:
>    $x = 3;
>    $y = "$x++;"
>    eval $y; # not sure about the correct syntax though
>    print $x; # displays 4

Would be trivial to have this built-in, although it can create very strange
problems.
I can make an Euphoria executor for scripts though as a routine. (running at
less speed than normal thus!)

>Perl can check if a variable or a routine exists, is defined, or ... well,
>Euphoria has routine_id but no variable_id.

You don't want this. Bad programming style and no obvious purpose.

>Finally, Perl is free (no download time) because it is included as a
>standard programming language in UNIX systems. Perl can also be compiled
>for win32 etc if you get the source, which is *available*. Euphoria limits
>you to 300 lines and never gives a public domain source where I can change
>that 300 ;->

Duh! Welcome to the world, We need food! Hence, we need money!
You too obviously.

>There is no debugging facility at all in Perl (!), but I rarely use it if
>there were one. There is a great debugging facility in Euphoria, but with

If I take any trivial perl program and look at it, I get a headache!
Trust me, I would need a *very* good debugging facility!
And you're obviously not very experieced with the debugging facilities of
Euphoria.
If you were, you would already by hooked by it, and would want such for Perl
also.

>ugly colors. Euphoria will dump core, but not unless you are registered or

    Ugly colors.  True, I always bring my source codes to an art-galary.
    They are high-contrast and work in EGA as well. Which is a lot more
practical than more subtle colors.

>your program is small -- and I do mean small. Why have I always asked for
>the 300 line limit to be removed? Because to me Euphoria is just a
>stripped-down Perl, since I rarely make small programs for that core dumper
>to work.

Don't be insulted by this, but the length of code and the number of
statements used is linear relative to the qualitiy of the programmer.
When I started in Euphoria, I made MaZer for example. Mazer 2 about a year
later, had many more options and less bugs and it was 1/3 of the code of
Mazer1.

And there are many ways around the 300 statements limit.
If you would know Euphoria well enough, you would know it beats perl on
almost any turf, and you would know the ways around the 300 statements
limit.

Perl has no obvious theoretic base, while Euphoria is so thought-through.
Robert could put all the theoretic stuff about functional program languages,
safety, scoping rules, implementation details, etc. in the documentation,
but people tend to need to know how to use it. Not why it is made in such a
way, that forces us to use it in a certain way.

>>You might reply "why DIM? Aren't you dim enough already?".You might...but
I
>>wouldn't recommend it.
>
>Hmm, nice pun smile, but they's not English speakers.

Try telling them, Euphoria could care less how big or small their dims are
and thus doesn't ask for it. It is flexible enough they will grasp they size
themselves blink

>Note how the four statements inside type..end type would be condensed to a
>mere ONE if we had a selective ternary conditional operator (in C it's
>called ?:):

In C you need to have a lot of things called.
Euphoria = simple
C = Pointers, {}, ;, ?, ++, --, integers, bytes, booleans, doubles, floats,
30+ data type conversion routines!...

Why doesn't Euphoria have '?', because we already have if- which is more
readable and better to understand.
C is a hack-language. You can do a lot you shouldn't be able to, but you do
need to be able to, because of the lack of many things.

>>of a copy of ex.exe. Bounded programs are by default shrouded also, so no
>>one can mess with the embbeded code in the executable.
>
>By default???
>
>Can one have an UNshrouded program bound, and e.g. have it self-modify upon
>running?

Nope, but shrouded isn't (as some1 stated) compiled.
It just replaces all keywords with symbolds, and renames all variables and
routine names.
However, registered users can scramble/encrypt their code also.
So you *can* modify your code, *if* you would have known all the symbols,
bad luck.
(would be bad programming style anyway)

What I would like is the ability to shroud everything except this and that
file:

shourd mylib.e -except options.e

(options.e is included in mylib.e, but will not be shrouded or binded into
the program!!)

So we can then have:

mylib.exe
options.e

Where mylib.exe calls options.e
This is good for plugins, options, highscores, hardware support, etc.

>btw: is the limit <= 300 statements or < 300 statements???

You seem to have a lot of time to write emails. Why not work for money *or*
stop complaining about the 300 statements limit. We are lucky RDS decided to
release a public domain version anyway. You should be thankfull. It's their
work. (yes, some people out there work instead of writing long emails)

>I type quickly and still want to have short-circuit...

Howcome, please give me ONE good argument...


>uuuuggggllllyyyy sad

Have you seen the things we need to pull, when we don't want short-circuit
for an if-statements. Now that's ugly.
Plus its not ugly, read it out loud, its almost an full english explenation
to ex.exe what you want to do.
It's not meant for an art-galary you know.

>hashes *someone*!?!?!?

See RDS' site, Junko of RDS has already provided this.

Ralf Nieuwenhuijsen
nieuwen at xs4all.nl

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu