Re: passing a string with the character as an argument

2012-02-29 Thread Andrej Mitrovic
On 2/29/12, James Miller ja...@aatch.net wrote:
 Today I Learned that windows has insane escaping.

You won't have to worry about it for long:
https://github.com/D-Programming-Language/phobos/pull/457


Re: Random behavior using a wrapped C library

2012-02-29 Thread simendsjo

On Wed, 29 Feb 2012 07:44:23 +0100, James Miller ja...@aatch.net wrote:


On 29 February 2012 19:30, simendsjo simend...@gmail.com wrote:
On Wed, 29 Feb 2012 05:03:30 +0100, Mike Parker aldac...@gmail.com  
wrote:



On 2/29/2012 1:10 AM, simendsjo wrote:


On Tue, 28 Feb 2012 16:58:13 +0100, Trass3r u...@known.com wrote:


http://d.puremagic.com/issues/show_bug.cgi?id=5570



Thanks. I've literally spent hours testing various things without any
luck - would have been simpler if I knew asm :/

A blocker for using x64 on linux then.



Have you tested on 32-bit yet? I had the exact same problem with one  
of my
wrappers when passing a struct by value, but on 32-bit Windows.  
Luckily, in
my case it was simple enough to implement the function in D to work  
around

it. I'm curious to know if it's related.



Yes. Tested on x32, and it works just fine. I'll use ia32libs and -m32  
for

the time being then.

A strange thing is that memory consumption went _up_ when everything was
compiled as x32.


I don't know much, but wouldn't bigger register sizes mean that less
data needs shuffled in and out of memory? Resulting in less
instructions and therefore less memory usage?

I'm just guessing though

--
James Miller


Probably. Almost everything is done using structs right now. Guess it will  
be quite different when I get a lot of classes bouncing around.


Re: Pretty fields string

2012-02-29 Thread Andrej Mitrovic
Just noticed there's an std.traits import missing. I hate how D
silently ignores that FunctionTypeOf is left undefined.


How can I use structs in a named enum?

2012-02-29 Thread simendsjo

.. That is  enum E : Struct {}

struct S {
int a;
}

// ok
enum E : S {
a = S(1),
}

// Error: need member function opCmp() for struct S to compare
/*
enum E2 : S {
a = S(1),
b = S(2)
}
*/

struct S2 {
int a;
int opCmp(ref const S2 other)
{
return a == other.a ? 0 : (a  other.a ? -1 : 1);
}
}

// Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable  
using argument types (E3)

// Error: cast(const(S2))S2(1) is not an lvalue
// Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable  
using argument types (E3)

// Error: cast(const(S2))S2(1) is not an lvalue
enum E3 : S2 {
a = S2(1),
b = S2(2)
}

void main() {
}


So E3 is passed as the parameter to S2.opCmp..?


Re: How can I use structs in a named enum?

2012-02-29 Thread simendsjo

On Wed, 29 Feb 2012 12:27:32 +0100, simendsjo simend...@gmail.com wrote:

On Wed, 29 Feb 2012 12:15:35 +0100, simendsjo simend...@gmail.com  
wrote:



.. That is  enum E : Struct {}

struct S {
 int a;
}

// ok
enum E : S {
 a = S(1),
}

// Error: need member function opCmp() for struct S to compare
/*
enum E2 : S {
 a = S(1),
 b = S(2)
}
*/

struct S2 {
 int a;
 int opCmp(ref const S2 other)
 {
 return a == other.a ? 0 : (a  other.a ? -1 : 1);
 }
}

// Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable  
using argument types (E3)

// Error: cast(const(S2))S2(1) is not an lvalue
// Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable  
using argument types (E3)

// Error: cast(const(S2))S2(1) is not an lvalue
enum E3 : S2 {
 a = S2(1),
 b = S2(2)
}

void main() {
}


So E3 is passed as the parameter to S2.opCmp..?


Hmm.. By removing ref const in opCmp, it works as expected


Btw.. Removing the ref is obvious, but why do I have to remove const?
Perhaps also the documentation for opCmp should be improved..?


about std.csv and derived format

2012-02-29 Thread bioinfornatics
Dear,

I would like to parse this file:
http://genome.ucsc.edu/goldenPath/help/ItemRGBDemo.txt

struct Bed{
stringchrom;// 0
size_tchromStart;   // 1
size_tchromEnd; // 2
stringname; // 3
size_tscore;// 4
char  strand;   // 5
size_tthickStart;   // 6
size_tthickEnd; // 7
size_t[3] itemRgb;  // 8
size_tblockCount;   // 9
size_tblockSizes;   // 10
size_tblockStarts;  // 11
}

In more fields 3 to 11 are optional. Then you can have:
* field 0 - 3
* field 0 - 4
* field 0 - 5
... to 0 - 12



Re: about std.csv and derived format

