On Sun, Aug 19, 2012 at 10:50 PM, john skaller <
skal...@users.sourceforge.net> wrote:
>
> On 20/08/2012, at 3:07 PM, Dobes Vandermeer wrote:> Maybe I've been overly
> brainwashed by the "goto haters" out there but I don't think returning an
> opt[] or other union type is all that bad.
>
> You're missing the context. Consider this:
>
> fold_left (fun (acc:bool) (elt:bool) => acc and elt)
> somelistofbool;
>
> This calculates the "and" of all the bools in the list. On average it is
> twice
> as slow as it needs to be because it doesn't exit as soon as the
> accumulator
> becomes false. Once you're inside the fold, you cannot stop it.
>
Wouldn't it sense to define a "contains" operations that searches for
"false" instead?
It seems like any algorithm that requires a goto can be rearranged into one
that doesn't require it and is just as fast.
> > Or for a proc putting it into a shared var somewhere. How is this done
> in OCaml and Haskell? Or is that a terribly broken experience in those
> languages?
>
> It's broken in Ocaml. In Ocaml, you would use an exception for an early
> exit.
> This works fine if you remember to catch it :) However exception handlers
> in Ocaml defeat tail recursion optimisation (if they're in the wrong place)
> since a tail call wrapped in a try block is not actually in tail position.
>
Strange, in Scala they just offer versions of the operation with an early
exit. For example you can define operations like foldWhile() that stop if
you return None and return the last non-None value it got.
> Let's say you want to write some procedure like for_lines_in_file(...)
> that calls a procedure for each line in a file, then closes the file. If
> someone does one of these non-local gotos out of that loop, will you still
> close the file? I'm guessing not.
>
> Not if they jump past the close.
>
:-(.
> > This non-local goto looks like the devil to me.
>
> It is.
>
> you need to first understand that Felix low level language has
> (conditional) goto because
> it is the basis on which all control structures are built. Loops, tail
> recursion, all of these
> things require goto. That's the underlying machine instruction. Its a
> superior pain
> C doesn't have computed gotos (if you're running gcc it does have and Felix
> uses it, its much faster than switch).
>
This non-local goto thing looks more like something you were intending to
make use of ...
> Non-local gotos sound evil, but we have to have them, to allow wrapping
> code in blocks (functions or procedures) temporarily, then inlining them.
> That makes the previously non-local goto local again, but this happens
> after type checking.
>
Hmmm I don't understand what you're saying here, maybe it's too late at
night.
> > The further down this road of non-local gotos (and gotos in general)
> you go, the more you are going to turn people off the language, not to
> mention adding to the list of dangerous and confusing language misfeatures
> you've got that already will turn people off the language when they learn
> of them.
>
> You do not have to use them. We don't even have to document them.
> Goto isn't a misfeature. Its essential. You cannot define a for loop,
> while loop,
> or anything else without a conditional goto.
>
Right, but that is in the output language, not the input language.
> It's not necessary that the goto be in the concrete syntax.
> We could leave it out. Then you would have to use Scheme action codes
> of the parser to define loops. You would not be able to do it in the
> library.
>
Using goto under the hood is necessary to implement your lightweight
threads, I recognise that. It's an implementation detail.
But the way you presented this non-local goto thing is like it is something
you expect people to use for something. I don't like it ... as someone who
is paranoid I want to know that if I allow someone to give me a procedure
to call that I can know when that procedure exits.
I'm not a huge fan of exceptions either, but at least they can be "caught"
and you can use a "finally" block to release any resources you've
accumulated on the way in. The non-local goto doesn't just bypass that, it
makes it impossible.
Perhaps this just means another feature is needed which allow one to do a
try ... finally ... sequence that the non-local goto agrees to call on its
way by.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language