[rust-dev] 2 possible simplifications: reverse application, records as arguments

Benjamin Striegel ben.striegel at gmail.com
Sat Apr 14 09:00:39 PDT 2012


So this would basically mean that a function like:

fn wtever(foo: int, bar: str) { ... }

could be called as either:

wtever(1, "hello");  // "tuple" syntax
wtever{foo: 1, bar: "hello"};  // "record" syntax

Not sure how I feel about invoking a function using a record literal, its'
a little bit elegant but it also feels clunky to have different enclosing
glyphs depending on if you want to pass by name or by position. What I'd
*really* love is just for Rust to have optional named parameters in
function invocations, like so many other languages have. Then you could do:

wtever(1, "hello");
wtever(foo: 1, bar: "hello");
wtever(1, bar: "hello");  // not possible using just tuple and record
literals!

AFAIK named parameters aren't supported in C++, so this could be an area
where Rust really improves upon it.

On Sat, Apr 14, 2012 at 6:10 AM, David Rajchenbach-Teller <
dteller at mozilla.com> wrote:

> On 4/14/12 8:07 AM, Kobi Lurie wrote:
> > such a flurry of activity here :-D
> >
> > I saw a few things I liked, in the felix language (and some that are
> > above my head for now.)
> >
> > Do you think they fit rust well or not?
> >
> > one is reverse application.
> > it's actually logical and might simplify things.
> > (similar to extension methods in c#)
> > there are no classes, but a syntax like: obj.method(b,c) still exists.
> > from what I could tell, the function is really method(obj,b,c), and the
> > previous syntax gets translated to it. which is just nicer for the
> > programmers, minimizing parentheses.
>
> Looks like a nasty case of overloading of |method|, though :/
>
> > another thing is that instead of passing arguments, you pass just one
> > (anonymous) record. the record is the arguments.
> > which means, that argument names become mandatory, and the order
> > wouldn't matter.
> > or alternatively, a tuple, and then names don't matter. (personally I
> > prefer the record with explicit names)
> > from the calling side it looks the same.
>
> I personally like a lot the idea of being able to label arguments.
>
> > actually there is a third one, virtual sequences, as I saw in the factor
> > programming language (which is a really cool language btw, very nicely
> > done)
> > http://docs.factorcode.org/content/article-virtual-sequences.html
>
> Not sure I understand. Is that a variant on enumerations or streams?
>
> Cheers,
>  David
>
>
> --
> David Rajchenbach-Teller, PhD
>  Performance Team, Mozilla
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120414/94ed6030/attachment.html>


More information about the Rust-dev mailing list