2012-02-29 Thread bioinfornatics
Le mercredi 29 février 2012 à 12:42 +0100, bioinfornatics a écrit :
 Dear,
 
 I would like to parse this file:
 http://genome.ucsc.edu/goldenPath/help/ItemRGBDemo.txt
 
 struct Bed{
   stringchrom;// 0
   size_tchromStart;   // 1
   size_tchromEnd; // 2
   stringname; // 3
   size_tscore;// 4
   char  strand;   // 5
   size_tthickStart;   // 6
   size_tthickEnd; // 7
   size_t[3] itemRgb;  // 8
 size_tblockCount; // 9
 size_tblockSizes; // 10
 size_tblockStarts;// 11
 }
 
 In more fields 3 to 11 are optional. Then you can have:
 * field 0 - 3
 * field 0 - 4
 * field 0 - 5
 ... to 0 - 12
 


line 0 - 2 into ItemRGBDemo.txt are metadata so they should be parsed
by hand.

browser position chr7:127471196-127495720
browser hide all
track name=ItemRGBDemo description=Item RGB demonstration
visibility=2 itemRgb=On

My problem is:
- need to parse data in csv format
- how manage with optional field



Re: about std.csv and derived format

2012-02-29 Thread Jesse Phillips
On Wednesday, 29 February 2012 at 11:51:29 UTC, bioinfornatics 
wrote:
Le mercredi 29 février 2012 à 12:42 +0100, bioinfornatics a 
écrit :

Dear,

I would like to parse this file:
http://genome.ucsc.edu/goldenPath/help/ItemRGBDemo.txt



My problem is:
- need to parse data in csv format
- how manage with optional field


It looks like the data is tab delimited so separator is a tab. 
There are no optional fields in CSV, but you can disable 
exceptions.


auto records = csvReader!(Bed,Malformed.ignore)(str,'\t');


Re: How can I use structs in a named enum?

2012-02-29 Thread bearophile
simendsjo:

 Perhaps also the documentation for opCmp should be improved..?

Also, and maybe here DMD has to give better error messages :-)

Bye,
bearophile


Re: How can I use structs in a named enum?

2012-02-29 Thread simendsjo
On Wed, 29 Feb 2012 13:40:51 +0100, bearophile bearophileh...@lycos.com  
wrote:



simendsjo:


Perhaps also the documentation for opCmp should be improved..?


Also, and maybe here DMD has to give better error messages :-)

Bye,
bearophile


Yes. Using argument types E3 doesn't make much sense when the named enum  
is a complex type.


Re: More general Cartesian product

2012-02-29 Thread Philippe Sigaud
 I have a need for a Cartesian product of multiple ranges. I see there's
been a discussion here (Dec 2011) as well as a request posted (#7128). It
seems to me that the request deals with a multidimensional product -- which
is what I need -- while the implementation by Timon Gehr deals only with
the two-dimensional case.

I have one in a dsource project:

http://www.dsource.org/projects/dranges

It's in the algorithm.d module, look for 'combinations'

Docs are there:

http://svn.dranges.org/projects/dranges/trunk/dranges/doc/algorithm.html

For a generalization of this, you may want to have a look into the
rangeofranges.d module (docs: same than algorithm, or click on the
'package' tab on the left).

I think a .zip is given on the main page.
Alternatively, it's also on github:

www.github.com/PhilippeSigaud/dranges


Re: Pretty fields string

2012-02-29 Thread Philippe Sigaud
 I've done this a couple of times before but I always had issues, e.g.
 functions and property calls would be mixed in. But I think I have a
 good go-to function now:

Nice. What does it give for:

- function overloads (PITA that)?
- type aliase (alias int Int;)?
- function aliases or member aliases?
- inner templates (struct template, etc, not pure template as these are not
allowed in a struct)?
- unittests inside the structs?


Re: passing a string with the character as an argument

2012-02-29 Thread jic
James Miller Wrote:

 On 29 February 2012 20:21, Jos van Uden user@domain.invalid wrote:
  On 29-2-2012 7:06, James Miller wrote:
 
  On 29 February 2012 18:51, jiccabr...@wrc.xerox.com  wrote:
 
 
  Greetings!
 
  I have this program,
 
  import std.process : system;
  import std.stdio;
  int main(char[][] args)
  {
   char[] cmd;
 
   for (int i=1;iargs.length;i++)
   {
     cmd ~= args[i] ~  ;
   }
   writefln(cmd);
   return(1);
  }
 
  if I compile it and run it this way,
 
  test 1! 2@ 3  4#
 
  the result is
 
 
 
  If you are on Windows, then I don't know why this is happening.
 
 
  On windows the ampersand also has a special meaning. In that case
  try the carrot ^ to escape
 
  test 1! 2@ 3^  4#
 
  Jos
 
 
 Today I Learned that windows has insane escaping.
 
Me too.  I tried escaping it with the wonder-working \, but that didn't work.  
This does work.  Weird stuff...  Thanks all.


Re: More general Cartesian product

2012-02-29 Thread Magnus Lie Hetland

On 2012-02-29 14:24:36 +, Philippe Sigaud said:


[snip]

Thanks for the response.

In the meantime, I also hacked together a simple version of what I 
needed (see below), but I'll look into the references you provided as 
well :)


