The thought is that you should be able to do it with static variables
(ones that are known at compile time, like his example)

This is known as Compile Time Function Evaluation, I know there's been
some work on it, and you can probably search the RFCs to figure out
the status currently.

On Wed, Sep 24, 2014 at 11:30 AM, John Clements
<[email protected]> wrote:
>
> On Sep 17, 2014, at 7:04 AM, Daneel Yaitskov <[email protected]> wrote:
>
>> Hi,
>>
>>
>> Does Rust macro have flow control based on a variable value?
>>
>> I didn't find such info here  http://doc.rust-lang.org/guide-macros.html.
>>
>> I'd like to get a macro expading a for loop.
>>
>> doTimes(3, println!("DDDD"))
>> =>
>> println!("DDDD")
>> println!("DDDD")
>> println!("DDDD”)
>
> Perhaps I’m misunderstanding you, but in general that’s impossible. 
> Specifically, variable varues aren’t known at runtime. So, for instance, if 
> you wrote
>
> doTimes(x, println!(“DDDD”))
>
> … there’s no way (in general) to know the value of ‘x’ until the program is 
> run.
>
> Is there some reason you can’t just use a function call, here?
>
> John Clements
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to