Could a macro work just as well here?

On Mon, Aug 12, 2013 at 3:10 PM, Armin Ronacher <[email protected]
> wrote:

> Hi,
>
> I was just thinking about that again, and I wonder if that could be used
> to create a pattern for initialization "literals" for collections.
>
> Once we have "yield fn" there could be syntax that converts initialization
> code into a generator that is passed to a function call:
>
>
>     let mut l = List::literal() {{
>         ~"foo",
>         ~"bar"
>     }};
>
>     /* -> */
>
>     let mut l = List::literal((yield || -> Iterator<(~str)> {
>         yield return ~"foo",
>         yield return ~"bar"
>     }})());
>
>
> And as an extension to make hashmap syntax nicer:
>
>
>     let mut hm = HashMap::literal() {{
>         ~"foo" => 1,
>         ~"bar" => 2
>     }};
>
>     /* -> */
>
>     let mut hm = HashMap::literal((yield || -> Iterator<(~str, int)> {
>         yield return (~"foo", 1),
>         yield return (~"bar", 2)
>     }})());
>
>
> Unfortunately it could not be HashMap::new() because we can't have
> functions with different argument counts :(
>
>
> Regards,
> Armin
> ______________________________**_________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to