When you say that "all hell breaks loose" if the target frame is not
active, what do you mean? Some kind of runtime error?
I thought the work with monads and option types was there to avoid this
kind of problem.
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. 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?
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.
This non-local goto looks like the devil to me. 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.
On Sat, Aug 18, 2012 at 9:08 PM, john skaller <skal...@users.sourceforge.net
> wrote:
> I've just implemented this:
>
> proc A (x:int) {
> proc B (y:int) {
> println$ "B start";
> return from A; // <<-------------
> println$ "B again BAD";
> }
> println$ "Here is A";
> B 2;
> println$ "Here is A BAD";
> return;
> _endof_A:>
> println$ "Fast exit from A";
> }
>
> A 22;
>
> Basically "return from p" terminates the current
> procedure and all parents up to the named procedure's
> most recent stack frame, and is equivalent to doing a non-local
> goto to the end of the procedure p.
>
> In the last commit you have to manually put the sequence
>
> return;
> _endof_X:>
>
> at the end of the procedure you want to return from. I will remove that
> requirement shortly.
>
> This features provides a way to shortcut a loop or other algorithm,
> when you find a result. Like goto, the target must be visible and
> it must be active (or all hell breaks loose). You can put this instruction
> in a closure but the parent must be active when the closure is invoked,
> i.e. there has to be an active call chain to pop off the "stack".
>
> I don't think you can goto out of a procedure nested inside a function
> nested in a procedure.
>
> I will also do a functional equivalent if I can, it's basically the same
> except it returns a value. This would be done by returning a magic
> variable after the target label, and assigning it at the return point,
> however there's a minor problem with this implementation
> that it technically breaks the rule that functions can't have side effects
> by assigning values outside their own scope. At present this isn't
> checked by Felix so it will work, but if a check is later added some
> special handling may be needed to cope with fast exits.
>
> In both cases, this construction is "better" than the alternatives
>
> (a) throw an exception
>
> (b) return a union all the way up the call chain, which must then
> be decoded after every application to detect a fast exit.
>
> Note (b) could never work for procedures since they don't return values.
> Generally (b) would be a mess to implement. Exceptions can't be used
> for procedures anyhow, since they don't have machine stack frames.
>
> --
> john skaller
> skal...@users.sourceforge.net
> http://felix-lang.org
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Felix Language" group.
> To post to this group, send email to felix-langu...@googlegroups.com.
> To unsubscribe from this group, send email to
> felix-language+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/felix-language?hl=en.
>
>
------------------------------------------------------------------------------
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