5 ms·
You're missing something. The semantics of `ret` are always consistent: it always returns from out the innermost `fn()` declaration (closures written using the
by nikomatsakis 15y ago
You're missing something. The semantics of `ret` are always consistent: it always returns from out the innermost `fn()` declaration (closures written using the sugared notation `{||...}` do not count as fn declarations, but closures written as `fn() { ... }` do). In cases where this is not possible, a static error is generated.
- vilya 15y agoSo what happens if we pass a stack closure containing a ret into another function? For example, what would this code print out: fn foo(f: fn()) { log(info, "calling f"); f(); log(info, "called f"); } fn bar() { log(info, "calling foo"); foo({|| ret; }); log(info, "called foo"); } I'm not clear on whether the ret would return from foo or from bar - or whether it would be a compile error. BTW thanks for taking the time to reply - I appreciate it!
- kibwen 15y agoTried compiling this myself with a main function that just calls bar(), resulting in a compiler error: `ret` in block function