void forall(alias func, size_t lvl=0, T...)(T args) {
   static if (lvl == args.length) {
   func(args);
   }
   else {
   foreach (e; args[lvl]) {
   forall!(func, lvl+1)
  (args[0..lvl], e, args[lvl+1..$]);
   }
   }
}

--
Magnus Lie Hetland
http://hetland.org



Re: Pretty fields string

2012-02-29 Thread Jacob Carlborg

On 2012-02-29 10:58, Andrej Mitrovic wrote:

I've done this a couple of times before but I always had issues, e.g.
functions and property calls would be mixed in. But I think I have a
good go-to function now:

import std.algorithm;
import std.conv;
import std.string;
import std.stdio;
import std.range;

struct Foo
{
 int one = 1;
 @property int test() { return 1; }
 int three = 3;
 string[string] aa;
 string toString() { return prettyFieldsString(this); }
}

string prettyFieldsString(T)(T t)
 if (is(T == struct) || is(T == class))
{
 Appender!string result;
 Appender!(string[]) fields;
 Appender!(string[]) values;

 foreach (member; __traits(allMembers, T))
 {
 mixin(
 static if (!is( FunctionTypeOf!(t. ~ member ~ ) ))
 {
 static if (member !=  ~ `toString` ~ )
 {
 fields.put(member);
 values.put(to!string(__traits(getMember, t,  ~ `` ~
member ~ `` ~ )));
 }
 }
 );
 }

 size_t spaceLen = 1;
 foreach (field; fields.data)  // should use reduce!() here..
 spaceLen = max(spaceLen, field.length);

 alias std.array.replicate replicate;
 string spaceString = replicate( , spaceLen);

 foreach (field, value; lockstep(fields.data, values.data))
 result.put(format(%s: %s%s\n, field, replicate( , spaceLen
- field.length), value));

 return result.data;
}

void main()
{
 Foo foo;
 foo.aa[foo] = bar;
 writeln(foo);
}

Sample output: http://paste.pocoo.org/show/558492/

I've had to put everything into one foreach loop since there are still
some CTFE bugs I run into. I also had to add a check against toString,
otherwise I get an infinite loop in the toString() call.

Anyway, feel free to use/improve this function.


Seems like what I have in my serialization library Orange:

https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d

fieldsOf and getValueOfField. These work only on instance variables 
and don't care if the variable is public or not.


--
/Jacob Carlborg


Re: Trouble with -lib in linux undefined reference to `_Dmain'

2012-02-29 Thread Kevin Cox
I think you need the -lib in the linker command (too?).
On Feb 29, 2012 12:25 PM, André an...@s-e-a-p.de wrote:

 Hi,
 I use Mono-D and have a hello world example which compiles fine.
 I set the compiler option -lib and receives an error undefined
 reference to `_Dmain'.

 Following commands are generated for the build process:
 dmd -c main.d 
 -of/home/user/Dokumente/**MonoDevelop/HelloWorld/**HelloWorld/obj/Debug/main.o
 -I/usr/include/d/dmd/phobos -I/usr/include/d/dmd/**druntime/import
 -gc -debug -lib

 dmd -gc -debug -of/home/user/Dokumente/**MonoDevelop/HelloWorld/**
 HelloWorld/bin/Debug/**HelloWorld obj/Debug/main.o

 Do I miss an additional linux option or is the order of the commands wrong?

 Kind regards
 André



Re: Trouble with -lib in linux undefined reference to `_Dmain'

2012-02-29 Thread André

you are right, that was the error.
Thanks.

Kind regards
André

Am 29.02.2012 18:27, schrieb Kevin Cox:

I think you need the -lib in the linker command (too?).

On Feb 29, 2012 12:25 PM, André an...@s-e-a-p.de
mailto:an...@s-e-a-p.de wrote:

Hi,
I use Mono-D and have a hello world example which compiles fine.
I set the compiler option -lib and receives an error undefined
reference to `_Dmain'.

Following commands are generated for the build process:
dmd -c main.d

-of/home/user/Dokumente/__MonoDevelop/HelloWorld/__HelloWorld/obj/Debug/main.o
-I/usr/include/d/dmd/phobos
-I/usr/include/d/dmd/__druntime/import -gc -debug -lib

dmd -gc -debug

-of/home/user/Dokumente/__MonoDevelop/HelloWorld/__HelloWorld/bin/Debug/__HelloWorld
obj/Debug/main.o

Do I miss an additional linux option or is the order of the commands
wrong?

Kind regards
André





Re: How can I use structs in a named enum?

2012-02-29 Thread bearophile
simendsjo:

 Yes. Using argument types E3 doesn't make much sense when the named enum  
 is a complex type.

If this diagnostic bug/enhancement is not in Bugzilla then I suggest you to add 
it. Now there are two persons that are quite efficient at fixing Bugzilla bugs, 
but they need to know there is a problem.

Bye,
bearophile


Re: How can I use structs in a named enum?

2012-02-29 Thread Jonathan M Davis
On Wednesday, February 29, 2012 12:15:35 simendsjo wrote:
 .. That is  enum E : Struct {}
 
 struct S {
 int a;
 }
 
 // ok
 enum E : S {
 a = S(1),
 }
 
 // Error: need member function opCmp() for struct S to compare
 /*
 enum E2 : S {
 a = S(1),
 b = S(2)
 }
 */
 
 struct S2 {
 int a;
 int opCmp(ref const S2 other)
 {
 return a == other.a ? 0 : (a  other.a ? -1 : 1);
 }
 }
 
 // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable
 using argument types (E3)
 // Error: cast(const(S2))S2(1) is not an lvalue
 // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable
 using argument types (E3)
 // Error: cast(const(S2))S2(1) is not an lvalue
 enum E3 : S2 {
 a = S2(1),
 b = S2(2)
 }
 
 void main() {
 }
 
 
 So E3 is passed as the parameter to S2.opCmp..?

