Hello list (new here),

May I comment on a post from this Monday?

Heri Sim posted:
> 1st, dereferencing should be automatic everywhere.
> Running a pattern match on borrowed boxes should NOT require an asterisk
> (*).
> Passing in a stack-local variable to a function or closure (that
> requires arguments to be passed by reference), should not require the
> ampersand (&) in the caller. Why can't the compiler figure this out?

I agree with the majority on the list that requiring use of the ampersand when 
calling is a useful feature, but why not automatic dereferencing everywhere? 
There are two problems with this, namely comparison and assignment.

For the former, I think D really got it right with `x is y` to compare 
references and `x == y` to compare objects/boxes. In the case of references to 
references (e.g. ~@int) it would have to be decided which references were 
compared by "is", but in any case "&" can be used to get a reference to 
compare.

Assignment could similarly be done with a new syntax to *assign to the box 
referenced by* a pointer, e.g. x <- y. Unfortunately that doesn't cover 
multiple levels of boxing. An alternative might be not auto-dereferencing 
assignment targets or use of `&x` to "undo" a level of dereferencing (instead 
of merely take the address of):

        let mut a : ~int = ~1
        a = 2   // assign to box
        &a = ~3 // assign to reference

I'm not quite sure about assignments but for other cases this seems beneficial 
to me (especially since it avoids most of the syntax changes involved in 
replacing an unboxed parameter with a boxed parameter).


Second thing: why are semicolons required at the end of lines at all? Go, 
Scala etc. manage fine without.

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

Reply via email to