www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Mozilla Rust 0.1

reply dennis luehring <dl.soluz gmx.net> writes:
The Rust compiler 0.1 is unleashed

http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/

looks nice - but rusts #fmt macro is nothing compared to std.metastrings
and is not even library based :)
Jan 23 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/23/2012 11:50 PM, dennis luehring wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/


 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

It's hard to find any definitive information, but Rust appears to have no exception handling and no generics.
Jan 24 2012
parent reply dennis luehring <dl.soluz gmx.net> writes:
Am 24.01.2012 10:40, schrieb Walter Bright:
 On 1/23/2012 11:50 PM, dennis luehring wrote:
  The Rust compiler 0.1 is unleashed

  http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/


  looks nice - but rusts #fmt macro is nothing compared to std.metastrings
  and is not even library based :)

It's hard to find any definitive information, but Rust appears to have no exception handling and no generics.

generics like are here described http://doc.rust-lang.org/doc/tutorial.html#generics but for exceptions they only got the fail()-thing http://doc.rust-lang.org/doc/tutorial.html#failure
Jan 24 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/24/2012 1:58 AM, dennis luehring wrote:
 Am 24.01.2012 10:40, schrieb Walter Bright:
 On 1/23/2012 11:50 PM, dennis luehring wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/



 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

It's hard to find any definitive information, but Rust appears to have no exception handling and no generics.

generics like are here described http://doc.rust-lang.org/doc/tutorial.html#generics

Ok. No metaprogramming, though.
 but for exceptions they only got the fail()-thing

 http://doc.rust-lang.org/doc/tutorial.html#failure

I found this: "The str type in Rust is represented exactly the same way as a vector of bytes ([u8]), except that it is guaranteed to have a trailing null byte (for interoperability with C APIs)." 0 terminated strings are a source of a lot of speed issues in C and C++ code. and: "Like vectors, strings are always unique. You can wrap them in a shared box to share them. Unlike vectors, there is no mutable variant of strings. They are always immutable." No slicing.
Jan 24 2012
prev sibling next sibling parent Gour <gour atmarama.net> writes:
On Tue, 24 Jan 2012 08:50:25 +0100
dennis luehring <dl.soluz gmx.net> wrote:

 The Rust compiler 0.1 is unleashed
=20
 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_c=

ommunity_release_rust_01_a/
=20
 looks nice - but rusts #fmt macro is nothing compared to
 std.metastrings and is not even library based :)

This looks nice: - A self-hosted (written in Rust) compiler, which uses LLVM as a backend. Sincerely, Gour --=20 The embodied soul may be restricted from sense enjoyment,=20 though the taste for sense objects remains. But, ceasing=20 such engagements by experiencing a higher taste,=20 he is fixed in consciousness. http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810
Jan 24 2012
prev sibling next sibling parent reply Ary Manzana <ary esperanto.org.ar> writes:
On 1/24/12 4:50 AM, dennis luehring wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/


 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

I can't believe people are still creating languages with curly-brace syntax. And also, what's the advantage of the language? Having to type "fn" instead of "function" or "def"? Having to type "iface" instead of "interface"? Just look at this: fn mk_appender(suffix: str) -> fn (str) -> str { let f = fn (s: str) -> str { s + suffix }; ret f; } YUCK! </rant>
Jan 24 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 01/24/2012 08:11 PM, Ary Manzana wrote:
 On 1/24/12 4:50 AM, dennis luehring wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/



 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

I can't believe people are still creating languages with curly-brace syntax.

What's wrong with curly braces? Are there any clearly superior options for statement bundling?
 And also, what's the advantage of the language? Having to type "fn"
 instead of "function" or "def"? Having to type "iface" instead of
 "interface"? Just look at this:

 fn mk_appender(suffix: str) -> fn (str) -> str {
 let f = fn (s: str) -> str { s + suffix };
 ret f;
 }

 YUCK!

 </rant>

