On Sun, Feb 24, 2013 at 12:06 AM, Ashish Myles <marci...@gmail.com> wrote:
> On Fri, Feb 22, 2013 at 12:35 PM, John Clements
> <cleme...@brinckerhoff.org> wrote:
>>
>> On Feb 22, 2013, at 6:22 AM, Paul Stansifer wrote:
>>
>> > Rust syntax expects a literal number in the `[T * n]` construct; from the 
>> > parser's point of view, what it receives is an expression, without any 
>> > information that it is a number. (There are internal reasons for this, but 
>> > it also makes the behavior of `$` more consistent; for example, preventing 
>> > Rust from having C's issue where everybody has to use lots of parentheses 
>> > in macro definitions.) Implementing $n:integer in Rust is a possible 
>> > solution, but not likely to happen very soon.
>> >
>> > Unfortunately, I can't think of a workaround that generates the same type.
>>
>> More or less as a note to myself and Paul: I claim that this problem would 
>> be solved by a token-tree-based macro system.
>>
>> John
>>
>
> I just want to add for consideration: I hope the (eventually)
> implemented solution allows compile-time evaluable integer expressions
> for maximal expressivity. Same thing for $n:bool, etc, if implemented.
>

Wait a sec...I guess we are barking up the wrong tree.  The problem is
not that rust macros don't support $n:integer, but that static array
initialization seem to require a raw integer literal (possibly at the
parsing level).  One can imagine designing a statically-allocated
matrix for size C1 x C2 that would allocate similar to:
    const C1 : int = 2;
    const C2 : int = 2;
    let a : [int * (C1*C2)] = [1,2,3,4];
But the code above gives the following error
    error: expected integral vector length but found `(`

If this misbehavior were fixed, I think the macro system would not
need to accommodate ints and other types specially, keeping it
fundamentally simpler.  I would think that anything that requires a
compile-time integer should be able to receive a compile-time
evaluable integer expression.  Ideally, it would be great if Rust went
further to allow something like
    let a : [int * choose(C1, C2)];
or
    const C3 = choose(C1, C2);
    let a : [int * C3];
where choose is a pure function that returns n-choose-k.

Any thoughts?
Ashish
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to