http://d.puremagic.com/issues/show_bug.cgi?id=4423

- Jonathan M Davis


Re: Compiling DMD on MAC OS X

2012-02-29 Thread Joshua Niehus
On Monday, 20 February 2012 at 11:18:34 UTC, Tyro[a.c.edwards] 
wrote:

...

and I doubt you want me to put all of what dmd -v spits out 
for this little script.


Thanks,
Andrew


Hi Andrew,

I ran into this problem as well and here is how I fixed/hacked it:
OSX Lion, and soon to be Mountain Lion, no longer come with GCC 
installed for the Command Line (/usr/bin/gcc)
What you need to do is Install Xcode from the app store, which is 
free, and then:

  * Launch your Xcode 4.1
  * Go to preferences  Downloads
  * Click on the install button near the Command line tools

This will put gcc in your /usr/bin directory.

Then try to recompile your code.

-- the new mac installer on the website should probably come with 
gcc or check for dependencies


Josh


Re: How can I use structs in a named enum?

2012-02-29 Thread simendsjo
On Wed, 29 Feb 2012 19:00:10 +0100, bearophile bearophileh...@lycos.com  
wrote:



simendsjo:

Yes. Using argument types E3 doesn't make much sense when the named  
enum

is a complex type.


If this diagnostic bug/enhancement is not in Bugzilla then I suggest you  
to add it. Now there are two persons that are quite efficient at fixing  
Bugzilla bugs, but they need to know there is a problem.


Bye,
bearophile


http://d.puremagic.com/issues/show_bug.cgi?id=7612


Re: Pretty fields string

2012-02-29 Thread Andrej Mitrovic
On 2/29/12, Jacob Carlborg d...@me.com wrote:
 Seems like what I have in my serialization library Orange:

Sweet. I was gonna take a look at Orange for just this purpose. Thanks.


Re: class templates and static if

2012-02-29 Thread Ali Çehreli

On 02/28/2012 02:12 AM, Dmitry Olshansky wrote:
 On 28.02.2012 2:17, Ali Çehreli wrote:

 I have played with this optimization recently. (Could be dmd 2.057.) No,
 dmd did not optimize a straightforward switch statement over a ubyte
 expression with about two hundred ubyte cases.

 Hate to say it but I see it in real-world code, VM performance almost
 doubled.

That's really good to hear. Perhaps my experiments were either naive, or 
a series of cmp xxx je xxx would be faster, say for the ubyte type 
that I've used.


 Mm care to share you experiments?

Here is a program that mixes-in a lookup function that contains a single 
switch statement that covers the entire 256 values of ubyte:


import std.stdio;
import std.conv;

string oneCase(FromT, ToT)(FromT fromExpr, ToT toExpr)
{
return
 case  ~ to!string(fromExpr)
~ : return  ~ to!string(ToT.init) ~ ; ;
}

string manyCases(FromT, ToT)(size_t count)
{
string result;

ToT fromExpr;
foreach (i; 0 .. count) {
result ~= oneCase(fromExpr, 42);
++fromExpr;
}

return result;
}

string lookUpFunc(FromT, ToT)(size_t count)
{
immutable header = ToT.stringof ~  lookUp( ~ FromT.stringof
   ~  expr) { switch (expr) { ;
immutable cases = manyCases!(FromT, ToT)(count);
immutable footer =  default: return  ~ to!string(ToT.init) ~ ; } };

return header ~ cases ~ footer;
}

void main()
{
enum funcWithManyCases = lookUpFunc!(ubyte, ubyte)(256);

writeln(Mixing-in: , funcWithManyCases);
mixin(funcWithManyCases);

assert(lookUp(42) == 0);
}

