On 2/17/12 7:18 AM, Andrew Pennebaker wrote:
ssylvan, as a Lisper I would be in favor of having fn name(args) ... desugar to let name = fn(args) ... where fn is essentially lambda.

I am not in favor of removing named fn items for several reasons.

1. I like that named functions do not inherit their environment. I find that for long functions I typically only want one or two variables from the environment, and inheriting more than that is inviting bugs, as those other variables are not meant to be used. This could admittedly be addressed by requiring explicit capture clauses.

2. In addition, the order of closure construction is very significant in Rust, particularly when you do things like move data into a closure. But declarations like "fn foo()" do not look like side-effecting statements, although they would be. Also, item decl order is generally insignificant in Rust, but this would no longer be the case.

3. Finally, the issue of mutually recursive functions would become quite annoying. As I understand it, this proposal would mean that functions inherit the names that appear before their declaration, making it hard to write a mutually recursive function declaration. If you decide to inherit all names from the parent, then it becomes quite challenging to know whether all variables that might be used have been initialized. You end up needing a `let rec` form or something like that.

No doubt these issues can be addressed, but just making "fn foo(x,y)" sugar for "let foo = {|x, y| ...}" will not be very usable by itself (imo).


Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to