Re: [rust-dev] Porting some nesC features to rust?

2014-04-02 Thread Ashish Myles
And just in case there is a confusion (as I have noticed others to have), it might help to see a specific example comparing static dispatch with dynamic. // This is a single function for all types implementing the LCD Trait. fn foo(x : &LCD) { // x's type is &LCD rather than the actual type of the

Re: [rust-dev] Possible bug? os::args() then split then print

2014-02-25 Thread Ashish Myles
On Tue, Feb 25, 2014 at 11:00 AM, Phil Dawes wrote: > fn main() { > let arr : ~[&str] = std::os::args()[1].split_str("::").collect(); > std::io::println("first " + arr[0]); > std::io::println("first again " + arr[0]); > } > I am working on an older version of the compiler that fails

Re: [rust-dev] How to use dynamic polymorphism with collection

2014-02-08 Thread Ashish Myles
On Sat, Feb 8, 2014 at 6:48 PM, Ashish Myles wrote: > > On Sat, Feb 8, 2014 at 1:21 PM, Philippe Delrieu > wrote: > >> pub trait Base { >> fn do_base(&self); >> } >> >> struct TestBase; >> >> impl Base for TestBase

Re: [rust-dev] How to use dynamic polymorphism with collection

2014-02-08 Thread Ashish Myles
On Sat, Feb 8, 2014 at 1:21 PM, Philippe Delrieu wrote: > pub trait Base { > fn do_base(&self); > } > > struct TestBase; > > impl Base for TestBase{ > fn do_base(&self){ > println!("ici"); > } > } > > trait GenerciFn{ > fn do_generic(&self, base: &T); > } > > st

rust-dev@mozilla.org

2014-01-19 Thread Ashish Myles
Thanks! I appreciate the detailed answers and look forward to future changes. :) And I had already run into and started reading Niko's article you linked for DSTs. I love the thorough analyses you guys go through for each feature. Ashish On Sun, Jan 19, 2014 at 1:17 PM, Alex Crichton wrote: >

Re: [rust-dev] Cloning a statically-sized array

2014-01-19 Thread Ashish Myles
add others). Not ideal, but useful until this > gets straightened out. > > > > > > On Sun, Jan 19, 2014 at 12:19 AM, Daniel Micay wrote: > >> On Sun, Jan 19, 2014 at 12:17 AM, Ashish Myles >> wrote: >> > Now, I already know that statically-sized arrays of

rust-dev@mozilla.org