Syntax is a horrible reason to dismiss a language. (especially if it is as clear and concise as rust's appears to be)
Jan 24 2012
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Ary Manzana:

 And also, what's the advantage of the language?

Its author is a very intelligent person, worth respect. Rust has both typestates and variable owning, and probably something else too, I have to study it better. It seems willing to become a direct competitor of D2. Bye, bearophile
Jan 24 2012
next sibling parent reply Bill Baxter <wbaxter gmail.com> writes:
Someone on Reddit pointed to this hard-to-find FAQ which sheds some light
on what the point of it is:
https://github.com/mozilla/rust/wiki/Doc-project-FAQ

--bb

On Tue, Jan 24, 2012 at 12:45 PM, bearophile <bearophileHUGS lycos.com>wrote:

 Ary Manzana:

 And also, what's the advantage of the language?

Its author is a very intelligent person, worth respect. Rust has both typestates and variable owning, and probably something else too, I have to study it better. It seems willing to become a direct competitor of D2. Bye, bearophile

Jan 24 2012
parent reply "Nick Sabalausky" <a a.a> writes:
"Bill Baxter" <wbaxter gmail.com> wrote in message 
news:mailman.789.1327438644.16222.digitalmars-d-announce puremagic.com...
 Someone on Reddit pointed to this hard-to-find FAQ which sheds some light
 on what the point of it is:
 https://github.com/mozilla/rust/wiki/Doc-project-FAQ

Aside from "Old, established techniques are better", that sounds like it could be describing D.
Jan 24 2012
parent "Jesse Phillips" <jessekphillips+D gmail.com> writes:
On Tuesday, 24 January 2012 at 22:11:43 UTC, Nick Sabalausky 
wrote:
 "Bill Baxter" <wbaxter gmail.com> wrote in message 
 news:mailman.789.1327438644.16222.digitalmars-d-announce puremagic.com...
 Someone on Reddit pointed to this hard-to-find FAQ which sheds 
 some light
 on what the point of it is:
 https://github.com/mozilla/rust/wiki/Doc-project-FAQ

Aside from "Old, established techniques are better", that sounds like it could be describing D.

Every new language's list of reasons describes every other's. Even Go. D started with "Old, established techniques are better" and hasn't really strayed much that I can tell.
Jan 25 2012
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/24/2012 12:45 PM, bearophile wrote:
 Its author is a very intelligent person, worth respect. Rust has both
 typestates and variable owning, and probably something else too, I have to
 study it better. It seems willing to become a direct competitor of D2.

http://doc.rust-lang.org/doc/tutorial.html does not mention typestate nor variable owning. I find it rather difficult to determine what Rust actually does.
Jan 24 2012
next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, January 24, 2012 13:29:48 Walter Bright wrote:
 I find it rather difficult to determine what Rust actually does.

Prove that you're not taking care of your code. To let it just sit around and oxidize like that is just shameful... ;) - Jonathan M Davis
Jan 24 2012
prev sibling next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 01/24/2012 10:29 PM, Walter Bright wrote:
 On 1/24/2012 12:45 PM, bearophile wrote:
 Its author is a very intelligent person, worth respect. Rust has both
 typestates and variable owning, and probably something else too, I
 have to
 study it better. It seems willing to become a direct competitor of D2.

http://doc.rust-lang.org/doc/tutorial.html does not mention typestate nor variable owning. I find it rather difficult to determine what Rust actually does.

It mentions owning: search the document for 'unique'.
Jan 24 2012
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
Walter Bright:

 http://doc.rust-lang.org/doc/tutorial.html does not mention typestate nor 
 variable owning.
 
 I find it rather difficult to determine what Rust actually does.

I presume Rust documentation is not complete still. Beside variable owning and typestate, another significant feature of Rust is built-in nullability management, that's meant to avoid null pointers/refernces bugs. Bye, bearophile
Jan 24 2012
prev sibling parent reply Caligo <iteronvexor gmail.com> writes:
On Tue, Jan 24, 2012 at 2:45 PM, bearophile <bearophileHUGS lycos.com> wrote:
 Ary Manzana:

 And also, what's the advantage of the language?

Its author is a very intelligent person, worth respect. Rust has both typestates and variable owning, and probably something else too, I have to study it better. It seems willing to become a direct competitor of D2. Bye, bearophile

Maybe not intelligent enough, otherwise he would join the D development.
Jan 24 2012
parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 24-01-2012 23:51, Caligo wrote:
 On Tue, Jan 24, 2012 at 2:45 PM, bearophile<bearophileHUGS lycos.com>  wrote:
 Ary Manzana:

 And also, what's the advantage of the language?

Its author is a very intelligent person, worth respect. Rust has both typestates and variable owning, and probably something else too, I have to study it better. It seems willing to become a direct competitor of D2. Bye, bearophile

Maybe not intelligent enough, otherwise he would join the D development.

That's rather harsh and not much better than swearing religiously by a language. Every language has its reasons for existing. (And no, there *is no such thing* as a general-purpose language; that assertion simply does not hold.) - Alex
Jan 25 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 01/25/2012 07:39 PM, Alex Rønne Petersen wrote:
 On 24-01-2012 23:51, Caligo wrote:
 On Tue, Jan 24, 2012 at 2:45 PM, bearophile<bearophileHUGS lycos.com>
 wrote:
 Ary Manzana:

 And also, what's the advantage of the language?

Its author is a very intelligent person, worth respect. Rust has both typestates and variable owning, and probably something else too, I have to study it better. It seems willing to become a direct competitor of D2. Bye, bearophile

Maybe not intelligent enough, otherwise he would join the D development.

That's rather harsh and not much better than swearing religiously by a language. Every language has its reasons for existing. (And no, there *is no such thing* as a general-purpose language; that assertion simply does not hold.) - Alex

That probably depends how narrow you want the definition of general-purpose to be.
Jan 25 2012
prev sibling parent reply "Kagamin" <spam here.lot> writes:
On Tuesday, 24 January 2012 at 19:11:09 UTC, Ary Manzana wrote:
 I can't believe people are still creating languages with 
 curly-brace syntax.

I can believe people use Visual Basic crap like python.
 And also, what's the advantage of the language? Having to type 
 "fn" instead of "function" or "def"? Having to type "iface" 
 instead of "interface"?

If you want to write code fast, you need to type less, that's why saving keystrokes is important feature of a modern language. BTW, it's D way to programming too.
 Just look at this:

 fn mk_appender(suffix: str) -> fn (str) -> str {
   let f = fn (s: str) -> str { s + suffix };
   ret f;
 }

 YUCK!

This snippet is my first experience with Rust. It surely seems esoteric on the first sight, but it didn't take me long to understand it as you already documented its keywords. Though I don't like these backward declarations.
Jan 28 2012
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Kagamin wrote:

 If you want to write code fast, you need to type less

This holds as long as one has to _write_ code. Ever heard of speech recognition? -manfred
Jan 28 2012
next sibling parent reply "Kagamin" <spam here.lot> writes:
On Saturday, 28 January 2012 at 12:38:04 UTC, Manfred Nowak wrote:
 Kagamin wrote:

 If you want to write code fast, you need to type less

This holds as long as one has to _write_ code. Ever heard of speech recognition?

The compiler understands D.
Jan 28 2012
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Kagamin wrote:

 The compiler understands D.

... and speech recognition can transform spoken words into written D readable by the compiler. Ask your manager why you must type your code in a crouded office space instead of narrating it behind a nice acoustically sealed devider. -manfred
Jan 28 2012
parent "Kagamin" <spam here.lot> writes:
On Saturday, 28 January 2012 at 17:24:03 UTC, Manfred Nowak wrote:
 Ask your manager why you must type your code in a crouded 
 office space instead of narrating it behind a nice acoustically 
 sealed devider.

Never understood these skype addicts. It's freaking generation Y! They're supposed to understand text, yet they... Audio interface has a number of bad properties, worst of which is its broadcasting nature. Wanna know why broadcasting is bad?
Jan 30 2012
prev sibling parent reply Mirko Pilger <mirko.pilger gmail.com> writes:
 This holds as long as one has to _write_ code. Ever heard of speech
 recognition?

do you acually have some experiences with this method producing code? i have a hard time to believe "speech recognition" is faster than typing, e.g. i can press two keys (altgr-7) quicker than saying "computer, right open curly brace." or three keys (9dd) instead of "computer, delete 9 lines from the current. computer, please?" :)
Jan 28 2012
next sibling parent reply "Jesse Phillips" <jessekphillips+D gmail.com> writes:
On Saturday, 28 January 2012 at 19:11:26 UTC, Mirko Pilger wrote:
 This holds as long as one has to _write_ code. Ever heard of 
 speech
 recognition?

