Subject: | TODO: value semantics |
There's two parts to this feature - the syntax, and the implementation.
Syntax-wise, I wonder if it would be nicer to keep the 'try' syntax purely for control flow, similar to things like 'if' and 'foreach', and add different looking syntax for value-returning semantics, so that the reader is less surprised by nonobvious behaviour.
Perhaps the 'do' keyword could be used here as is used in other bits of perl syntax, e.g.
my $value = do try { ... } catch { "default" };
my $value = try do { ... } catch { ... };
Implementation-wise, there are difficulties in propagating the runtime gimme context correctly into the body of the try block. Solving this one might require creating a new runtime op that can adjust the context dynamically. In particular, static analysis isn't good enough in such situations as 'do try' blocks being returned in tail position of a function
sub { ...; return do try { foo() } }
--
Paul Evans