I compiled with -O and then used obj2asm to see that there are 256 cmp 
xxx jmp xxx instructions.


Ali



Re: Pretty fields string

2012-02-29 Thread Andrej Mitrovic
On 2/29/12, Philippe Sigaud philippe.sig...@gmail.com wrote:
 Nice. What does it give for:

 - function overloads (PITA that)?
 - type aliase (alias int Int;)?
 - function aliases or member aliases?
 - inner templates (struct template, etc, not pure template as these are not
 allowed in a struct)?
 - unittests inside the structs?


Well I was mainly interested in printing fields that take memory in a
struct/class instance, not functions or other things. :)

Just noticed it doesn't work ok if there's a nested template
declaration in a struct. It would say Error: cannot resolve type for
t.temp(T).

Then I've tried using a static if + __traits(compiles) to work around
it (and even is(typeof)), and before you know it..
Assertion failure: 'type' on line 6695 in file 'expression.c'

lol. :p


Re: Pretty fields string

2012-02-29 Thread Andrej Mitrovic
On 2/29/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
 Just noticed it doesn't work ok if there's a nested template
 declaration in a struct. It would say Error: cannot resolve type for
 t.temp(T).

Correction: it was the unittest block that was problematic. I've filed
it http://d.puremagic.com/issues/show_bug.cgi?id=7613


how to use raw sockets

2012-02-29 Thread maarten van damme
hello,
I want to use raw sockets but there is a lack of documentation on how to
use them in D.
Is there somewhere I can read more about them or has someone succesfully
used them?

Thank you,
maarten


GUI or more human readable -profile data?

2012-02-29 Thread simendsjo

http://www.digitalmars.com/ctg/trace.html

Has someone made some GUI/pretty printing/dump to database or other tools  
to make the profile data a bit simpler to digest?


Re: how to use raw sockets

2012-02-29 Thread David

Am 29.02.2012 20:44, schrieb maarten van damme:

hello,
I want to use raw sockets but there is a lack of documentation on how to
use them in D.
Is there somewhere I can read more about them or has someone succesfully
used them?

Thank you,
maarten


Hello,

