Re: [rust-dev] Help needed writing idiomatic rust to pass sequences of strings around

2014-03-23 Thread Patrick Walton
On 3/23/14 12:11 AM, Phil Dawes wrote: On Sun, Mar 23, 2014 at 2:04 AM, Patrick Walton pcwal...@mozilla.com mailto:pcwal...@mozilla.com wrote: Why not change the signature of `search_crate` to take `~str`? Patrick Hi Patrick, The main reason I haven't done this is that it is already

Re: [rust-dev] Help needed writing idiomatic rust to pass sequences of strings around

2014-03-23 Thread Huon Wilson
On 23/03/14 18:14, Patrick Walton wrote: On 3/23/14 12:11 AM, Phil Dawes wrote: On Sun, Mar 23, 2014 at 2:04 AM, Patrick Walton pcwal...@mozilla.com mailto:pcwal...@mozilla.com wrote: Why not change the signature of `search_crate` to take `~str`? Patrick Hi Patrick, The main reason

Re: [rust-dev] Help needed writing idiomatic rust to pass sequences of strings around

2014-03-23 Thread Phil Dawes
Great, thanks Patrick + Huon On Sun, Mar 23, 2014 at 7:47 AM, Huon Wilson dbau...@gmail.com wrote: On 23/03/14 18:14, Patrick Walton wrote: On 3/23/14 12:11 AM, Phil Dawes wrote: On Sun, Mar 23, 2014 at 2:04 AM, Patrick Walton pcwal...@mozilla.com mailto:pcwal...@mozilla.com wrote:

[rust-dev] Structural Typing

2014-03-23 Thread Ziad Hatahet
Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev

Re: [rust-dev] Structural Typing

2014-03-23 Thread Daniel Micay
On 23/03/14 06:34 AM, Ziad Hatahet wrote: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala Rust used to have structural records. The feature was removed because it's far from orthogonal with

Re: [rust-dev] Structural Typing

2014-03-23 Thread Liigo Zhuang
IMO, this is bad. 2014年3月23日 下午6:34于 Ziad Hatahet hata...@gmail.com写道: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala ___ Rust-dev mailing

Re: [rust-dev] Structural Typing

2014-03-23 Thread Matthieu Monrocq
I would note that Rust macros are actually working with structural typing: the expanded macro cannot be compiled unless the expressions/statements it results in can be compiled. Regarding Scala here, it seems a weird idea to ask that each and every method should copy+paste the interface. We all

[rust-dev] How do I pass -march down to llvm from rustc?

2014-03-23 Thread Vladimir Pouzanov
I'm trying to experiment with rust and some embedded code. Currently I have to do a three-pass compilation: rustc --target arm-linux-eabi -O --emit bc main.rs -o main.bc llc -mtriple arm-none-eabi -march=thumb -mcpu=cortex-m0 main.bc -o main.s arm-none-linux-gnueabi-as main.s -o main.o First,

[rust-dev] Goto statement missing