2014-01-19 Thread Ashish Myles
Thanks for the detailed explanations! On Sun, Jan 19, 2014 at 2:01 AM, Alex Crichton wrote: > > fn borrow1<'a>(&'a self) -> &'a int { > > match (self) { > > // error: mismatched types: expected `&'a int` but found > `~int` > > // (expected &-ptr but found ~-pt

[rust-dev] Cloning a statically-sized array

2014-01-18 Thread Ashish Myles
Now, I already know that statically-sized arrays of primitives are implicitly copyable, but consider, for example, a statically-sized array of a non-copyable but Clone-able type. I find that for v of type [T, ..2], v.clone() is not a static array. Perhaps it's because v is being implicitly treate

rust-dev@mozilla.org

2014-01-18 Thread Ashish Myles
I understand as per a previous discussion that the owned box ~[T] doesn't quite have the semantics of a unique *pointer*. Below include my successes in some borrowing scenarios and analogous failed attempts at borrowing a reference to a unique pointer to an array within a FooVec struct. How do I d

Re: [rust-dev] Macros expanding to multiple statements

2014-01-11 Thread Ashish Myles
tln!("{:?}", b); > } > ); > ) > > Multi-statement macros are covered by > https://github.com/mozilla/rust/issues/10681 . > > > Huon > > > > On 12/01/14 13:40, Ashish Myles wrote: > > Rust 0.9 indicates that support for expansion of macros

[rust-dev] Macros expanding to multiple statements

2014-01-11 Thread Ashish Myles
Rust 0.9 indicates that support for expansion of macros into multiple statements is now supported, and the following example from the test suite works for me. https://github.com/mozilla/rust/blob/master/src/test/run-pass/macro-multiple-items.rs However, I receive an error for the following code #

Re: [rust-dev] What type to put for index when impl-ing Index?

2014-01-08 Thread Ashish Myles
gt; let foo = Foo([1.0, 2.0, 3.0]); > println!("{:?}", foo[tmp]); > } > > On 9 Jan 2014, at 2:08 pm, Ashish Myles wrote: > > > The following implementation of Index for Foo works fine. > > > > struct Foo([f64, ..3]); > > impl Index for Foo {

[rust-dev] What type to put for index when impl-ing Index?

2014-01-08 Thread Ashish Myles
The following implementation of Index for Foo works fine. struct Foo([f64, ..3]); impl Index for Foo { fn index(&self, index: &uint) -> f64 { match self { &Foo(ref v) => v[*index].clone() } } } fn main() { let tmp : uint = 0; let foo = Foo([1.0, 2.0, 3.0

Re: [rust-dev] Auto-borrow/deref (again, sorry)

2013-12-28 Thread Ashish Myles
I think I see the confusion (as I suffered from the same point of confusion). So let me restate your answer and please correct me of I am wrong. 1. "mut int" and "& mut int" are different types and the former doesn't automatically convert to the latter. 2. The way to get the latter from the former

Re: [rust-dev] Define copyable types for [T, ..2] static vector initialization

2013-11-29 Thread Ashish Myles
(i)); > } > } > ary > } > > > This would let you call it like Foo(array::from_fn(|_| Zero::zero())). > > -Kevin > > On Nov 29, 2013, at 8:37 PM, Ashish Myles wrote: > >> That's some seriously nifty stuff, which got my stuff compiling again.

Re: [rust-dev] Define copyable types for [T, ..2] static vector initialization

2013-11-29 Thread Ashish Myles
ntrinsics::uninit(); > for i in range(0u, SZ as uint) { > intrinsics::move_val_init(&mut ary[i], Zero::zero()); > } > } > Foo(ary) > } > } > > -Kevin > > On Nov 29, 2013, at 7:05 PM, Ashish Myles wr

Re: [rust-dev] Define copyable types for [T, ..2] static vector initialization

2013-11-29 Thread Ashish Myles
? On Nov 29, 2013 6:47 PM, "Huon Wilson" wrote: > On 30/11/13 10:33, Ashish Myles wrote: > >> Previously we had the Copy trait, which when implemented by trait T >> allowed one to write >> [Zero::zero(), ..SZ] where T implemented the Zero trait. But now I am &g

[rust-dev] Define copyable types for [T, ..2] static vector initialization

2013-11-29 Thread Ashish Myles
Previously we had the Copy trait, which when implemented by trait T allowed one to write [Zero::zero(), ..SZ] where T implemented the Zero trait. But now I am not sure how to get that behavior. Concretely, here is the code I want to get compiling. (Just to check, I added both Clone and DeepClone,

Re: [rust-dev] Why separate equivalent impls for &'self [A], ~[A], @[A]

2013-07-08 Thread Ashish Myles
On Sat, Jul 6, 2013 at 10:26 PM, Daniel Micay wrote: > On Sat, Jul 6, 2013 at 10:09 PM, Ashish Myles wrote: >> Perhaps this was an oversight as the code base has developed >> organically. But in case it was intentional, I just wanted to check. >> >> libstd/to_str.rs de

[rust-dev] Why separate equivalent impls for &'self [A], ~[A], @[A]

2013-07-06 Thread Ashish Myles
Perhaps this was an oversight as the code base has developed organically. But in case it was intentional, I just wanted to check. libstd/to_str.rs defines each of the following impls impl<'self,A:ToStr> ToStr for &'self [A] impl ToStr for ~[A] impl ToStr for @[A] whereas only the first

Re: [rust-dev] deriving Clone on a struct with a static vector

2013-07-06 Thread Ashish Myles
On Sat, Jul 6, 2013 at 5:45 AM, Jason Fager wrote: > I've started implementing traits for fixed-length vectors with a few macros: > > https://gist.github.com/jfager/5936197 > > I don't have Clone yet, but it should be easy to add. > As a side note, looking through your code, this is cool: st

Re: [rust-dev] deriving Clone on a struct with a static vector

2013-07-06 Thread Ashish Myles
On Sat, Jul 6, 2013 at 1:43 AM, Patrick Walton wrote: > On 7/5/13 10:42 PM, Ashish Myles wrote: >> >> And an additional question. >> 3. What is the rationale in having both Copy and Clone? Can one >> provide an exhaustive list for where one would want to use Copy &g

Re: [rust-dev] deriving Clone on a struct with a static vector

2013-07-05 Thread Ashish Myles
And an additional question. 3. What is the rationale in having both Copy and Clone? Can one provide an exhaustive list for where one would want to use Copy instead of Clone/DeepClone? I tried to use clone everywhere, but I needed to be able to write, for example, [Zero::zero(),.. 3] as in the fo

[rust-dev] deriving Clone on a struct with a static vector

2013-07-05 Thread Ashish Myles
1. The following code #[deriving(Clone)] struct V { v : [f64, ..3] } fn main() { } gives the following error tmp.rs:1:11: 1:16 error: mismatched types: expected `[f64, .. 3]` but found `&[f64, .. 3]` (expected vector but found &-ptr) tmp.rs:1 #[deriving(Clone)] Is this inte

[rust-dev] Borrow lifetime assignment changed?

2013-07-03 Thread Ashish Myles
Any idea why the following fails use std::{io,rand,task}; fn main() { for ["Alice", "Bob", "Carol"].iter().advance |&name| { do task::spawn { use std::rand::RngUtil; let v = rand::rng().shuffle([1, 2, 3]); for v.iter().advance |&num| {

Re: [rust-dev] Rust 0.7 prerelease testing

2013-07-03 Thread Ashish Myles
On Wed, Jul 3, 2013 at 4:00 PM, Ashish Myles wrote: > openSUSE 12.2 (i.e. previous release). "make check" succeeds: > > summary of 25 test runs: 5261 passed; 0 failed; 302 ignored > To clarify, I did the check against trunk (0c6fc46c030ab0515a052fa99c9e10c75c

Re: [rust-dev] Rust 0.7 prerelease testing

2013-07-03 Thread Ashish Myles
openSUSE 12.2 (i.e. previous release). "make check" succeeds: summary of 25 test runs: 5261 passed; 0 failed; 302 ignored ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev

Re: [rust-dev] Front page example

2013-06-23 Thread Ashish Myles
Great, thanks, it works! Is there a way to invoke the shuffle() without bringing it explicitly into local scope, say via some verbose way that specifies the trait to be used? Ashish On Sat, Jun 22, 2013 at 11:00 PM, Huon Wilson wrote: > On 23/06/13 12:53, Ashish Myles wrote: >> >&

[rust-dev] Front page example

2013-06-22 Thread Ashish Myles
I have been out of rust for a bit, and coming back to it, I am having a difficult time adapting the front page example at http://www.rust-lang.org/ to the trunk version of rust (updated last night). I turned the example to use std::*; fn main() { for ["Alice", "Bob", "Carol"].each |&

[rust-dev] tjc's pre-talk and talk (was: This Week in Rust)

2013-06-22 Thread Ashish Myles
> - tjc's pre-talk and talk, "Rust: A Friendly Introduction" went very well. The > [slides](http://catamorphism.org/Writing/Rust-Tutorial-tjc.pdf) are up, and > a recording is coming soon (hopefuly). tjc says the slides aren't as > understanable without the audio of the talk. Thanks for the

Re: [rust-dev] Calling static methods on type parameters?

2013-04-28 Thread Ashish Myles
Ha! I asked the same question when I first started. I wouldn't be surprised if this is a common cause of confusion for people coming from C++ and that name resolution family. Perhaps notes regarding this could be added to https://github.com/mozilla/rust/wiki/Rust-for-CXX-programmers ? Ashish On

[rust-dev] Macro bugs or misunderstanding of use?

2013-04-09 Thread Ashish Myles
Hi, I am running the rust compiler from trunk. My macro usage seems to be a macro_rules! my_print( ($a:expr, $b:expr) => ( io::println(fmt!("%d", a)); io::println(fmt!("%d", b)); ); ) fn main() { let a : int = 1; let b : int = 2; my_print!(a, b); }

Re: [rust-dev] How to use concat_idents! properly

2013-03-02 Thread Ashish Myles
On Sat, Mar 2, 2013 at 2:20 PM, Ashish Myles wrote: > On Sat, Mar 2, 2013 at 1:41 PM, Paul Stansifer > wrote: >> >> `concat_idents!` is currently broken, and it's my fault. Here's a >> discussion of how it might be fixed in the future: >> https://

Re: [rust-dev] How to use concat_idents! properly

2013-03-02 Thread Ashish Myles
On Sat, Mar 2, 2013 at 1:41 PM, Paul Stansifer wrote: > > `concat_idents!` is currently broken, and it's my fault. Here's a > discussion of how it might be fixed in the future: > https://mail.mozilla.org/pipermail/rust-dev/2013-February/003170.html Sadly, > there is no workaround. Perhaps it shoul

[rust-dev] How to use concat_idents! properly

2013-03-02 Thread Ashish Myles
So far, I have had a difficult time finding anything definitive on this except for some rust test code. fn main() { // PART 1: works (from rust test code) let asdf_fdsa = ~"<.<"; io::println(concat_idents!(asd, f_f, dsa)); io::println(stringify!(use_mention_distinction)); // P

Re: [rust-dev] I wanted a dollar but you gave me a ... dollar?

2013-02-24 Thread Ashish Myles
On Sun, Feb 24, 2013 at 3:03 PM, Ashish Myles wrote: > > 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 > pars

Re: [rust-dev] I wanted a dollar but you gave me a ... dollar?

2013-02-24 Thread Ashish Myles
On Sun, Feb 24, 2013 at 12:06 AM, Ashish Myles wrote: > On Fri, Feb 22, 2013 at 12:35 PM, John Clements > 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 >

Re: [rust-dev] I wanted a dollar but you gave me a ... dollar?

2013-02-23 Thread Ashish Myles
On Fri, Feb 22, 2013 at 12:35 PM, John Clements 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 nu

[rust-dev] I wanted a dollar but you gave me a ... dollar?

2013-02-21 Thread Ashish Myles
Thanks for all the corrections and feedback so far. Another strange one that has me stumped. This one gives me a strange error that reads like the e-mail subject. macro_rules! VectorT { ($Vec:ident, $n:expr) => ( struct $Vec { priv mut m_v: [T * $n]; } ); }

[rust-dev] Simple use of templates/generics compilation hassles

2013-02-21 Thread Ashish Myles
Well, I eventually figured out how to get things compiling, but it was highly non-obvious. I would appreciate it if someone could shed some light on why things behave this way so that I may learn to visually "see" the error. Say we have the following struct pub struct Vector3 { priv mu

Re: [rust-dev] Many little questions while writing a Vector class

2013-02-21 Thread Ashish Myles
Thanks for all the answers. On Thu, Feb 21, 2013 at 9:17 AM, Niko Matsakis wrote: > > > Ashish Myles wrote: > >> Lots of questions. >> >> 1. Is there an array string join function? I looked through possible >> pertinent vector- and string-related modul

[rust-dev] Many little questions while writing a Vector class

2013-02-20 Thread Ashish Myles
Lots of questions. 1. Is there an array string join function? I looked through possible pertinent vector- and string-related modules and I didn't see something equivalent. 2. Any particular reason to_str() for arrays (defined in in std::to_str) is defined only for unique arrays? i.e.

[rust-dev] Cloning managed memory between tasks?

2013-02-20 Thread Ashish Myles
I didn't much previous discussion on this topic on google. Sorry if I missed something and re-starting an old discussion. Here is an example from the manual of a standard lisp-style list. enum List { Nil, Cons(T, @List) } If one wished to move such a list to another task, a copy to unique

[rust-dev] Parametrizing traits by integers (or equivalent behavior)

2013-02-18 Thread Ashish Myles
Firstly, as this seems to be the only discussion mailing list for rust, I presumed that this might be a good place to ask newbie-ish questions. Please correct me if I am wrong. (I have previously played around with D, which has separate mailing lists for learners.) I am particularly interested in