I would use libpcap for that, since this is C you can interface it from 
D. Bu there are no bindings for it yet, you would have to make them 
first (you can submit them to https://github.com/D-Programming-Deimos ).


Re: how to use raw sockets

2012-02-29 Thread maarten van damme
I've tried porting libcap once but I failed miserably. If I'd succeed in
porting they wouldn't be of good quality.


Re: GUI or more human readable -profile data?

2012-02-29 Thread Robert Clipsham

On 29/02/2012 19:41, simendsjo wrote:

http://www.digitalmars.com/ctg/trace.html

Has someone made some GUI/pretty printing/dump to database or other
tools to make the profile data a bit simpler to digest?


If you're on Windows you could try:

http://h3.gd/code/xfProf/

Although I don't believe it uses the data from -profile. On linux/OS X 
you can use valgrind/kcachegrind, though it doesn't have demangling for 
D symbols (at least, last time I checked).


--
Robert
http://octarineparrot.com/


Re: GUI or more human readable -profile data?

2012-02-29 Thread simendsjo
On Wed, 29 Feb 2012 22:28:29 +0100, Robert Clipsham  
rob...@octarineparrot.com wrote:



On 29/02/2012 19:41, simendsjo wrote:

http://www.digitalmars.com/ctg/trace.html

Has someone made some GUI/pretty printing/dump to database or other
tools to make the profile data a bit simpler to digest?


If you're on Windows you could try:

http://h3.gd/code/xfProf/

Although I don't believe it uses the data from -profile. On linux/OS X  
you can use valgrind/kcachegrind, though it doesn't have demangling for  
D symbols (at least, last time I checked).




Nope, linux. But I bet the feature is used, so somewhere out there,  
there's some tools for making it simpler to make sense of :)


Re: GUI or more human readable -profile data?

2012-02-29 Thread Andrej Mitrovic
Boom: https://bitbucket.org/stqn/profiled

I've never used it though.


Re: how to use raw sockets

2012-02-29 Thread James Miller
On 1 March 2012 10:05, maarten van damme maartenvd1...@gmail.com wrote:
 I've tried porting libcap once but I failed miserably. If I'd succeed in
 porting they wouldn't be of good quality.

Not porting, writing bindings for it. Its pretty easy. just convert
the declarations into D extern (C) { declarations.
By the looks of it, you'll want to do bindings for
https://github.com/mcr/libpcap/blob/master/pcap/pcap.h and possibly
https://github.com/mcr/libpcap/blob/master/pcap/bpf.h.

The man page here, http://www.tcpdump.org/pcap3_man.html can also give
you a good starting point, and you could just write the bindings
straight from that if you want.

There is documentation to help people write C bindings here:
http://dlang.org/interfaceToC.html

Also if you submit it to Deimos, and if it happens to be a little
rough-around-the-edges or incomplete, somebody else can fill in the
gaps. Obviously you need to do a reasonable job, but it is only
writing function prototypes, so there's not much that can go wrong.

--
James Miller


Re: how to use raw sockets

2012-02-29 Thread maarten van damme
thank you, I'll give it a try.
One of my previous attempts failed because I didn't know what was really
needed to include in the bindings and what was excess. I'm going to post
what I have in a week, hope it works out.


Re: GUI or more human readable -profile data?

2012-02-29 Thread Jonathan M Davis
On Thursday, March 01, 2012 00:17:55 Robert Clipsham wrote:
 Just as a side note, -profile doesn't work with multi-threaded
 applications, so using some other profiler would probably be a better
 bet anyway.

It doesn't work with 64-bit programs either.

- Jonathan M Davis


Re: about std.csv and derived format

2012-02-29 Thread bioinfornatics
Le mercredi 29 février 2012 à 13:23 +0100, Jesse Phillips a écrit :
 On Wednesday, 29 February 2012 at 11:51:29 UTC, bioinfornatics 
 wrote:
  Le mercredi 29 février 2012 à 12:42 +0100, bioinfornatics a 
  écrit :
  Dear,
  
  I would like to parse this file:
  http://genome.ucsc.edu/goldenPath/help/ItemRGBDemo.txt
 
  My problem is:
  - need to parse data in csv format
  - how manage with optional field
 
 It looks like the data is tab delimited so separator is a tab. 
 There are no optional fields in CSV, but you can disable 
 exceptions.
 
 auto records = csvReader!(Bed,Malformed.ignore)(str,'\t');

thanks jesse;

how i can convert inputRange return type to Bed ?
csvReader return a type that change dynamycally so if i use a template
function the type is never same and i can't hard write a copy to Bed
type.
example if i use BedData3 or BedData4:

-
struct BedData3{
stringchrom;// 0
size_tchromStart;   // 1
size_tchromEnd; // 2
stringname; // 3
}

struct BedData4{
stringchrom;// 0
size_tchromStart;   // 1
size_tchromEnd; // 2
stringname; // 3
size_tscore;// 4
}


i have try to deal with ReturnType but i fail.

paste https://gist.github.com/1946288

at line 294 bedReader take ane BedData3 tp 11
then at line 338 how get an array of record and store this array into
struct bed line 192


thanks a lot



Regarding std.array.Appender

2012-02-29 Thread bearophile
Do you know why std.array.Appender defines a put method instead of 
overloading the ~= operator?

Bye and thank you,
bearophile


Re: Regarding std.array.Appender

2012-02-29 Thread Jonathan M Davis
On Wednesday, February 29, 2012 20:25:35 bearophile wrote:
 Do you know why std.array.Appender defines a put method instead of
 overloading the ~= operator?

put is a function on output ranges, and Appender is an output range.

- Jonathan M Davis


Re: Regarding std.array.Appender

2012-02-29 Thread Andrej Mitrovic
Luckily you can always use alias this and overload opCatAssign. 'alias
this' is a great tool for customizing APIs. :)


Re: Regarding std.array.Appender

2012-02-29 Thread Jonathan M Davis
On Wednesday, February 29, 2012 20:53:04 Jonathan M Davis wrote:
 On Wednesday, February 29, 2012 20:25:35 bearophile wrote:
  Do you know why std.array.Appender defines a put method instead of
  overloading the ~= operator?
 
 put is a function on output ranges, and Appender is an output range.

Also, given that it doesn't define ~ (and it wouldn't really make sense for it 
to), it would be very weird IMHO to define ~=.

- Jonathan M Davis


Re: about std.csv and derived format

2012-02-29 Thread bioinfornatics
Le jeudi 01 mars 2012 à 01:52 +0100, bioinfornatics a écrit :
 Le mercredi 29 février 2012 à 13:23 +0100, Jesse Phillips a écrit :
  On Wednesday, 29 February 2012 at 11:51:29 UTC, bioinfornatics 
  wrote:
   Le mercredi 29 février 2012 à 12:42 +0100, bioinfornatics a 
   écrit :
   Dear,
   
   I would like to parse this file:
   http://genome.ucsc.edu/goldenPath/help/ItemRGBDemo.txt
  
   My problem is:
   - need to parse data in csv format
   - how manage with optional field
  
  It looks like the data is tab delimited so separator is a tab. 
  There are no optional fields in CSV, but you can disable 
  exceptions.
  
  auto records = csvReader!(Bed,Malformed.ignore)(str,'\t');
 
 thanks jesse;
 
 how i can convert inputRange return type to Bed ?
 csvReader return a type that change dynamycally so if i use a template
 function the type is never same and i can't hard write a copy to Bed
 type.
 example if i use BedData3 or BedData4:
 
 -
 struct BedData3{
 stringchrom;// 0
 size_tchromStart;   // 1
 size_tchromEnd; // 2
 stringname; // 3
 }
 
 struct BedData4{
 stringchrom;// 0
 size_tchromStart;   // 1
 size_tchromEnd; // 2
 stringname; // 3
 size_tscore;// 4
 }
 
 
 i have try to deal with ReturnType but i fail.
 
 paste https://gist.github.com/1946288
 
 at line 294 bedReader take ane BedData3 tp 11
 then at line 338 how get an array of record and store this array into
 struct bed line 192
 
 
 thanks a lot
 

It is ok i have found a way maybe is not an efficient way but it works:
https://gist.github.com/1946669

a minor bug exist for parse track line will be fixed tomorrow. time to
bed


Big thanks to all



Re: Regarding std.array.Appender

2012-02-29 Thread bearophile
Jonathan M Davis:

  put is a function on output ranges, and Appender is an output range.
 
 Also, given that it doesn't define ~ (and it wouldn't really make sense for 
 it 
 to), it would be very weird IMHO to define ~=.