2014-03-23 Thread Jérôme Bartand
Hello fellow Rustians, I noticed that there is no goto statement in Rust yet. Gotos are very useful e.g. for writing FSMs or for code generation and can, if used sensibly, often make code more readable than code with traditional control structures and temporary variables. Can we please have a

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Clark Gaebel
Use tail call recursion for your FSMs. On Mar 23, 2014 11:57 AM, Jérôme Bartand moije...@gmail.com wrote: Hello fellow Rustians, I noticed that there is no goto statement in Rust yet. Gotos are very useful e.g. for writing FSMs or for code generation and can, if used sensibly, often make

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Clark Gaebel
I think the biggest case for gotos is jumping out of nested loops. Does rust have a nice way of doing that yet? On Mar 23, 2014 11:57 AM, Jérôme Bartand moije...@gmail.com wrote: Hello fellow Rustians, I noticed that there is no goto statement in Rust yet. Gotos are very useful e.g. for

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Léo Testard
Hello Gotos are considered harmful for a reason. They allow you to bypass every static block scope rules. Rust is a language with many static analysis concerning typing and scope rules. I don't think goto statements integrate well in such languages. On the other hand, I never felt gotos missing

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Kang Seonghoon
2014-03-24 1:08 GMT+09:00 Léo Testard leo.test...@gmail.com: On the other hand, I never felt gotos missing when writing FSM simulation code, but we do have a very nice syntax for jumping out of nested loops : g: for i in foo.iter() { // ... h: loop { if foo { break g; }

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Léo Testard
Kang Seonghoon some...@mearie.org To be exact, it is `'g: ...` and `break 'g;` respectively. Its resemblance with the lifetime syntax is no coincidence. Woops, indeed, sorry for the mistake. There's no syntax highlighting when wirting code in emails, and I'm not very used to this new syntax.

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Patrick Walton
On 3/23/14 9:04 AM, Clark Gaebel wrote: I think the biggest case for gotos is jumping out of nested loops. Does rust have a nice way of doing that yet? There's labeled break and continue. Use `'foo:` to denote a label. (The reason that we use lifetime syntax there is that eventually it may be

Re: [rust-dev] How do I pass -march down to llvm from rustc?

2014-03-23 Thread Vladimir Pouzanov
Nevermind, I lost -O somewhere in between copying and pasting command line flags. Optimised version doesn't have any morestack references (which is strange concept though). On Sun, Mar 23, 2014 at 5:44 PM, Vladimir Pouzanov farcal...@gmail.comwrote: Figured out I can use --target

Re: [rust-dev] How do I pass -march down to llvm from rustc?

2014-03-23 Thread Vladimir Pouzanov
So it doesn't work in the end. rustc --emit bc with flags set for cortex-m0 provides exact same bc with only difference in target triple (which makes perfect sense) However, replacing llc step with rustc --emit asm provides a different assembler file, which requires __morestack. Should I expect

Re: [rust-dev] How do I pass -march down to llvm from rustc?

2014-03-23 Thread Corey Richardson
No. See https://github.com/mozilla/rust/pull/8955 and https://github.com/mozilla/rust/issues/11871 for discussion. You can stub out morestack but that won't remove the stack size checks. It's sanest to just compile the IR yourself (the stack checking is a target-specific machine pass, which is why

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Corey Richardson
Note that there's Rust support for Ragel (https://github.com/erickt/ragel), so you can just use that. It's much easier than writing out your state machines by hand. On Sun, Mar 23, 2014 at 1:18 PM, Patrick Walton pcwal...@mozilla.com wrote: On 3/23/14 9:04 AM, Clark Gaebel wrote: I think the

Re: [rust-dev] How do I pass -march down to llvm from rustc?

2014-03-23 Thread Vladimir Pouzanov
Thanks for links to bugs. Is there anything to read on the whole morestack thing? I thought that it's connected to segmented stacks that are (are they?) going away. It seems that I can use #[no_split_stack] before each and every function to generate a valid freestanding binary. If I just could

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Tony Arcieri
On Sun, Mar 23, 2014 at 11:42 AM, Corey Richardson co...@octayn.net wrote: Note that there's Rust support for Ragel (https://github.com/erickt/ragel), so you can just use that. It's much easier than writing out your state machines by hand. What kind of code is the Rust backend(s) capable of

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Tony Arcieri
On Sun, Mar 23, 2014 at 11:50 AM, Corey Richardson co...@octayn.net wrote: Yes. Cool! Who needs goto then? ;) -- Tony Arcieri ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev

Re: [rust-dev] Goto statement missing

2014-03-23 Thread Erick Tryzelaar
Yep it uses the labeled break and continue. It's not quite as fast as goto state machines because it has to use a state table to decide where to jump to. I've been thinking of a couple alternatives that could make us as fast as a c state machine. The simplest night be to leverage the fact that

Re: [rust-dev] Structural Typing

2014-03-23 Thread Ziad Hatahet
You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper around it manually then. -- Ziad On

Re: [rust-dev] Structural Typing

2014-03-23 Thread Patrick Walton
On 3/23/14 2:19 PM, Ziad Hatahet wrote: You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper

Re: [rust-dev] Structural Typing

2014-03-23 Thread Liigo Zhuang
+1 2014年3月24日 上午5:46于 Patrick Walton pcwal...@mozilla.com写道: On 3/23/14 2:19 PM, Ziad Hatahet wrote: You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function

Re: [rust-dev] Refactor json.rs

2014-03-23 Thread Sean McArthur
How is it different from having the generic on the trait itself? On Mar 22, 2014 10:44 AM, comex com...@gmail.com wrote: On Sat, Mar 22, 2014 at 10:24 AM, Edward Wang edward.yu.w...@gmail.com wrote: But of course, it is very uncivilized :) Any suggestion on how to refactor this piece of

Re: [rust-dev] Structural Typing

2014-03-23 Thread Ziad Hatahet
Thanks for the feedback everyone. It makes sense how things currently are for Rust. Keep up the great work! -- Ziad On Sun, Mar 23, 2014 at 4:54 PM, Liigo Zhuang com.li...@gmail.com wrote: +1 2014年3月24日 上午5:46于 Patrick Walton pcwal...@mozilla.com写道: On 3/23/14 2:19 PM, Ziad Hatahet wrote: