www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - why D matters for Bioinformatics

reply "george" <georgkam gmail.com> writes:
An interesting post and case for using D in bioinformatics by
Pjotr Prins
http://blog.thebird.nl/?p=93
May 22 2012
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
On Tuesday, 22 May 2012 at 16:01:25 UTC, george wrote:
 An interesting post and case for using D in bioinformatics by
 Pjotr Prins
 http://blog.thebird.nl/?p=93

This article is a strong advertisement for D. I agree D will be good for bioinformatics. Bye, bearophile
May 22 2012
next sibling parent reply deadalnix <deadalnix gmail.com> writes:
Le 22/05/2012 19:40, bearophile a écrit :
 On Tuesday, 22 May 2012 at 16:01:25 UTC, george wrote:
 An interesting post and case for using D in bioinformatics by
 Pjotr Prins
 http://blog.thebird.nl/?p=93

This article is a strong advertisement for D. I agree D will be good for bioinformatics. Bye, bearophile

I spreaded the word. This article is great and I 100% agree with it :D
May 22 2012
parent reply travert phare.normalesup.org (Christophe Travert) writes:
"bearophile" , dans le message (digitalmars.D:168160), a écrit :
 deadalnix:
 http://blog.thebird.nl/?p=93


with it :D

The article says:
There are a few things I miss in D. For example pattern 
recognition on unpacking data, which is great in Haskell, 
Erlang, and Scala (see example 
[http://www.scala-lang.org/node/120 ]).<

The author of that article has missed that D lacks something much simpler than pattern matching, and even more commonly useful. Currently in D you have to write something like: int[2][] directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]; foreach (sx_sy; directions) { immutable sx = sx_sy[0]; immutable sy = sx_sy[1]; // code that uses sx and sy While a less clunky language allows you to unpack them better, something like: auto directions = [tuple(-1, 0), tuple(1, 0), tuple(0, -1), tuple(0, 1)]; foreach (immutable (sx, sy); directions) { // code that uses sx and sy If you use tuples, you want to unpack them often, it's a basic operation on tuples.

This little example raises a question if tuples becomes part of the langage. Should static array have tuple capabilities ? Besides that, it is easy to emulate your example with a little library solution. Maybe something like that should be added to std.range. -- Christophe
May 23 2012
next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 23.05.2012 14:10, bearophile wrote:

 Why not? Fixed-sized arrays are similar to tuples with uniform types.
 Unpacking short arrays in the same way you unpack tuples *very handy*
 and it's commonly done in both Python and Haskell (and probably in other
 languages too):

I'd rather see common structure/static array expansion. Then returning struct will be as powerful as multiple value return. The latter can be added sometime later, since tuple is just a plain struct. I expect some form of pattern matching a-la Ecma Script 6 (yeah, I know but idea itself is good). My proposal the is following using a.{ ... } syntax to unpack: Record r = ...; auto a, b, c = r.{ first, third, some_other_field };//a=r.first, b=r.third, c = r.some_other_field With tuples: auto a, b, c = r.{};//a = r[0], b = r[1], c = r[2] auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4] With arrays, exactly the same as tuples: auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4] Tuples with named fields can work in both named and indexed "modes". Indexes must be a valid CT-constant. More over we then have nested unpacking syntax: auto x, i = r.{ something, nested_thing.{ precious_secret} }; //x = r.something, i = r.nested_thing.precious_secret The same with just about any expression: auto point = (a+b()).{ x, y }; //even better - point is now Tuple!(<type of x>, "x", <type of y>, "y") Summarizing it all. For single left-side variable the rewrite of expression is: auto __tmp = <expr>, tuple(__tmp.<spec_1>, __tmp.<spec_2>); For multiple left-side the rewrite of the whole statement is: auto __tmp = <expr>, __1st = __tmp.<spec_1>, __2nd = __tmp.<spec_2> ...; Where spec_x is constructed from: root_0.{ ... root_1.{ .. root_n.{ var_x ... } ... } ... } as root_0.<...>.root_n.var_x If some var_k/root_k happens to be CT index the rewrite is ...[root_k]... or ...[var_k].. So far I think it's the closest thing to multiple value return with natural syntax. It also brings concise syntax for a common general propose task. -- Dmitry Olshansky
May 23 2012
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
 My proposal the is following using a.{ ... } syntax to unpack:

In short: I think the original proposal of https://github.com/D-Programming-Language/dmd/pull/341 could be enhanced with introduction <expr>.{ <spec> } selectors allowing to cherry pick fields and array elements easily. If we go with Kenji's proposal, this can be treated as cool way to construct tuple by applying selector to an expression.
 Record r = ...;
 auto a, b, c = r.{ first, third, some_other_field };//a=r.first,
 b=r.third, c = r.some_other_field

 With tuples:
 auto a, b, c = r.{};//a = r[0], b = r[1], c = r[2]
 auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]

 With arrays, exactly the same as tuples:
 auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]

 Tuples with named fields can work in both named and indexed "modes".
 Indexes must be a valid CT-constant.

 More over we then have nested unpacking syntax:

 auto x, i = r.{ something, nested_thing.{ precious_secret} };
 //x = r.something, i = r.nested_thing.precious_secret

 The same with just about any expression:

 auto point = (a+b()).{ x, y };
 //even better - point is now Tuple!(<type of x>, "x", <type of y>, "y")


 Summarizing it all.

 For single left-side variable the rewrite of expression is:
 auto __tmp = <expr>, tuple(__tmp.<spec_1>, __tmp.<spec_2>);

 For multiple left-side the rewrite of the whole statement is:
 auto __tmp = <expr>, __1st = __tmp.<spec_1>, __2nd = __tmp.<spec_2> ...;


 Where spec_x is constructed from:

 root_0.{ ... root_1.{ .. root_n.{ var_x ... } ... } ... }

 as
 root_0.<...>.root_n.var_x

 If some var_k/root_k happens to be CT index the rewrite is
 ...[root_k]... or ...[var_k]..


 So far I think it's the closest thing to multiple value return with
 natural syntax. It also brings concise syntax for a common general
 propose task.

-- Dmitry Olshansky
May 23 2012
prev sibling parent travert phare.normalesup.org (Christophe Travert) writes:
"bearophile" , dans le message (digitalmars.D:168206), a écrit :
 Besides that, it is easy to emulate your example with a little
 library solution. Maybe something like that should be added to
 std.range.

What syntax do you suggest?

foreach (immutable sx, sy; unpack(s)) {...} doing something like (but more optimised than): foreach (immutable sx, sy; lockstep(s.map!"a[0]", s.map!"a[1]")) {...} You have to be careful with types, I don't think the result of map here can be cast to immutable (but I didn't check).
May 23 2012
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 5/22/12 12:40 PM, bearophile wrote:
 On Tuesday, 22 May 2012 at 16:01:25 UTC, george wrote:
 An interesting post and case for using D in bioinformatics by
 Pjotr Prins
 http://blog.thebird.nl/?p=93

This article is a strong advertisement for D. I agree D will be good for bioinformatics.

On reddit: http://www.reddit.com/r/programming/comments/tzpdh/d_is_a_dragon_or_why_d_matters_for_bioinformatics/ Andrei
May 22 2012
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
deadalnix:
 http://blog.thebird.nl/?p=93


with it :D

The article says:
There are a few things I miss in D. For example pattern 
recognition on unpacking data, which is great in Haskell, 
Erlang, and Scala (see example 
[http://www.scala-lang.org/node/120 ]).<

The author of that article has missed that D lacks something much simpler than pattern matching, and even more commonly useful. Currently in D you have to write something like: int[2][] directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]; foreach (sx_sy; directions) { immutable sx = sx_sy[0]; immutable sy = sx_sy[1]; // code that uses sx and sy While a less clunky language allows you to unpack them better, something like: auto directions = [tuple(-1, 0), tuple(1, 0), tuple(0, -1), tuple(0, 1)]; foreach (immutable (sx, sy); directions) { // code that uses sx and sy If you use tuples, you want to unpack them often, it's a basic operation on tuples. Bye, bearophile
May 22 2012
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Christophe Travert:

 This little example raises a question if tuples becomes part of 
 the langage. Should static array have tuple capabilities ?

Why not? Fixed-sized arrays are similar to tuples with uniform types. Unpacking short arrays in the same way you unpack tuples *very handy* and it's commonly done in both Python and Haskell (and probably in other languages too): In Python:
 t = (10, 20)
 a, b = t
 a



 b



 l = [3, 5]
 x, y = l
 x



 y



In Haskell: Prelude> let t = (10, 20) Prelude> let (a, b) = t Prelude> a 10 Prelude> b 20 Prelude> let l = [3, 5] Prelude> let [x, y] = l Prelude> x 3 Prelude> y 5
 Besides that, it is easy to emulate your example with a little
 library solution. Maybe something like that should be added to
 std.range.

What syntax do you suggest? (Generally tuple unpacking/small array unpacking is a so commonly done operation that it needs a clean and very nice syntax, so you often want it as built-in feature). Bye, bearophile
May 23 2012
prev sibling next sibling parent Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--f46d0401730bcd5eb304c0b2aab0
Content-Type: text/plain; charset=UTF-8

On Wed, May 23, 2012 at 3:00 PM, Dmitry Olshansky <dmitry.olsh gmail.com>wrote:

 My proposal the is following using a.{ ... } syntax to unpack:

In short: I think the original proposal of https://github.com/D-**Programming-Language/dmd/pull/**341<https://github.com/D-Programming-Language/dmd/pull/341> could be enhanced with introduction <expr>.{ <spec> } selectors allowing to cherry pick fields and array elements easily. If we go with Kenji's proposal, this can be treated as cool way to construct tuple by applying selector to an expression.
 Record r = ...;
 auto a, b, c = r.{ first, third, some_other_field };//a=r.first,
 b=r.third, c = r.some_other_field

 With tuples:
 auto a, b, c = r.{};//a = r[0], b = r[1], c = r[2]
 auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]

 With arrays, exactly the same as tuples:
 auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]

 Tuples with named fields can work in both named and indexed "modes".
 Indexes must be a valid CT-constant.

 More over we then have nested unpacking syntax:

 auto x, i = r.{ something, nested_thing.{ precious_secret} };
 //x = r.something, i = r.nested_thing.precious_secret

 The same with just about any expression:

 auto point = (a+b()).{ x, y };
 //even better - point is now Tuple!(<type of x>, "x", <type of y>, "y")


 Summarizing it all.

 For single left-side variable the rewrite of expression is:
 auto __tmp = <expr>, tuple(__tmp.<spec_1>, __tmp.<spec_2>);

 For multiple left-side the rewrite of the whole statement is:
 auto __tmp = <expr>, __1st = __tmp.<spec_1>, __2nd = __tmp.<spec_2> ...;


 Where spec_x is constructed from:

 root_0.{ ... root_1.{ .. root_n.{ var_x ... } ... } ... }

 as
 root_0.<...>.root_n.var_x

 If some var_k/root_k happens to be CT index the rewrite is
 ...[root_k]... or ...[var_k]..


 So far I think it's the closest thing to multiple value return with
 natural syntax. It also brings concise syntax for a common general
 propose task.

-- Dmitry Olshansky

This is awesome! I really like it! -- Bye, Gor Gyolchanyan. --f46d0401730bcd5eb304c0b2aab0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Wed, May 23, 2012 at 3:00 PM, Dmitry Olshansk= y <span dir=3D"ltr">&lt;<a href=3D"mailto:dmitry.olsh gmail.com" target=3D"= _blank">dmitry.olsh gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D= "gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding= -left:1ex"> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> My proposal the is following using a.{ ... } syntax to unpack:<br> </blockquote> <br> In short:<br> I think the original proposal of<br> =C2=A0<a href=3D"https://github.com/D-Programming-Language/dmd/pull/341" ta= rget=3D"_blank">https://github.com/D-<u></u>Programming-Language/dmd/pull/<= u></u>341</a><br> could be enhanced with introduction =C2=A0&lt;expr&gt;.{ &lt;spec&gt; } sel= ectors allowing to cherry pick fields and array elements easily.<br> <br> If we go with Kenji&#39;s proposal, this can be treated as cool way to cons= truct tuple by applying selector to an expression.<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> <br> Record r =3D ...;<br> auto a, b, c =3D r.{ first, third, some_other_field };//a=3Dr.first,<br> b=3Dr.third, c =3D r.some_other_field<br> <br> With tuples:<br> auto a, b, c =3D r.{};//a =3D r[0], b =3D r[1], c =3D r[2]<br> auto a, b, c =3D r.{0, 2, 4}; // a =3D r[0], b =3D r[2], c =3D r[4]<br> <br> With arrays, exactly the same as tuples:<br> auto a, b, c =3D r.{0, 2, 4}; // a =3D r[0], b =3D r[2], c =3D r[4]<br> <br> Tuples with named fields can work in both named and indexed &quot;modes&quo= t;.<br> Indexes must be a valid CT-constant.<br> <br> More over we then have nested unpacking syntax:<br> <br> auto x, i =3D r.{ something, nested_thing.{ precious_secret} };<br> //x =3D r.something, i =3D r.nested_thing.precious_secret<br> <br> The same with just about any expression:<br> <br> auto point =3D (a+b()).{ x, y };<br> //even better - point is now Tuple!(&lt;type of x&gt;, &quot;x&quot;, &lt;t= ype of y&gt;, &quot;y&quot;)<br> <br> <br> Summarizing it all.<br> <br> For single left-side variable the rewrite of expression is:<br> auto __tmp =3D &lt;expr&gt;, tuple(__tmp.&lt;spec_1&gt;, __tmp.&lt;spec_2&g= t;);<br> <br> For multiple left-side the rewrite of the whole statement is:<br> auto __tmp =3D &lt;expr&gt;, __1st =3D __tmp.&lt;spec_1&gt;, __2nd =3D __tm= p.&lt;spec_2&gt; ...;<br> <br> <br> Where spec_x is constructed from:<br> <br> root_0.{ ... root_1.{ .. root_n.{ var_x ... } ... } ... }<br> <br> as<br> root_0.&lt;...&gt;.root_n.var_x<br> <br> If some var_k/root_k happens to be CT index the rewrite is<br> ...[root_k]... or ...[var_k]..<br> <br> <br> So far I think it&#39;s the closest thing to multiple value return with<br> natural syntax. It also brings concise syntax for a common general<br> propose task.<br> <br><span class=3D"HOEnZb"><font color=3D"#888888"> </font></span></blockquote><span class=3D"HOEnZb"><font color=3D"#888888"> <br> <br> <br> <br> -- <br> Dmitry Olshansky<br> </font></span></blockquote></div><br>This is awesome! I really like it!<br = clear=3D"all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br> --f46d0401730bcd5eb304c0b2aab0--
May 23 2012
prev sibling parent bioinfornatics <bioinfornatics fedoraproject.org> writes:
Le mardi 22 mai 2012 =C3=A0 18:01 +0200, george a =C3=A9crit :
 An interesting post and case for using D in bioinformatics by
 Pjotr Prins
 http://blog.thebird.nl/?p=3D93

I have created dsciene for develop a bioinformatics library https://github.com/dscience-developers/dscience everyone are welcome to contribute
May 24 2012