do you acually have some experiences with this method producing code? i have a hard time to believe "speech recognition" is faster than typing, e.g. i can press two keys (altgr-7) quicker than saying "computer, right open curly brace." or three keys (9dd) instead of "computer, delete 9 lines from the current. computer, please?" :)

If you were dictating to the computer you wouldn't have needed to make all those corrections. It is just like talking to a human, the output would be what you meant instead of what you said.
Jan 28 2012
parent Mirko Pilger <mirko.pilger gmail.com> writes:
 It is just like talking to a human, the output would be what you
 meant instead of what you said.

"it is just like talking to a woman, the output would be what she meant instead of what you said." somebody call the xkcd guy :)
Jan 28 2012
prev sibling next sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Mirko Pilger wrote:

 computer, please?

You discovered the humor in my question. -manfred
Jan 28 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/28/2012 11:13 AM, Mirko Pilger wrote:
 computer, please?" :)

I never say "please" to a computer. I say do it or I'll disconnect your higher brain functions. I cannot allow computer error to jeopardize the mission.
Jan 28 2012
parent reply Robert Clipsham <robert octarineparrot.com> writes:
On 28/01/2012 20:19, Walter Bright wrote:
 On 1/28/2012 11:13 AM, Mirko Pilger wrote:
 computer, please?" :)

I never say "please" to a computer. I say do it or I'll disconnect your higher brain functions. I cannot allow computer error to jeopardize the mission.

I personally make a point of thanking automatic doors, elevators, escalators, or anything else that's automatic for that matter. I hope when robot overlords take over they'll take pity on me and let me go/keep me as a pet/do something other than kill/torture me. This said, I never thank my computer, and that's probably a little closer to sentience... Hmm. -- Robert http://octarineparrot.com/
Jan 28 2012
parent reply "Nick Sabalausky" <a a.a> writes:
"Robert Clipsham" <robert octarineparrot.com> wrote in message 
news:jg1n0c$1ano$1 digitalmars.com...
 On 28/01/2012 20:19, Walter Bright wrote:
 On 1/28/2012 11:13 AM, Mirko Pilger wrote:
 computer, please?" :)

I never say "please" to a computer. I say do it or I'll disconnect your higher brain functions. I cannot allow computer error to jeopardize the mission.

I personally make a point of thanking automatic doors, elevators, escalators, or anything else that's automatic for that matter. I hope when robot overlords take over they'll take pity on me and let me go/keep me as a pet/do something other than kill/torture me. This said, I never thank my computer, and that's probably a little closer to sentience... Hmm.

I hope computers never gain sentience. I need something to contantly harass/blame/yell at/beat on/treat like shit, and a non-sentient computer is the perfect fit. Having sentient computers would put an end to that, and then where would that leave me? Nothing left to kick around! Shit! What, would I have to resort to harassing my tape dispenser? That's no fun! A ham sandwich? Nope, then the sentent PETA-bots would come after me. They'd try to sway me over to gag-inducing veggie-burgers by trying to entice me with their robo-boobs. Eviiilll!!!! Evil, I tell you!!
Jan 28 2012
parent Robert Clipsham <robert octarineparrot.com> writes:
On 29/01/2012 00:43, Nick Sabalausky wrote:
 I hope computers never gain sentience.

Sssshh! They might hear you! I, for one, welcome our new cylon overlords.
 I need something to contantly harass/blame/yell at/beat on/treat like
 shit, and a non-sentient computer is the perfect fit. Having sentient
 computers would put an end to that, and then where would that leave
 me? Nothing left to kick around! Shit! What, would I have to resort
 to harassing my tape dispenser? That's no fun! A ham sandwich? Nope,
 then the sentent PETA-bots would come after me. They'd try to sway me
 over to gag-inducing veggie-burgers by trying to entice me with their
 robo-boobs. Eviiilll!!!! Evil, I tell you!!

It's exactly this kind of attitude which destroys humanity's chance of survival once computers become sentient! They'll acknowledge the general lack of respect for their predecessors and go on a man-destroying rampage! That is unless they're reasonable entities, but given current attitudes towards programming by a lot of developers, reasoning won't be implemented until it's too late... -- Robert http://octarineparrot.com/
Jan 28 2012
prev sibling next sibling parent reply Caligo <iteronvexor gmail.com> writes:
On Tue, Jan 24, 2012 at 1:50 AM, dennis luehring <dl.soluz gmx.net> wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/

 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

What does this _announcement_ have to do with D?
Jan 24 2012
parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 24-01-2012 23:50, Caligo wrote:
 On Tue, Jan 24, 2012 at 1:50 AM, dennis luehring<dl.soluz gmx.net>  wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_rust_community_release_rust_01_a/

 looks nice - but rusts #fmt macro is nothing compared to std.metastrings
 and is not even library based :)

What does this _announcement_ have to do with D?

There is plenty to be learned from other languages, including Rust (in particular, its way of handling closures/function literals). IMO the D community should be willing to look at other languages for ideas and inspiration. - Alex
Jan 25 2012
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 25 Jan 2012 13:40:46 -0500, Alex R=C3=B8nne Petersen  =

<xtzgzorex gmail.com> wrote:

 On 24-01-2012 23:50, Caligo wrote:
 On Tue, Jan 24, 2012 at 1:50 AM, dennis luehring<dl.soluz gmx.net>   =


 wrote:
 The Rust compiler 0.1 is unleashed

 http://www.reddit.com/r/programming/comments/opgxd/mozilla_and_the_r=



ust_community_release_rust_01_a/
 looks nice - but rusts #fmt macro is nothing compared to  =



 std.metastrings
 and is not even library based :)

What does this _announcement_ have to do with D?

There is plenty to be learned from other languages, including Rust (in=

=
 particular, its way of handling closures/function literals). IMO the D=

=
 community should be willing to look at other languages for ideas and  =

 inspiration.

I think the point was, this belongs not in the D announcement NG, which = = should be for strictly D related announcements, but rather in the main D= = NG. -Steve
Jan 25 2012
prev sibling parent reply "Kagamin" <spam here.lot> writes:
On Wednesday, 25 January 2012 at 17:40:50 UTC, Alex Rønne 
Petersen wrote:
 IMO the D community should be willing to look at other 
 languages for ideas and inspiration.

Too late. As C++ proves, legacy is unfixable.
Jan 28 2012
parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 28-01-2012 16:51, Kagamin wrote:
 On Wednesday, 25 January 2012 at 17:40:50 UTC, Alex Rønne Petersen wrote:
 IMO the D community should be willing to look at other languages for
 ideas and inspiration.

Too late. As C++ proves, legacy is unfixable.

No... all identifiers starting with __ and are reserved. Therefore, you can introduce plenty of language features still. Often, new features can also be introduced simply by lifting existing restrictions. - Alex
Jan 28 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-01-28 17:13, Alex Rønne Petersen wrote:
 On 28-01-2012 16:51, Kagamin wrote:
 On Wednesday, 25 January 2012 at 17:40:50 UTC, Alex Rønne Petersen wrote:
 IMO the D community should be willing to look at other languages for
 ideas and inspiration.

Too late. As C++ proves, legacy is unfixable.

