Re: Ralf-circuiting ;-)
>Date: Thu, 25 Jun 1998 03:29:42 +0200
>From: Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL>
>Subject: Re: To David, Ralf (3), Lewis, Joe (2),
> but all may read (Rob Craig should)
>
>However, you're version is bit cleaner I must admit.
>It was a thought-in-a-sec-programmed-in-a-sec thingie.
My cleaner version is a thought-n-progged-in-a-sec as well.
Typed right into Eudora w/o checking.
I know lotsa languages, lotsa hacks, lotsa virus-making tricks [;->],
but only ONE language saying 'Prog run w/ PD version, it exceeds limit,
please reg to debug'.
At least other languages would tell me what the ERROR was! (luv ya,
Perl!) No core-dump is needed either.
(btw, in UNIX you can core-dump almost any program, also C++ programs)
>I meant, you want short-circuit as an optimization while you can gain the
>same speed now, however the above statement is slower than the 'a and b'
>So, actually, optimized-as-possible-programs will run *slower* with
>short-circuit plus a few will be broken.
SAME speed!? No! It needs to read more statements, interpret them, ...
(I hope you know what 'interpret' means, hint: it's a verb,
'interpreter' is a noun.)
>It works slower, you wanted optimization, make your point, if there is one.
Why would they work slower? They work the same way (internally that's
more-or-less how and and or are implemented). Yes I have a point.
>Another thought-in-a-sec-programmed-in-a-sec thingies. Syntax errors don't
>count.
Yea? since when?
>> (3) Logic: If y[1] = GET_SUCCESS and integer(y[2]) but y[2] <= 0 or
>> y[2] > length(x) or x[y] >= 31 then your version puts nothing.
>> Original version puts "That is not a valid month!\n\n". [need
>> manual fix]
>
>No, I should've put the 'else..end if' stuff before after the first end-if.
Then your version puts nothing if y[1] != GET_SUCCESS or not integer(y[2])
or y[2] <= 0 or y[2] > length(x), it only complains when x[y] >= 31.
My point is you have to repeat the else block, be it 1 statement or 100.
>However, there are cleaner ways to go about this, which are much more safe
>and readable than you approuch in the first place. First of all, all
>sections of your code that share no variables other than obvious ones should
>be placed in functions or procedures for clearity and reusability,
>esspecially something as trivial as inputting a month. However, in this case
>it might even be beter to make a type called month and verify the if the get
>() was succesful and test if the value is a month. If not, the user has to
>try again.
No, you may not make functions or types to accomplish a single if
(because they ALSO COUNT AGAINST YOUR STATEMENT COUNT).
>There are work-arounds to do what you want the way you want to do it, and
>these, I must admit, look less readable, unlike different approuches. If
>you can't think of a nice clean, safe approuch to get a month from the user
>without any need for short-circuit, ask me, and I'll give you the code you
>need.
Makes me wonder how important the non-SC-ing and/or operators are...
tell me why they are needed.
>My point is, proper is a relative. Indentation is a personal choice.
So be it -- you'll catch less logic errors.
>Trust me, my code is seen the way I typed it.
>Internally, ex.exe simply considers *any* whitespace (not matter if it is
>a -newline- and twelf tabs or a just a space) as a seperator. It seperates
>keywords, symbols and values.
>You choose to see it that way. I choose to see it the way I want to see it
>and ex.exe looks at it and converts it all the 32-bit pointers to machine
>code. (the code to execute the wanted action). Ex.exe could care less about
>your proper or nonproper indentation.
and is that innermost else being executed for failures on outside ifs?
nah...
>Euphoria is a *functional* language. It is meant to work with functions for
>the most simple and trivial tasks. Functions or types are the cleanest way
>to do this anyway.
>And the number of statements is completely irrelevent and has nothing to do
>with the programming language.
My point is, why make it necessary to make functions? You'll soon run
out of names and begin naming them shroudedly... just like Assembly,
you need lots of labels, fortunately there's still a way to overcome it.
>Like I said, use a different approuch.
approAch.
>When I draw an algorithm on paper it does not have 5 short-circuited levels
>of or and if it has it looks precizely the way the euphoria program will
>look like.
>I think the problem here is you, not nothing how to do somehting with
>euphoria easily wihtout the need of short-circuit.
Tough accusement Ralf, I'm no lawyer, but now I know why your wordings
are so sharp.
If the problem is me so what? You can keep using Euph 2.0
> Puzzle ??
> Give me an example of an usage where you would need to this, and I will
>give you an method of achieving this with the need of knowledge of euphoria
>but without the need of short-circuit.
By that you admit, "no I can't do that, I'll think of an alternative if
I were you". Lots of code in my server (in C++) use those for
optimization and not for 'need', but yes, I do test teens or more
conditions at once and want to quit evaluating as soon as a result is
determined.
What is so difficult about short-circuit?
>Statement count is irrelevent, and is the last thing that should convience
>RDS to put this in the language. Those that bring food on their table don't
>have to care about the statement count so why should RDS? They are serving
>their clients not their parasites!
Another sharp paragraph.
Oh well. Maybe I'm in such a bad mood today that I activate the not-
normally-active statement-sharpness detector in replying to 80+ mails.
Yes you're right, why should RDS? I was just suggesting!
>You don't have a file length funciton in Assembly.
>You have a dos-interrupt you can call for that (func #23)
>You can do the same in Euphoria, what in the world is your point..??
>(Plus, you can call machine code and use Pete's dynamic ASM translator)
Both Euphoria and ASM need some code to do that basic operation.
("func #23" is not a function, of course, it needs lots of code to
set up the "this func number, these are args, do it" style.)
At least Delphi, Visual Basic, Pascal, QBasic has a function to do
those.
>You'll get over it
>Oh.. so now Perl is much better, cuz I forgot a ')'.
>This is a discussion and you're trying to prove that Perl has a few nice
>things that Euphoria needs, I show you how easy Euphoria fills this, 'lack'
>in your eyes, and you try to prove otherwise by complaining about a ')' I
>forgot.. geez
>
>Readability, re-usability, safety.. statement count doesn't matter.
Nope, you're using a function to do a basic operation, in most other
languages (again) you have a function to read all the file in one go
(provided they're small enough). Euphoria has thrown away the limit,
why does it have to throw away the built-in ability and insist on
some coding by the programmer?
>> Robert Craig: Please define statement count.
>
>Why, will it bring food on his table ?
Nope, but it will not take food out of his table. Trust me
(trying to still be polite)
>Why, those who pay could care less about this, there is really no motivation
>for Robert to put this in the language..
>And what's the use of a 'am I shrouded' variable.. ?
if am_i_shrouded then
puts(2, "You may not shroud me!")
abort(255)
end if
sequence cl
integer f
cl = command_line()
f = open(cl[2], "ub")
-- self-modification code goes here...
>Because we don;t want to learn 1002312123 number of functions to use a
>programming language. Euphoria avoids many functions by using routines as
>dir () and video_config ().
>That's what we call a compromize.
>A very clean one, actually.
Alright -- at least allow
include dir.e
if compare(command_line()[2], "C:\\EUPHORIA\\TEST.EX") then
puts(2, "You have moved or renamed me! You may not do that!\n")
abort(255)
else
for i = 1 to length(command_line())
printf(1, "%s is %d bytes long.\n", {command_line()[i],
dir(command_line()[i])[1][3])
end for -- includes sizes of EX and TEST.EX
end if
>But, its even worse at this point. system () actually launches another
>shell. Not very memory efficient, not to mention speed.
Yeah, system() can only launch ONE command, i.e. getenv("COMSPEC")
>Nope, not unless I want it to be able to.
How come *you* get to decide everything here?
>Yes, still it shouldn't be able to integrate with the program.
>However an advanced form of get as an expression evaluator would be nice.
Hey, that's cool.
x = gets(0) -- "{1, \"ABC\", \'3\', {}, {{}, {1}}}\n"
x = "x = " & x -- "x = {1, \"ABC\", \'3\', {}, {{}, {1}}}\n"
if eval(x) then -- {1, "ABC", '3', {}, {{}, {1}}}
puts(1, "x is now: ")
? x -- x is now: {1,{65,66,67},51,{},{{},{1}}}
else
puts(2, "can\'t parse:\n" & x & "\n\n" & lasterror())
end if
Opinions? (It'll be executed almost as fast as in-line code, it
saves you from mistyping [doesn't abort program, just returns false
from eval], it'll be executed much faster than get()!)
>Lets consider a program that needs both. It 'needs' short-circuit and it
>*needs* normal if-fing.
Let's face it, no programs need "normal" iffing.
Uh -- except your programs...
>When I optimize it for the current version of Euphoria it will be faster,
>because the short-circuit would internally be compiled to the same as the
>'if-trick' I pulled, while the normal if-fing will go slower on this future
>fantasy version of Euphoria.
Give me an example WHY you need to do "normal" iffing.
> If you REALLY cannot find a different approuch for a problem that you
>think needs short-circuit, you can always do this:
>
> if a then if b then if c then
> end if end if end if
What about short-circuiting "or" and "else" or "elsif".
>> Try understanding how ugly it is to have an elsif, an else, ... in
>> your implementation of the short-circuit evaluation.
>
>Try reading it out loud.
>Try a different approuch.
>Try Perl, try C, or any other language offereing short-circuit. Like them ?
I do!
>the knowledge you need to solve this mystery. "What did he mean ?" Maybe I
>should give away prizes for the first one that guesses right
Ralf... your English is not fine enough for people to correctly
understand you. I'm not the only one who have trouble with this...
>> ? sequence(a) ~ length(a) : 1
>
>Ahhhhhhhhhhhhhhhhh!!!!!
>You do love mysteries don't ya ?!!
>Cuz, that is precizely what the above is, a walking mystery.
Yep, I do, but the above is no mystery to me, it's too clear.
>That's cheap.
>Visa versa. You are USED to the short-circuiting operands, because of C,
>Perl, etc. (you have the list yourself..)
Given the option, and not the experience, I would still vote for SC.
>"I dont like defining functions just to do one check"
>-- 1) Euphoria is a functional language. Which means ...
>You're using the wrong language.
Heh, correct. Why is there only thousands of Euph users and lots of
other languages' users? Why should I care about Euph anyway? 'Cause
I like it and have some "hey, if this is implemented, it'd be great"
ideas...
>-- 2) The 'I' and the 'like' prove that it is not an argument at all.
Sure, it was NOT meant as an argument :->
>I can not come up with many cases where this would be the case, on the other
>hand I can come up with millions of cases where the need for
>non-shortcuiting would be critical. (Note the need for short-circuit is not
>a critical thing, if you even want to call it a 'need' at all)
Examples?
>So, if you want C, go use C.
>Euphoria != C (thankfully)
>Euphoria != Basic
>
>Wanne know why ? Because Euphoria is better.
>The number of language that do that differently makes no argument, it only
>gives you more languages to use for those programs you need.. eh.. wait..
>you never need short-circuiting..
Actually if you're discussing "you'll never need", you DON'T need
=, !=, <=, <, or >, because with >= you can test:
a >= b with a >= b
a <= b with b >= a
a = b with (a >= b) and (b >= a)
a != b with not ((a >= b) and (b >= a))
a > b with not (b >= a)
a < b with not (a >= b)
but you have all six of them! Isn't that strange??? :->>>
>I think the problem here is that you, Andy, are too used to* the short-c
>operads.
>
>.. right ?
I have programmed in C less than I have with Euphoria, and prefers
the short-circuiting operands anyway.
Come on -- you're being inconsistent and are just trying to turn
everything sent to you back... that's not good.
|
Not Categorized, Please Help
|
|