I don't understand why that's weird.
In Java you can't overload an append operator, so using a method is right. But 
for me it's weird that Appender doesn't use the D operator to _append_. I 
sometimes use add instead of put by mistake, forgetting the right method 
name, because I find it quite unnatural. If Appender needs a put, then I 
suggest to give it both put method and ~= operator.

Bye,
bearophile


Re: Regarding std.array.Appender

2012-02-29 Thread Adam D. Ruppe

On Thursday, 1 March 2012 at 02:23:55 UTC, bearophile wrote:
But for me it's weird that Appender doesn't use the D operator 
to _append_.  [...] I suggest to give it both put method and 
~= operator.


I agree entirely.


Another annoyance is if you have a function that works on
regular arrays, you probably used ~=.

But you decide to switch to Appender to try for a speed boost.

Now you have to change all the usage too, since the interfaces
are incompatible!


Re: Regarding std.array.Appender

2012-02-29 Thread Jonathan M Davis
On Wednesday, February 29, 2012 21:23:54 bearophile wrote:
 Jonathan M Davis:
   put is a function on output ranges, and Appender is an output range.
  
  Also, given that it doesn't define ~ (and it wouldn't really make sense
  for it to), it would be very weird IMHO to define ~=.
 
 I don't understand why that's weird.
 In Java you can't overload an append operator, so using a method is right.
 But for me it's weird that Appender doesn't use the D operator to _append_.
 I sometimes use add instead of put by mistake, forgetting the right
 method name, because I find it quite unnatural. If Appender needs a put,
 then I suggest to give it both put method and ~= operator.

Would you define += without defining +? Or *= without defining *? It strikes me 
as a misuse of operator overloading if you have an opOpAssign without its 
corresponding opBinary.

- Jonathan M Davis


Re: Regarding std.array.Appender

2012-02-29 Thread Jonathan M Davis
On Thursday, March 01, 2012 03:29:06 Adam D. Ruppe wrote:
 On Thursday, 1 March 2012 at 02:23:55 UTC, bearophile wrote:
  But for me it's weird that Appender doesn't use the D operator
  to _append_.  [...] I suggest to give it both put method and
  ~= operator.
 
 I agree entirely.
 
 
 Another annoyance is if you have a function that works on
 regular arrays, you probably used ~=.
 
 But you decide to switch to Appender to try for a speed boost.
 
 Now you have to change all the usage too, since the interfaces
 are incompatible!

True, but it can't do all of the other operations that array can do either. 
It's an output range, not an array. And odds are that it's going to be 
refactored such that it doesn't even contain an array internally anymore, 
beacause that's an inefficient way to implement appending. Someone (Robert 
Jacques IIRC, but I'd have to check) has already created such an 
implementation, and there's a decent chance that it's going to make it into 
Phobos.

So, I'm not sure that treating Appender as an array is really a good idea in 
the first place. If you want the truly generic approach, then treat is an 
output range.

- Jonathan M Davis


Re: Regarding std.array.Appender

2012-02-29 Thread Adam D. Ruppe

On Thursday, 1 March 2012 at 02:44:35 UTC, Jonathan M Davis wrote:
True, but it can't do all of the other operations that array 
can do either.


Yeah, but the one operation it replaces, ~=, can be done
on an array.

If you're trying to convert array code to Appender for
speed, most likely you're going to be replacing a
bunch of ~= calls.

It's ok if the other op don't compile, but this one
really should. Appender, regardless of the internal
representation vs array is a speed optimization;
an implementation detail.


It's an output range, not an array.


It's also an Appender, though. I think it is a little
silly to have an Appender to which you can't /append/.