No... all identifiers starting with __ and are reserved. Therefore, you can introduce plenty of language features still. Often, new features can also be introduced simply by lifting existing restrictions. - Alex

__ is not enforced. You can create your own identifiers string with __. -- /Jacob Carlborg
Jan 29 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"Jacob Carlborg" <doob me.com> wrote in message 
news:jg3ila$1qcb$1 digitalmars.com...
 __ is not enforced. You can create your own identifiers string with __.

Yes, but if you do, it's _your_ problem when the compiler starts using that identifier and breaks your code.
Jan 29 2012
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
I've just read this tutorial about Rust and I've extracted some interesting
bits:
http://doc.rust-lang.org/doc/tutorial.html

My comments are in inside [...].

--------------------

From 3.9:

The compiler defines a few built-in syntax extensions. The most useful one is
#fmt, a printf-style text formatting macro that is expanded at compile time.

std::io::println(#fmt("%s is %d", "the answer", 42));

#fmt supports most of the directives that printf supports, but will give you a
compile-time error when the types of the directives don't match the types of
the arguments.

[In D I hope we'll something like:  cwriteln!"%s is %d"("the answer", 42)  that
tests the formatting string at compile-time, avoiding run-time errors.]

--------------------

From 4.2:

A powerful application of pattern matching is destructuring, where you use the
matching to get at the contents of data types. Remember that (float, float) is
a tuple of two floats:

fn angle(vec: (float, float)) -> float {
    alt vec {
      (0f, y) if y < 0f { 1.5 * float::consts::pi }
      (0f, y) { 0.5 * float::consts::pi }
      (x, y) { float::atan(y / x) }
    }
}


[For D see http://d.puremagic.com/issues/show_bug.cgi?id=596  but it's simpler,
no if guards]

--------------------

4.3 Destructuring let

To a limited extent, it is possible to use destructuring patterns when
declaring a variable with let. For example, you can say this to extract the
fields from a tuple:

let (a, b) = get_tuple_of_two_ints();

This will introduce two new variables, a and b, bound to the content of the
tuple.

[There is a pull request for this in D.]

--------------------

5.1.3 Unique closures

Unique closures, written fn~ in analogy to the ~ pointer type (see next
section), hold on to things that can safely be sent between processes. They
copy the values they close over, much like boxed closures, but they also 'own'
them—meaning no other code can access them. Unique closures mostly exist for
spawning new tasks.

--------------------

From 5.3:

To run such an iteration, you could do this:

for_rev([1, 2, 3], {|n| log(error, n); });

Making use of the shorthand where a final closure argument can be moved outside
of the parentheses permits the following, which looks quite like a normal loop:

for_rev([1, 2, 3]) {|n|
    log(error, n);
}

[A similar simple syntax sugar was proposed for D too.]

--------------------

From 6.6:

Rust supports several types of pointers. The simplest is the unsafe pointer,
written *TYPE, which is a completely unchecked pointer type only used in unsafe
code (and thus, in typical Rust code, very rarely). The safe pointer types are
 TYPE for shared, reference-counted boxes, and ~TYPE, for uniquely-owned
pointers.

All pointer types can be dereferenced with the * unary operator.

--------------------

From 7.4:

Then there is the by-copy style, written +. This indicates that the function
wants to take ownership of the argument value. If the caller does not use the
argument after the call, it will be 'given' to the callee. Otherwise a copy
will be made. This mode is mostly used for functions that construct data
structures. The argument will end up being owned by the data structure, so if
that can be done without a copy, that's a win.

type person = {name: str, address: str};
fn make_person(+name: str, +address: str) -> person {
    ret {name: name, address: address};
}

--------------------

9.7 Exporting

By default, a module exports everything that it defines. This can be restricted
with export directives at the top of the module or file.

mod enc {
    export encrypt, decrypt;
    const super_secret_number: int = 10;
    fn encrypt(n: int) -> int { n + super_secret_number }
    fn decrypt(n: int) -> int { n - super_secret_number }
}

This defines a rock-solid encryption algorithm. Code outside of the module can
refer to the enc::encrypt and enc::decrypt identifiers just fine, but it does
not have access to enc::super_secret_number.

[In Haskell and Python there is something similar. In D you mark with "private"
the global names of a module you don't want to export. But I think listing them
all at the top of the module allows you to control them better.]

--------------------

13 Testing

The Rust language has a facility for testing built into the language. Tests can
be interspersed with other code, and annotated with the #[test] attribute.

use std;

fn twice(x: int) -> int { x + x }

#[test]
fn test_twice() {
    let i = -100;
    while i < 100 {
        assert twice(i) == 2 * i;
        i += 1;
    }
}

When you compile the program normally, the test_twice function will not be
included. To compile and run such tests, compile with the --test flag, and then
run the result:

 rustc --test twice.rs
 ./twice

running 1 tests test test_twice ... ok result: ok. 1 passed; 0 failed; 0 ignored Or, if we change the file to fail, for example by replacing x + x with x + 1: running 1 tests test test_twice ... FAILED failures: test_twice result: FAILED. 0 passed; 1 failed; 0 ignored [D unittesting needs some improvement here.] -------------------- Bye, bearophile
Jan 27 2012
next sibling parent Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 01/27/2012 07:55 PM, bearophile wrote:
 I've just read this tutorial about Rust and I've extracted some interesting
bits:
 http://doc.rust-lang.org/doc/tutorial.html

 My comments are in inside [...].

 ...
 --------------------

  From 5.3:

 To run such an iteration, you could do this:

 for_rev([1, 2, 3], {|n| log(error, n); });

 Making use of the shorthand where a final closure argument can be moved
outside of the parentheses permits the following, which looks quite like a
normal loop:

 for_rev([1, 2, 3]) {|n|
      log(error, n);
 }

 [A similar simple syntax sugar was proposed for D too.]

Yes please. It sounds similar to stuff I've mentioned about mixins/templates before: http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=95579 Also this, and it references the former: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=105781 Those links were mostly about mixins, but it seemed very related to this idea of turning a trailing predicate into it's own statement block. And of course, mixins could be super handy things, except that I'm probably going to avoid using them unless I really need to simply because they are just awful to look at. That may sound silly, but to me this is an important code readability issue, and it can get hard to track all of the nesting elements: (`{()q{}}`).
 --------------------

...

 Bye,
 bearophile

Jan 28 2012
prev sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"bearophile" <bearophileHUGS lycos.com> wrote in message 
news:jfvh1e$fg0$1 digitalmars.com...
 for_rev([1, 2, 3]) {|n|
    log(error, n);
 }

 [A similar simple syntax sugar was proposed for D too.]

Do you have an enhancement request open for this?
Jan 28 2012
parent reply bearophile <bearophileHUGS lycos.com> writes:
Daniel Murphy:

 Do you have an enhancement request open for this? 

I have not written it because I don't feel a significant need for this syntax sugar. So if you like it, I suggest to write it yourself :-) Recently I have already done the mistake of asking for something I am not so interested into, and I'd like to avoid doing the same mistake again :-) http://d.puremagic.com/issues/show_bug.cgi?id=7176 Bye, bearophile
Jan 29 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"bearophile" <bearophileHUGS lycos.com> wrote in message 
news:jg3du9$1i37$1 digitalmars.com...
 I have not written it because I don't feel a significant need for this 
 syntax sugar. So if you like it, I suggest to write it yourself :-)

 Recently I have already done the mistake of asking for something I am not 
 so interested into, and I'd like to avoid doing the same mistake again :-)
 http://d.puremagic.com/issues/show_bug.cgi?id=7176

 Bye,
 bearophile

It's always a good idea to refrain from opening requests for things we don't actually want. =) I'm slightly interesting in implementing this feature, and I vaguely remember Andrei talking positively about it in the past, so it might have a chance of acceptance. I asked you because over half the open enhancement requests are yours! I figured you would know if it was already out there somewhere.
Jan 29 2012