Re: mixing array and string .find()

2009-03-23 Thread BCS

Hello Brian,


is it possible to write a generic .find function for arrays that
ignores strings and so doesn't cause conflicts? I think in D2 its easy
by putting an if() constraint on the template, but is it possible in
D1? like:



one solution is to dump the std.string.find (or alias it) and have the templated 
function cover that case as well.


template find(T) // untested so that might not work
{
  int find(T[] array, T obj) { ... }
  static if(is(T == char)
 alias std.string.find find;
  else
 int find(T[] array, T[] obj) { ... }
}




Re: mixing array and string .find()

2009-03-23 Thread Jarrett Billingsley
On Mon, Mar 23, 2009 at 9:11 PM, Denis Koroskin <2kor...@gmail.com> wrote:
> Try the following:
>
> int find(T)(T[] array, T obj) if (!is(T : char))
> {
>        foreach (i, v; array) {
>                if (v == obj)
>                        return i;
>        }
>        return -1;
> }
>
>

in D1.


Re: mixing array and string .find()

2009-03-23 Thread Denis Koroskin

Try the following:

int find(T)(T[] array, T obj) if (!is(T : char))
{
foreach (i, v; array) {
if (v == obj)
return i;
}
return -1;
}



Re: mixing array and string .find()

2009-03-23 Thread Jarrett Billingsley
On Mon, Mar 23, 2009 at 8:11 PM, Brian  wrote:
> is it possible to write a generic .find function for arrays that ignores
> strings and so doesn't cause conflicts? I think in D2 its easy by putting
> an if() constraint on the template, but is it possible in D1? like:

D2's overload sets would help here more than an if() constraint.  But
even still, it might be ambiguous.

You don't actually have to import one statically.  Just alias the one
you want to take precedence in the current module:

import std.string;
import my.templates;

alias my.templates.find find;

Now whenever you use 'find' it will use my.templates.find.


Re: No map file?

2009-03-23 Thread Derek Parnell
On Mon, 23 Mar 2009 10:02:28 +0100, Frank Benoit wrote:

> How can i make DMD (link/optlink) not to generate a map file?
> 
> -L/NOM or -LNOMAP
> 
> both seem not work.

You can't using dmd. It doesn't generate the right linker options for you
to avoid the map file. I do it in Bud by not having DMD invoke the linker,
instead I have Bud invoke the linker with the right options.

The easiest way is to delete the .map files after compiling.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell


mixing array and string .find()

2009-03-23 Thread Brian
is it possible to write a generic .find function for arrays that ignores 
strings and so doesn't cause conflicts? I think in D2 its easy by putting 
an if() constraint on the template, but is it possible in D1? like:

int find(T)(T[] array, T obj) {
foreach (i, v; array) {
if (v == obj)
return i;
}
return -1;
}

this conflicts with std.string.find, so i have to import one of them 
statically and use it like.
std.string.find("mystr", "s");

i want to be able to just have:
int[] arr;
arr.find(5);

string s;
s.find("foo");


Re: I hate ".dup"

2009-03-23 Thread Steven Schveighoffer

On Mon, 23 Mar 2009 11:07:16 -0400, Qian Xu 
wrote:


I have spent one day to find out an error.

-
class MyTime
{
  this(char[] timestring)
  {
 Time t;
 int p = tango.time.TimeStamp.iso8601(timestring, t);
 //...
  }
  // other methods
}
unittest
{
  MyTime mt = new MyTime("01:10:20,050");
  assert(MyTime.addMillis(mt, 1).toString() == "01:10:20,051"); //  
sometimes

failed
}
-

I ran this unit-test together with some other tests. Sometimes no error,
sometimes with errors.

Finally I have added timestring.dup in constructor, the problem does not
appear any more.

Oh god. I have to add ".dup" at the end of every string to avoid  
potential

program errors. This is so incredible


Best regards
Qian Xu


Coincidentally, someone else discovered a buffer-overrun bug in
tango.text.convert.TimeStamp, see
http://www.dsource.org/projects/tango/forums/topic/704

Please try downloading the latest trunk code and see if your code still
fails.

You should not have to .dup the string, if you do, that is a bug.

-Steve


Re: I hate ".dup"

2009-03-23 Thread Jarrett Billingsley
On Mon, Mar 23, 2009 at 12:15 PM, BCS  wrote:
> Hello Qian,
>
>> Oh god. I have to add ".dup" at the end of every string to avoid
>> potential program errors. This is so incredible
>>
>
> Run it on linux and it will seg-v when you try to access a literal string.
>
> Oh, and that issue is in no way unique to D. Any language with mutable
> strings will have it and any language without will force the copies anyway
> (but with better syntax)

It is unique to DMD/Optlink.  GDC Win will produce EXEs that throw a
segfault if you attempt to modify a read-only string.


Re: No map file?

2009-03-23 Thread Jarrett Billingsley
On Mon, Mar 23, 2009 at 11:11 AM, torhu  wrote:
> On 23.03.2009 10:02, Frank Benoit wrote:
>>
>> How can i make DMD (link/optlink) not to generate a map file?
>>
>> -L/NOM or -LNOMAP
>>
>> both seem not work.
>
> I don't know, but bud manages this somehow, so Derek Parnell might know.
>

rm *.map

:P


Re: I hate ".dup"

2009-03-23 Thread BCS

Hello Qian,


Oh god. I have to add ".dup" at the end of every string to avoid
potential program errors. This is so incredible



Run it on linux and it will seg-v when you try to access a literal string.

Oh, and that issue is in no way unique to D. Any language with mutable strings 
will have it and any language without will force the copies anyway (but with 
better syntax)





Tango ftp module

2009-03-23 Thread Trass3r

Has anyone ever tried the tango ftp code?
Nothing really works for me, even for simple cases.

For example, when using ls() it gets stuck in parseMlstLine() cause the 
exception

throw new FTPException("CLIENT: Bad syntax in MLSx response", "501");
doesn't get caught.
Thus the else branch isn't executed:
// If it passed, parse away!
if (mlsd_success)
[...]
// Fall back to LIST.
else
return this.sendListCommand(path);

and ls() doesn't work at all.


Is there any working example at all?


Re: No map file?

2009-03-23 Thread torhu

On 23.03.2009 10:02, Frank Benoit wrote:

How can i make DMD (link/optlink) not to generate a map file?

-L/NOM or -LNOMAP

both seem not work.


I don't know, but bud manages this somehow, so Derek Parnell might know.


I hate ".dup"

2009-03-23 Thread Qian Xu
I have spent one day to find out an error.

-
class MyTime
{
  this(char[] timestring)
  {
 Time t;
 int p = tango.time.TimeStamp.iso8601(timestring, t);
 //...
  }
  // other methods
}
unittest
{
  MyTime mt = new MyTime("01:10:20,050");
  assert(MyTime.addMillis(mt, 1).toString() == "01:10:20,051"); // sometimes
failed
}
-

I ran this unit-test together with some other tests. Sometimes no error,
sometimes with errors. 

Finally I have added timestring.dup in constructor, the problem does not
appear any more. 

Oh god. I have to add ".dup" at the end of every string to avoid potential
program errors. This is so incredible


Best regards
Qian Xu


Re: How to reduce compile times?

2009-03-23 Thread grauzone

Jarrett Billingsley wrote:

On Sat, Mar 21, 2009 at 3:45 PM, grauzone  wrote:

Also, I noticed that "dsss build -full" seems to be the way to pass this
flag on the command line. But the project is recompiled even when no file
was modified at all. This is not good: it should only recompile if something
has changed.


Why would you recompile if you haven't changed anything?  :P


I want to build system to recompile the program automatically before I 
execute it. Doing this manually is not an option, because it's annoying 
and I could forget it.


Re: How to reduce compile times?

2009-03-23 Thread Robert Fraser

Jarrett Billingsley wrote:

On Sat, Mar 21, 2009 at 3:45 PM, grauzone  wrote:

Also, I noticed that "dsss build -full" seems to be the way to pass this
flag on the command line. But the project is recompiled even when no file
was modified at all. This is not good: it should only recompile if something
has changed.


Why would you recompile if you haven't changed anything?  :P


If you have a build script that invokes the compiler among many other 
things, a continuous integration system, etc.


No map file?

2009-03-23 Thread Frank Benoit
How can i make DMD (link/optlink) not to generate a map file?

-L/NOM or -LNOMAP

both seem not work.