(put is great too, don't get me wrong, but so is ~=).


Why do bitfields throw exceptions instead of wrapping?

2012-02-29 Thread ixid

In C++ this works:

struct test
{
unsigned int h : 2;
};

int main()
{
test b;
b.h = 0;
for(int i = 0;i  10;i++)
++b.h;
return 0;
}

In D this throws an exception as soon as it wraps:

struct test
{
mixin(bitfields!(
 uint, h, 2,
 uint, , 30));
};

int main()
{
test b;
b.h = 0;
for(int i = 0;i  10;i++)
b.h = b.h + 1;
return 0;
}

Is there any way to make it work directly like the C++ example 
without doing something like

if(bitfield is at max)
wrap it by hand;

It also seems odd to leave out the various shortcut operators 
like ++, *= etc fr bitfields.


Re: Regarding std.array.Appender

2012-02-29 Thread James Miller
On 1 March 2012 15:49, Adam D. Ruppe destructiona...@gmail.com wrote:
 On Thursday, 1 March 2012 at 02:44:35 UTC, Jonathan M Davis wrote:

 True, but it can't do all of the other operations that array can do
 either.


 Yeah, but the one operation it replaces, ~=, can be done
 on an array.

 If you're trying to convert array code to Appender for
 speed, most likely you're going to be replacing a
 bunch of ~= calls.

 It's ok if the other op don't compile, but this one
 really should. Appender, regardless of the internal
 representation vs array is a speed optimization;
 an implementation detail.


 It's an output range, not an array.


 It's also an Appender, though. I think it is a little
 silly to have an Appender to which you can't /append/.

 (put is great too, don't get me wrong, but so is ~=).

I can see both sides, but I'm on Adam's side here. While all the other
opOpAssign functions are defined in terms of their opBinary equivalent
(e.g, += is 'add and assign'), ~= is essentially an operator in its
own right, specifically an append (as opposed to '~' which is
concatenate). Having both ~= and .put() would be fine, and would make
switching from arrays to Appenders much easier.

I understand that Appenders aren't arrays, and should not be used as
such, but you /can/ use an array as an Appender. At some point, you
have to concede design purity to convenience, otherwise you have a
language that is actively hostile to changing designs. *In best
nagging wife voice* You should have used an Appender from the
start. Now you have to go change all that code. Its your own fault
really

--
James Miller


Re: Why do bitfields throw exceptions instead of wrapping?

2012-02-29 Thread James Miller
On 1 March 2012 16:15, ixid nuacco...@gmail.com wrote:
 In C++ this works:

 struct test
 {
        unsigned int h : 2;
 };

 int main()
 {
        test b;
        b.h = 0;
        for(int i = 0;i  10;i++)
                ++b.h;
        return 0;
 }

 In D this throws an exception as soon as it wraps:

 struct test
 {
        mixin(bitfields!(
                                         uint, h, 2,
                                         uint, , 30));
 };

 int main()
 {
        test b;
        b.h = 0;
        for(int i = 0;i  10;i++)
                b.h = b.h + 1;
        return 0;
 }

 Is there any way to make it work directly like the C++ example without doing
 something like
 if(bitfield is at max)
    wrap it by hand;

 It also seems odd to leave out the various shortcut operators like ++, *=
 etc fr bitfields.

Looking through the bitmanip code, what happens is that the mixin
creates properties, including the setters and getters for those
properties, in the struct.

Due to the way @properties work, b.h is an rvalue, this is because b.h
- b.h(), the @property declaration just makes it so you can omit the
parenthesis. Thinking of it like this, you wouldn't try
this.getInt()++ would you?

Some experimentation shows that a ref getter allows for this kind of
modification, however, it is difficult to have both ref T and T
getters, due to the compiler not being able to choose which is which
when resolving the calls in most cases. Unfortunately it would be
unwise to just change the getter to a ref type, since that would mean
that any changes to it after retrieval would affect the original.

It is difficult to create a bit field that allows for all of the
features described, but still prevents stupid code from prevailing.
e.g. a 2-bit uint a: a = 4, if it wrapped rather than errored, then
that could cause all sorts of errors down the line, and would be
incredibly hard to diagnose.

If you want wrapping however, during the increment you can do this:

b.h = (b.h + 1) % b.h_max;

since all fields define a *_max field. Not as elegant as doing it
internally, but better than using a condition.

Bitfields are for tightly packed data, and therefore expecting all
language features to be available is missing the point. Hell bitfields
are provided by templates, so they aren't even a part of the language,
they are just a library feature.

Hope that helps

--
James Miller


Re: Regarding std.array.Appender

2012-02-29 Thread Ali Çehreli

On 02/29/2012 08:28 PM, James Miller wrote:

 I understand that Appenders aren't arrays, and should not be used as
 such, but you /can/ use an array as an Appender.

Yes you can but whatever you put() into the array is immediately 
popFront()'ed from the array. ;) You must use a temporary surrogate slice:


import std.stdio;
import std.range;

void main()
{
int[] array = [ 1, 2, 3 ];
int[] slice = array;

put(slice, 100);  // -- slice shrinks! :)
}

slice.length is 2 and array.length is 3.

 At some point, you
 have to concede design purity to convenience, otherwise you have a
 language that is actively hostile to changing designs.

Agreed.

Ali