Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-12 Thread FrankLike via Digitalmars-d-learn
There are some quotes missing when building the Debug 
configuration. I have committed a fix and also added the 
missing file reported in your other message (IIRC it is not 
needed by every VS SDK).


Sorry,Rainer Schuetze,
Here is some error when compile the VisualD:

--ERROR START
Building Resources\pkgcmd.cto
Command Line
set PATH=D:\D\dmd2\windows\bin;C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\\bin;%PATH%

set DMD_LIB=D:\D\dmd2\windows\lib
set VS9SDKBIN=c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin
set CTC=%VS9SDKBIN%\CTC.exe
if not exist %CTC% goto no_CTC
if not exist C:\Program Files (x86)\Microsoft Visual Studio 
10.0\\Common7\Tools\vsvars32.bat goto no_CTC

set PATH=%PATH%;%VS9SDKBIN%
call C:\Program Files (x86)\Microsoft Visual Studio 
10.0\\Common7\Tools\vsvars32.bat

if errorlevel 1 goto reportError
%CTC% Resources\pkgcmd.ctc Resources\pkgcmd.cto -Ccl -I.
goto reportError

:no_CTC
echo Warning: CTC.exe not found in %VS9SDKBIN%.
echo It is part of the VS2008 SDK and is needed to compile 
Resources\pkgcmd.ctc

if not exist Resources\pkgcmd.cto exit 1
echo Resources\pkgcmd.cto exists, so it is assumed to be up to 
date.
echo If the project rebuilt again and again with this message, 
touch Resources\pkgcmd.cto to make it newer than 
Resources\pkgcmd.ctc

:reportError
:reportError
if errorlevel 1 echo Building Resources\pkgcmd.cto failed!
Output
Warning: CTC.exe not found in 
c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin.
It is part of the VS2008 SDK and is needed to compile 
Resources\pkgcmd.ctc

-ERROR END-

I found it always to overwite the file 
'visuald\visuald\Resources\pkgcmd.cto.build.cmd',let the 
'VS9SDKBIN=c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin' not use

'%VSSDK100Install%VisualStudioIntegration\Tools\Bin' .
Then failed.

Thank you  again.

Frank


Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-12 Thread FrankLike via Digitalmars-d-learn

On Monday, 12 May 2014 at 06:36:10 UTC, FrankLike wrote:
There are some quotes missing when building the Debug 
configuration. I have committed a fix and also added the 
missing file reported in your other message (IIRC it is not 
needed by every VS SDK).



 Sorry,Rainer Schuetze,
And there is a little error in sdk.bat
'(echo unexpected Visual Studio SDK installation at %VSISDKINC% 
 exit /B 1)'

%VSISDKINC% should be %VSISDKINC%

Thank you again.

Frank




Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-12 Thread Rainer Schuetze via Digitalmars-d-learn



On 12.05.2014 08:36, FrankLike wrote:

There are some quotes missing when building the Debug configuration. I
have committed a fix and also added the missing file reported in your
other message (IIRC it is not needed by every VS SDK).


Sorry,Rainer Schuetze,
Here is some error when compile the VisualD:

--ERROR START
Building Resources\pkgcmd.cto
Command Line
set PATH=D:\D\dmd2\windows\bin;C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\\bin;%PATH%
set DMD_LIB=D:\D\dmd2\windows\lib
set VS9SDKBIN=c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin
set CTC=%VS9SDKBIN%\CTC.exe
if not exist %CTC% goto no_CTC
if not exist C:\Program Files (x86)\Microsoft Visual Studio
10.0\\Common7\Tools\vsvars32.bat goto no_CTC
set PATH=%PATH%;%VS9SDKBIN%
call C:\Program Files (x86)\Microsoft Visual Studio
10.0\\Common7\Tools\vsvars32.bat
if errorlevel 1 goto reportError
%CTC% Resources\pkgcmd.ctc Resources\pkgcmd.cto -Ccl -I.
goto reportError

:no_CTC
echo Warning: CTC.exe not found in %VS9SDKBIN%.
echo It is part of the VS2008 SDK and is needed to compile
Resources\pkgcmd.ctc
if not exist Resources\pkgcmd.cto exit 1
echo Resources\pkgcmd.cto exists, so it is assumed to be up to date.
echo If the project rebuilt again and again with this message, touch
Resources\pkgcmd.cto to make it newer than Resources\pkgcmd.ctc
:reportError
:reportError
if errorlevel 1 echo Building Resources\pkgcmd.cto failed!
Output
Warning: CTC.exe not found in
c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin.
It is part of the VS2008 SDK and is needed to compile Resources\pkgcmd.ctc
-ERROR END-

I found it always to overwite the file
'visuald\visuald\Resources\pkgcmd.cto.build.cmd',let the
'VS9SDKBIN=c:\l\vs9SDK\VisualStudioIntegration\Tools\Bin' not use
'%VSSDK100Install%VisualStudioIntegration\Tools\Bin' .
Then failed.


ctc.exe is not distributed with the SDKs starting from VS2010, so 
mapping to a more recent version does not work. That's why there is a 
precompiled pkgcmd.cto file in the repository. You'll have to update its 
modification time to avoid the build process trying to generate it from 
pkgcmd.ctc every time.


The explicitely used c:\l\vs9SDK is my installation, I should add a 
check for %VSSDK90Install% here.


Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-12 Thread Rainer Schuetze via Digitalmars-d-learn



On 12.05.2014 08:38, FrankLike wrote:

On Monday, 12 May 2014 at 06:36:10 UTC, FrankLike wrote:

There are some quotes missing when building the Debug configuration.
I have committed a fix and also added the missing file reported in
your other message (IIRC it is not needed by every VS SDK).



  Sorry,Rainer Schuetze,
And there is a little error in sdk.bat
'(echo unexpected Visual Studio SDK installation at %VSISDKINC%  exit
/B 1)'
%VSISDKINC% should be %VSISDKINC%



I agree it is a bit clearer with quotes, but echo still works without, 
doesn't it?




Re: Down the VisualD0.3.38-1.exe ,found virus!

2014-05-12 Thread FrankLike via Digitalmars-d-learn


ctc.exe is not distributed with the SDKs starting from VS2010, 
so mapping to a more recent version does not work. That's why 
there is a precompiled pkgcmd.cto file in the repository. 
You'll have to update its modification time to avoid the build 
process trying to generate it from pkgcmd.ctc every time.


The explicitely used c:\l\vs9SDK is my installation, I should 
add a check for %VSSDK90Install% here.


Sorry,Rainer Schuetze,

Use it ,this is a good idea:
set VSISDKINC=
if %VSISDKINC% ==  if not %VSSDK120Install% ==  set 
VSISDKINC=%VSSDK120Install%
if %VSISDKINC% ==  if not %VSSDK110Install% ==  set 
VSISDKINC=%VSSDK110Install%
if %VSISDKINC% ==  if not %VSSDK100Install% ==  set 
VSISDKINC=%VSSDK100Install%
if %VSISDKINC% ==  if not %VSSDK90Install% ==  set 
VSISDKINC=%VSSDK90Install%
if %VSISDKINC% ==  if not %VSSDK80Install% ==  set 
VSISDKINC=%VSSDK80Install%
if %VSISDKINC% ==  (echo could not detect the Visual Studio 
SDK  exit /B 1)




 Sorry,Rainer Schuetze,
And there is a little error in sdk.bat
'(echo unexpected Visual Studio SDK installation at 
%VSISDKINC%  exit

/B 1)'
%VSISDKINC% should be %VSISDKINC%



I agree it is a bit clearer with quotes, but echo still works 
without, doesn't it?


Not work now in VS2010.
The error is : '\Microsoft is '

Thank you.

Frank


Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread JR via Digitalmars-d-learn

Given that...

1. importing a module makes it compile the entirety of it, as 
well as whatever it may be importing in turn

2. templates are only compiled if instantiated
3. the new package.d functionality

...is there a reason *not* to make every single 
function/struct/class separate submodules in a package, and make 
*all* of those templates? Unnused functionality would never be 
imported nor instantiated, and as such never be compiled, so my 
binary would only include what it actually uses.



std/stdio/package.d:
module std.stdio;
// still allows for importing the entirety of std.stdio

public import std.stdio.foo;
public import std.stdio.writefln;
__EOF__


std/stdio/foo.d:
module std.stdio.foo;

void fooify(Args...)(Args args)
if (Args.length  0)
{
// ...
}

void fooify()()
{
// don't need this, won't compile this
}
__EOF__


std/stdio/writefln.d;
module std.stdio.writefln;

// nevermind the incompatible signature
auto writefln(string pattern, Args...)(Args args)
if (!pattern.canFind(PatternIdentifier.json))
{
// code that doesn't need std.json -- it is never 
imported

}
__EOF__


What am I missing?


Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 08:37:42 +
JR via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Given that...

 1. importing a module makes it compile the entirety of it, as
 well as whatever it may be importing in turn
 2. templates are only compiled if instantiated
 3. the new package.d functionality

 ...is there a reason *not* to make every single
 function/struct/class separate submodules in a package, and make
 *all* of those templates? Unnused functionality would never be
 imported nor instantiated, and as such never be compiled, so my
 binary would only include what it actually uses.


 std/stdio/package.d:
  module std.stdio;
  // still allows for importing the entirety of std.stdio

  public import std.stdio.foo;
  public import std.stdio.writefln;
  __EOF__


 std/stdio/foo.d:
  module std.stdio.foo;

  void fooify(Args...)(Args args)
  if (Args.length  0)
  {
  // ...
  }

  void fooify()()
  {
  // don't need this, won't compile this
  }
  __EOF__


 std/stdio/writefln.d;
  module std.stdio.writefln;

  // nevermind the incompatible signature
  auto writefln(string pattern, Args...)(Args args)
  if (!pattern.canFind(PatternIdentifier.json))
  {
  // code that doesn't need std.json -- it is never
 imported
  }
  __EOF__


 What am I missing?

Well, that would be a lot of extraneous files, which would be very messy IMHO.
It also makes it much harder to share private functionality, because
everything is scattered across modules - you'd be force to use the package for
that. It also wouldn't surprise me if it cost more to compile the code that
way if you were actually using most of it (though it may very well save
compilation time if you're using a relatively small number of the functions
and types). So, from a purely organization perspective, I think that it's a
very bad idea, though others may think that it's a good one. And since
package.d imports all of those modules anyway, separating them out into
separate files didn't even help you any.

Also, templates cost more to compile, so while you may avoid having to compile
some functions, becasue you're not using them, everything that _does_ get
compiled will take longer to compile. And if you templatize them in a way that
would result in more template instantiations (e.g. you actually templatize the
parameters rather than just giving the function an empty template parameter
list), then not only will the functions have to be compiled more frequently
(due to multiple instantiations), but they'll take up more space in the final
binary. Also, while D does a _much_ better job with template errors than C++
does, template-related errors in D are still far worse than with functions
that aren't templated, so you're likely going to cost yourself more time
debugging template-related compilation errors than you ever would gain in
reduced compilation times.

In addition, if a function is templatized, it's harder to use it with function
prototypes, which can be a definite problem for some code. It's also a
horrible idea for libraries to have functions templatized just to be
templatized, because that means that a function has to be compiled _every_
time that a program uses it rather than having it compiled once when the
library is compiled (the function would still have to be parsed unless it just
had its signature in a .di file, but that's still faster than full
compilation - and if a .di file is used, then all that has to be parsed is the
signature). So, while it's often valuable to templatize functions,
templatizing them to save compilation times is questionable at best.

D already does a _very_ good job at compiling quickly. Often, the linking step
costs more than the actualy compilation does (though obviosuly, as programs
grow larger, the compilation time does definitely exceed the link time).
Unless you're running into problems with compilation speed, I'd strongly
advise against trying to work around the compiler to speed up code
compilation. Templatize functions when it makes sense to do so, but don't
templatize them just in an attempt to avoid having them be compiled.

If you're looking to speed up compilation times, it makes far more sense to
look at doing things like reducing how much CTFE you use and how many
templates you use. CTFE in particular is ridiculously expensive thanks to it
effectively just being hacked into the compiler originally. Don has been doing
work to improve that, and I expect it to improve over time, but I don't know
how far along he is, and I don't know that it'll ever be exactly cheap to use
CTFE.

Keep in mind that lexing and parsing are the _cheap_ part of the compiler. So,
importing stuff really doesn't cost you much. Already, the compiler won't
fully compile all of the symbols within a module except when it's compiling
that module. Simply importing it just causes it to process the module as much
as required to 

Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread hane via Digitalmars-d-learn

and is there any way to sort char array with algorithm.sort?
---
import std.algorithm;
import std.range;

void main()
{
  int[] arr = [5, 3, 7];
  sort(arr); // OK

  char[] arr2 = ['z', 'g', 'c'];
  sort(arr2); // error
  sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
}
---
I don't know what's difference between int[] and char[] in D, but 
it's very unnatural.


Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread John Colvin via Digitalmars-d-learn

On Monday, 12 May 2014 at 14:49:53 UTC, hane wrote:

and is there any way to sort char array with algorithm.sort?
---
import std.algorithm;
import std.range;

void main()
{
  int[] arr = [5, 3, 7];
  sort(arr); // OK

  char[] arr2 = ['z', 'g', 'c'];
  sort(arr2); // error
  sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
}
---
I don't know what's difference between int[] and char[] in D, 
but it's very unnatural.


char[] is a rather special type of array: the language has 
unicode support and iterates over it by code-point (i.e. not 
guaranteed to be a single char per iteration).


If you want to sort chars and are assuming ASCII, you can just 
use std.string.representation to work with them as integer types:


import std.algorithm;
import std.range;
import std.string;

void main()
{
  int[] arr = [5, 3, 7];
  sort(arr); // OK

  char[] arr2 = ['z', 'g', 'c'];
  sort(arr2.representation); // error
  sort!q{ a[0]  b[0] }(zip(arr, arr2.representation)); // error
}


Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread John Colvin via Digitalmars-d-learn

On Monday, 12 May 2014 at 14:56:46 UTC, John Colvin wrote:

On Monday, 12 May 2014 at 14:49:53 UTC, hane wrote:

and is there any way to sort char array with algorithm.sort?
---
import std.algorithm;
import std.range;

void main()
{
 int[] arr = [5, 3, 7];
 sort(arr); // OK

 char[] arr2 = ['z', 'g', 'c'];
 sort(arr2); // error
 sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
}
---
I don't know what's difference between int[] and char[] in D, 
but it's very unnatural.


char[] is a rather special type of array: the language has 
unicode support and iterates over it by code-point (i.e. not 
guaranteed to be a single char per iteration).


If you want to sort chars and are assuming ASCII, you can just 
use std.string.representation to work with them as integer 
types:


import std.algorithm;
import std.range;
import std.string;

void main()
{
  int[] arr = [5, 3, 7];
  sort(arr); // OK

  char[] arr2 = ['z', 'g', 'c'];
  sort(arr2.representation); // error
  sort!q{ a[0]  b[0] }(zip(arr, arr2.representation)); // error
}


woops, should have deleted the // error comments


Re: Configuring Phobos from the 1-click installer

2014-05-12 Thread Moses via Digitalmars-d-learn
PATH environment variable is not related at all with phobos2 
sources paths.


All Linux packages (Ubuntu too) includes 
-I/usr/include/dmd/phobos on /etc/dmd.conf configuration file.
If you need to explicit pass this argument to dmd compiler, may 
be due to several reasons.


- You've edited your /etc/dmd.conf file.

- You've created a new dmd.conf on your current directory, on 
you home directory or on dmd command directory (/usr/bin/).


Any dmd.conf file on these places, overrides /etc/dmd.conf

Take a look at:
$ cat /etc/dmd.conf

Regard,



I didn't find any extra dmd.conf files, but I found that adding
#!/usr/include/dmd/phobos
to the top of my D program solved the problem to my satisfaction. 
Thanks so much for your help.


Re: Configuring Phobos from the 1-click installer

2014-05-12 Thread Kapps via Digitalmars-d-learn

On Monday, 12 May 2014 at 15:02:54 UTC, Moses wrote:
PATH environment variable is not related at all with phobos2 
sources paths.


All Linux packages (Ubuntu too) includes 
-I/usr/include/dmd/phobos on /etc/dmd.conf configuration 
file.
If you need to explicit pass this argument to dmd compiler, 
may be due to several reasons.


- You've edited your /etc/dmd.conf file.

- You've created a new dmd.conf on your current directory, 
on you home directory or on dmd command directory (/usr/bin/).


Any dmd.conf file on these places, overrides /etc/dmd.conf

Take a look at:
$ cat /etc/dmd.conf

Regard,



I didn't find any extra dmd.conf files, but I found that adding
#!/usr/include/dmd/phobos
to the top of my D program solved the problem to my 
satisfaction. Thanks so much for your help.


It really does seem like you have an extra dmd.conf that's being
loaded.

Type dmd -v abc.d - The first few lines should include what
config it's using.


Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread Ary Borenszweig via Digitalmars-d-learn

On 5/12/14, 5:37 AM, JR wrote:

Given that...

1. importing a module makes it compile the entirety of it, as well as
whatever it may be importing in turn
2. templates are only compiled if instantiated
3. the new package.d functionality

...is there a reason *not* to make every single function/struct/class
separate submodules in a package, and make *all* of those templates?
Unnused functionality would never be imported nor instantiated, and as
such never be compiled, so my binary would only include what it actually
uses.


Welcome to Crystal :-)

In Crystal, every function and method is templated. When you compile 
your program, only what you use gets compiled. A simple hello world 
program is just 16KB.


And contrary to what Jonathan M. Davis says, compiling programs is very 
fast. In fact, compilation times might indeed be faster, because you 
don't need to compile unused code. And the resulting binary is as small 
as possible. And the error messages are pretty good, also.


But D has an entirely different philosophy, so I don't think they will 
like it. I also once suggested auto for parameters, but they didn't 
like it.


I'm just saying this to say that yes, it's possible, and no, it doesn't 
hurt compilation times or error messages.


Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread JR via Digitalmars-d-learn
On Monday, 12 May 2014 at 09:16:53 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:
Well, that would be a lot of extraneous files, which would be 
very messy IMHO.
It also makes it much harder to share private functionality, 
because
everything is scattered across modules - you'd be force to use 
the package for
that. It also wouldn't surprise me if it cost more to compile 
the code that
way if you were actually using most of it (though it may very 
well save
compilation time if you're using a relatively small number of 
the functions
and types). So, from a purely organization perspective, I think 
that it's a
very bad idea, though others may think that it's a good one. 
And since
package.d imports all of those modules anyway, separating them 
out into

separate files didn't even help you any.


Thank you for answering. The package.d example was mostly to 
highlight that the current syntax and practice of importing 
everything in a package wouldn't change.


To be a bit more specific I'm new to everything beyond advanced 
scripting, so my code has grown organically. Partly due to 
shotgun programming, and partly due to exploratory programming. 
In the process of figuring out what code depends on what, to 
allow for making pieces of it more self-contained, I realized 
that with my current practice of gathering everything related to 
the same topic into one module made it all unneccesarily tangled. 
(--gc-sections seems to cause segfaults.)


As an example, both the homebrew string builder 'Yarn' and the 
simple 'string plurality(ptrdiff_t, string, string)' belong in 
mylib.string. But if I want to reuse only plurality there in 
other projects I would end up pulling in all the ancillary stuff 
Yarn needs to validate input, and it only segways from there. 
Correct?


The logical step would be to split the all-encompassing 
mylib.string module into submodules, and the logical followup 
question would be why I shouldn't do that everywhere. Knowing 
that templates aren't built unless concretely instantiated, the 
idea of templatizing everything fell into the same basket.


I hope you understand my concerns that I was falling into an 
anti-pattern.


Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 14:49:52 +
hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 and is there any way to sort char array with algorithm.sort?
 ---
 import std.algorithm;
 import std.range;

 void main()
 {
int[] arr = [5, 3, 7];
sort(arr); // OK

char[] arr2 = ['z', 'g', 'c'];
sort(arr2); // error
sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
 }
 ---
 I don't know what's difference between int[] and char[] in D, but
 it's very unnatural.

All strings in D are treated as ranges of dchar, not their element type. This
has to with the fact that a char or wchar are only part of a character. If you
want to sort arrays of characters, you need to use dchar[].

http://stackoverflow.com/questions/12288465
http://stackoverflow.com/questions/16590650

- Jonathan M Davis


How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn
Based on this conversation in another thread: 
http://forum.dlang.org/thread/wdddgiowaidcojbrk...@forum.dlang.org?page=5#post-yjmrqgesjtadecutvkye:40forum.dlang.org 
I've realised i may have a nasty bug lurking in the code. Now i 
want to completely understand what is happening.


Take the following code:

struct Args
{
Element element;
string uniqueData;
Callback callback;
}

class Element
{
void foo(Callback callback, string uniqueData = null)
{
auto handler = function(ClientData data)
{
// Use data.
};

auto cleanup = function(ClientData data)
{
free(data);
};

Args* args = cast(Args*)malloc(Args.sizeof);

(*args)= Args.init;
(*args).element= this;
(*args).uniqueData = uniqueData;
(*args).callback   = callback;

c_function(handler, args, cleanup);
}
}

I want to make sure that `callback` and `uniqueData` are never 
cleaned up by the GC until i wish to allow them to be freed. A 
comment was made that in the above scenario `callback` and 
`uniqueData` allow the potential of being cleaned up and that a 
call to `GC.addRoot` might fix this problem.


Would it be as simple to just add:

GC.addRoot(cast(void*)args);
GC.setAttr(cast(void*)args, GC.BlkAttr.NO_MOVE);

to the above example? Would this not allow collection until a 
call to GC.removeRoot(). Or do i have to handle `callback` and 
`uniqueData` individually? If so how do you stop a delegate and 
string from being cleaned up by the GC?


Any help or explanations are very much appreciated.

This is the actual production code: 
https://github.com/nomad-software/tkd/blob/master/source/tkd/element/element.d#L172


Re: core.sync.rwmutex example

2014-05-12 Thread Charles Hixson via Digitalmars-d-learn

On 05/10/2014 06:28 PM, TheFlyingFiddle via Digitalmars-d-learn wrote:
On Friday, 9 May 2014 at 23:12:44 UTC, Charles Hixson via 
Digitalmars-d-learn wrote:


But I'm worried about the receiving end. It needs, somehow, to ensure 
that the message it receives is the appropriate message, and that 
other messages don't get dropped while it's waiting for the 
answer...or, perhaps worse, substituted for the expected answer.  If 
I can depend on msg[0] of auto msg = receiveOnly!(Tid, bool) that 
will allow me to check that the message was received from the proper 
source


If you are worried that other messages having the same signature will 
be sent from other sources than the expected source you could make use 
of message tagging. Simply wrap the boolean result in a struct with a 
descriptive name.


struct SharedHashMapSetCB { bool flag; }
void set (string s, uint64_t id)
{
   tbl[s] = id;
   send (SharedHashMapSetCB(true));
}

//On the receiving end
auto msg = receiveOnly!SharedHashMapSetCB();

But doesn't this design lock the entire hash-table while the update 
is in progress?  Is there a better way?
I think a shared memory hash-map is better for your use case. Working 
with message passing is preferable done asynchronously. Blocking calls 
(send followed by receive) is likely to be slower then simply waiting 
on a semaphore.
I think you're probably right.  It should be a fairly fast lookup 
anyway, and since there should be only one copy of the table, I don't 
think one would get much of a speedup no matter what one did. OTOH, it 
can't be directly shared.  What can be shared is a handle to a singleton 
synchronized class.  Its requirement that it can be updated, IIUC, means 
that it can't be directly shared.


OTOH... I think I may need to build a mailbox class, the design I'm not 
yet sure about, that acts as an interface between the major number of 
threads and each other.  Access to it needs to be non-blocking 
(essentially) so it had probably better ONLY act as a message 
switchboard.  I want it to pass messages with time and origin 
(thread id) prefixed to them.  OTOH, I probably only need to support a 
small number of message formats, perhaps two, perhaps three.  And it 
would be more efficient if whenever a thread polled it, it responded 
with all waiting mail for that destination.  So it's only sending in 
response to a received message directed at it, but it holds all messages 
directed at some other thread.  This allows the other threads to loop 
through their processing, only occasionally pausing to check whether 
they have any mail or not. I'm hoping a couple of ms will be a long 
enough timeout.  The mailbox could spend most of it's time sitting 
blocked at receive.


This isn't the design I was thinking about earlier, but it seems better, 
and it's the design I originally ended up with the last time I thought 
about this problem seriously, though admittedly I never got around to 
implementing it.  The question in my mind is is it better to build this 
on top of std.concurrency, or to go back to the thread class.  The code 
of std.concurrency shows pretty clearly how to build a mailbox, but the 
one that it builds doesn't store the things that I want, and is a lot 
more flexible than I have any use for.  Still, it's being maintained as 
a part of the language...but it's a private class, so I can't use it 
directly.  But threading is difficult and error prone, so it might be 
better to write a layer on top of std.concurrency, even if it means I 
need to re-implement a lot of what has already been done.


--
Charles Hixson



Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Charles Hixson via Digitalmars-d-learn

On 05/12/2014 09:29 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

On Mon, 12 May 2014 14:49:52 +
hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:


and is there any way to sort char array with algorithm.sort?
---
import std.algorithm;
import std.range;

void main()
{
int[] arr = [5, 3, 7];
sort(arr); // OK

char[] arr2 = ['z', 'g', 'c'];
sort(arr2); // error
sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
}
---
I don't know what's difference between int[] and char[] in D, but
it's very unnatural.

All strings in D are treated as ranges of dchar, not their element type. This
has to with the fact that a char or wchar are only part of a character. If you
want to sort arrays of characters, you need to use dchar[].

http://stackoverflow.com/questions/12288465
http://stackoverflow.com/questions/16590650

- Jonathan M Davis

Given that he was working with pure ASCII, he should be able to cast the 
array to byte[] and sort it, but I haven't tried.  Also char[] isn't 
string.  Strings are immutable, and thus cannot be sorted in place.  To 
me this looks like an error in sort that he should be able to work 
around with a cast.


--
Charles Hixson



Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 11:08:47 -0700
Charles Hixson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On 05/12/2014 09:29 AM, Jonathan M Davis via Digitalmars-d-learn
 wrote:
  On Mon, 12 May 2014 14:49:52 +
  hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
  wrote:
 
  and is there any way to sort char array with algorithm.sort?
  ---
  import std.algorithm;
  import std.range;
 
  void main()
  {
  int[] arr = [5, 3, 7];
  sort(arr); // OK
 
  char[] arr2 = ['z', 'g', 'c'];
  sort(arr2); // error
  sort!q{ a[0]  b[0] }(zip(arr, arr2)); // error
  }
  ---
  I don't know what's difference between int[] and char[] in D, but
  it's very unnatural.
  All strings in D are treated as ranges of dchar, not their element
  type. This has to with the fact that a char or wchar are only part
  of a character. If you want to sort arrays of characters, you need
  to use dchar[].
 
  http://stackoverflow.com/questions/12288465
  http://stackoverflow.com/questions/16590650
 
  - Jonathan M Davis
 
 Given that he was working with pure ASCII, he should be able to cast
 the array to byte[] and sort it, but I haven't tried.

Sure, you can cast char[] to ubyte[] and sort that if you know that the array
only holds pure ASCII. In fact, you can use std.string.representation to do it
- e.g.

auto ascii = str.representation;

and if str were mutable, then you could sort it. But that will only work if
the string only contains ASCII characters. Regardless, he wanted to know why
he couldn't sort char[], and I explained why - all strings are treated as
ranges of dchar, making it so that if their element type is char or wchar, so
they're not random access and thus can't be sorted.

 Also char[] isn't string.

Yes, string is aliased to immutable(string)[], but char[] is still a string
type, and what I said applies to all string types. In particular, arrays of
char or wchar are called narrow strings, because it's not guaranteed that
one of their code units is a full code point, unlike arrays of dchar. But all
arrays of char, wchar, or dchar are strings.

 Strings are immutable, and thus cannot be sorted in place.

string is immutable and thus couldn't be sorted regardless of whether narrow
strings were treated as ranges of dchar or not, but char[] is a string just as
much as immutable(char)[] is. It's just not string.

- Jonathan M Davis


Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread Francesco Cattoglio via Digitalmars-d-learn

On Monday, 12 May 2014 at 08:37:43 UTC, JR wrote:

What am I missing?


Error messages!
If your code is not compiled, you can't know whether it is valid 
or not.


I must say that since we have unittests, this is somewhat less 
relevant, but still...

One nice thing would be stripping the executable of unneeded code.
One trick I've seen done in a program which compiled some scripts 
to an intermediate language was zeroing the parts which are 
unused, then use some executable compressor.


Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Kagamin via Digitalmars-d-learn
AFAIK, addRoot is for memory allocated in GC heap, and addRange 
is for other types of memory, so you can't add non-gc memory as 
root (just a guess, see docs). I would allocate whole Args in GC 
heap and add is as root, yes, it would prevent collection until 
the root is removed. A better way would be to store Args in a 
linked list in the widget, this way it will be fully managed, and 
Args will live as long as the widget class instance references 
them without additional tinkering with GC.


Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn

On Monday, 12 May 2014 at 19:13:28 UTC, Kagamin wrote:
AFAIK, addRoot is for memory allocated in GC heap, and addRange 
is for other types of memory, so you can't add non-gc memory as 
root (just a guess, see docs). I would allocate whole Args in 
GC heap and add is as root, yes, it would prevent collection 
until the root is removed. A better way would be to store Args 
in a linked list in the widget, this way it will be fully 
managed, and Args will live as long as the widget class 
instance references them without additional tinkering with GC.


Ah yeah, i never thought, i could allocate Args on the GC heap.

I have to allocate it on the fly and not store it in the widget 
because there could be many. I'll have a fiddle.


Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread Kagamin via Digitalmars-d-learn
You can write a tool, which will construct an amalgamation build 
of your code.


Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Kagamin via Digitalmars-d-learn
Why many? I'd say, you typically have 0 subscriptions (label, 
textbox) per widget, seldom - 1 (button, combobox, checkbox).


Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Kagamin via Digitalmars-d-learn
combobox and checkbox usually don't require a subscription 
either. Only button requires a reaction from your code, 
everything else usually works on its own.


newbie question about variables in slices..

2014-05-12 Thread Kai via Digitalmars-d-learn
Hi I am trying to iterate over a mmfile (ubyte[]) and convert it 
to uint


void main(){
MmFile inn = new MmFile(mmData.dat);
ubyte[] arr = cast(ubyte[])inn[];
for(ulong index = 0; indexarr.length; index+=4){
ulong stop = index+4;   
uint num  = littleEndianToNative!uint(arr[index..stop]);
}
if i try to compile this i get the following error:
Error: template std.bitmanip.littleEndianToNative cannot deduce 
function from argument types !(uint)(ubyte[])


but if change the last line to:
uint num  = littleEndianToNative!uint(arr[30..34]);

then it compiles and runs...

Am I doing something wrong with my variables index and stop?
cheers
Kai T


Re: newbie question about variables in slices..

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 20:12:41 +
Kai via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Hi I am trying to iterate over a mmfile (ubyte[]) and convert it
 to uint

 void main(){
   MmFile inn = new MmFile(mmData.dat);
   ubyte[] arr = cast(ubyte[])inn[];
   for(ulong index = 0; indexarr.length; index+=4){
   ulong stop = index+4;
   uint num  =
 littleEndianToNative!uint(arr[index..stop]); }
 if i try to compile this i get the following error:
 Error: template std.bitmanip.littleEndianToNative cannot deduce
 function from argument types !(uint)(ubyte[])

 but if change the last line to:
 uint num  = littleEndianToNative!uint(arr[30..34]);

 then it compiles and runs...

 Am I doing something wrong with my variables index and stop?
 cheers

The problem is that the compiler isn't smart enough to realize that
arr[index .. stop] is guaranteed to result in a array with a length of 4.

auto num = littleEndianToNative!uint(cast(ubyte[4])arr[index..stop]);

would work. On a side note, if you wanted to be safer, you should probably use
uint.sizeof everyewhere instead of 4. that would also make it easier to
convert it to a different integral type. Also, you should be using size_t, not
ulong for the indices. Array indices are size_t, and while that's ulong on a
64-bit system, it's uint on a 32-bit system, so your code won't compile on a
32-bit system.

- Jonathan M Davis


Re: Recommendation on option parsing

2014-05-12 Thread Chris Piker via Digitalmars-d-learn

On Saturday, 10 May 2014 at 11:59:03 UTC, Robert Schadek via
Digitalmars-d-learn wrote:
On 05/10/2014 01:09 AM, Chris Piker via Digitalmars-d-learn 
wrote:

Phobos' std.getopt is a bit spare for my taste, as there is
no builtin general help facility with word-wrapping.
...
--
Chris

please help to make this happen
https://github.com/D-Programming-Language/phobos/pull/2072


I'm not sure what you are asking for.  Would you like me to tryout
getoptEx?  If so, then sure I can do that, why not.  (Assuming I
can
figure out how to download your source file from github.)

If you are asking me to affect phobos, well, that's a little out
of my league for now.
--
Chris


Re: Recommendation on option parsing

2014-05-12 Thread Chris Piker via Digitalmars-d-learn

On Saturday, 10 May 2014 at 09:50:04 UTC, Jacob Carlborg wrote:

On 2014-05-10 01:09, Chris Piker wrote:

Phobos' std.getopt is a bit spare for my taste, as there is
no builtin general help facility with word-wrapping.
...


I'm using the one in Tango [1] with some additions [2]. It's a 
bit messy and I don't consider it stable, but it will 
automatically generate the help text. You can see some of it's 
uses here [3].


[1] https://github.com/SiegeLord/Tango-D2
[2] 
https://github.com/jacob-carlborg/mambo/tree/master/mambo/arguments
[3] 
https://github.com/jacob-carlborg/dstep/blob/master/dstep/driver/Application.d#L53


Thanks for the reference.  Just perusing your class structure
it looks like a well thought out module.  Unfortunatly this
also seems a heavy dependency to pull in, I have to use Tango
and then mombo on top of that.  Over the long haul that might
be the best answer, but I'm working on a rather small set of
programs for right now.
--
Chris


Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn

On Monday, 12 May 2014 at 20:03:46 UTC, Kagamin wrote:
Why many? I'd say, you typically have 0 subscriptions (label, 
textbox) per widget, seldom - 1 (button, combobox, checkbox).


There are many events that can be bound to on any widget.
https://github.com/nomad-software/tkd/blob/master/source/tkd/element/uielement.d#L328


Decoding HTML escape sequences

2014-05-12 Thread Hugo Florentino via Digitalmars-d-learn
Hi, I have some documents where some strings appears in HTML escape 
sequences in one of these forms:


\x3C\x53\x43\x52\x49\x50\x54\x20\x4C\x41\x4E\x47\x55\x41\x47\x45\x3D\x22\x4A\x61\x76\x61\x53\x63\x72\x69\x70\x74\x22\x3e

%3C%53%43%52%49%50%54%20%4C%41%4E%47%55%41%47%45%3D%22%4A%61%76%61%53%63%72%69%70%74%22%3e

And I would like to recode them to readable form:

SCRIPT LANGUAGE=Javascript

I tried something like this, using regular expressions and the uri 
module:



import std.stdio, std.file, std.encoding, std.string, std.regex, 
std.uri;


static auto re = regex(`(%[a-fA-F0-9]{2})`);

int main(in string[] args)
{
  if (args.length  2)
  {
writeln(Usage: unescape file1.htm  file2.htm);
return -1;
  }
  auto input = cast(Latin1String) read(args[1]);
  string buffer;
  transcode(input, buffer);

  string output;
  foreach(m; matchAll(buffer, re)) output ~= decode(m.hit);

  writeln(output);

  return 0;
}


Unfortunately it doesn't seem to work 100%.

I would appreciate any suggestion.

Regards, Hugo


Re: Recommendation on option parsing

2014-05-12 Thread Robert Schadek via Digitalmars-d-learn
On 05/12/2014 10:44 PM, Chris Piker via Digitalmars-d-learn wrote:
 On Saturday, 10 May 2014 at 11:59:03 UTC, Robert Schadek via
 Digitalmars-d-learn wrote:
 On 05/10/2014 01:09 AM, Chris Piker via Digitalmars-d-learn wrote:
 Phobos' std.getopt is a bit spare for my taste, as there is
 no builtin general help facility with word-wrapping.
 ...
 -- 
 Chris
 please help to make this happen
 https://github.com/D-Programming-Language/phobos/pull/2072

 I'm not sure what you are asking for.  Would you like me to tryout
 getoptEx?  If so, then sure I can do that, why not.  (Assuming I
 can
 figure out how to download your source file from github.)
yes please test it



DFL is the best UIcontrols for D,compare it to dwt, tkd,dtk,dlangui,anchovy......

2014-05-12 Thread FrankLike via Digitalmars-d-learn
1.DFL's Memory Usage is the least than other. winsamp.exe is 
2.1M,DFL's example's exe is 2.7M.
2.The size of DFL's example's exe files is the least than other, 
and only a single file.

3.DFL's source code is the most easy to understand.

Although DFL not use on Linux or Mac os X,it's easy to do for 
high level Software Engineer.


Now D need a simple ,quickly,easy to study UI Controls for D to 
develop.


Frank






Re: Decoding HTML escape sequences

2014-05-12 Thread Adam D. Ruppe via Digitalmars-d-learn
You should use decodeComponent instead of decode in your matchAll 
loop.


IMO encodeComponent and decodeComponent are the only two useful 
uri encode functions (btw same in JS, use decodeURIComponent 
instead of the other functions). The other ones have weird rules.


Re: why can't I call const methods on shared objects?

2014-05-12 Thread Vlad Levenfeld via Digitalmars-d-learn

@FreeSlave  John Colvin

Yes, I see your point. I could still get tearing on a read. So, 
in the case of methods that I believe are safe (e.g. 1-line 
@property getters) I'll just write a shared variadic function 
template that uses (cast()this).foo(args) to forward to the 
non-shared method... and in less-safe cases, I can just add some 
synchronization code to the shared version.
Or maybe its safer to do it the other way around, i.e. 
(cast(shared)this) and forward from non-shared to shared? There's 
not yet any established best practices for this, are there?


Re: Recommendation on option parsing

2014-05-12 Thread Chris Piker via Digitalmars-d-learn

On Monday, 12 May 2014 at 23:11:57 UTC, Robert Schadek via
Digitalmars-d-learn wrote:

Chris

please help to make this happen
https://github.com/D-Programming-Language/phobos/pull/2072


I'm not sure what you are asking for.  Would you like me to 
tryout getoptEx?

yes please test it


Okay, I replaced the std.getopt that came with dmd with your
version.  My code compiles, but of course it doesn't link
against the old libphobos.so.  I'm a complete newbe to D and
am not ready to build a new version of libphobos.so, that's
for the library maintainers to do, which is not a job I'm ready
to sign up for yet.  Right now I'm just trying to get my own
project done, and so far D's standard library is being a HUGE
impediment.  It's like programming against bare glibc all over
again when I hoped it would be a little more like the Python
standard libary.

Just being a random developer my opinon isn't that important
but, for what it's worth, I think an expanded option handling
feature should be implemented in a separate module.  That way
users can try it out without affecting their existing libphobos.

I like your enthusiasm.  If you have any modules that don't
require me to rebuild libphobos, I'll be happy to give them a
whirl.  Thank's for responding to my inquiry.

--
Chris


naming a variable at runtime

2014-05-12 Thread InfinityPlusB via Digitalmars-d-learn

Hi clever people

I'm trying to do something which I thought would be easy.
Read a file in, and for every row, create a array.

I want to be able to name the rows, as they are built.
So when row 1 is read in I get
int[] bob_1 = new int[0];
when the second row is read in, I get
int[] bob_2 = new int[0];

So at the end of running my program I effectively want bob_1, 
bob_2 and bob_3.

And then I can do something more interesting with them ...

I realise this is now slightly beyond my if-then-else 
capabilities, and was wondering if I could get some direction.


Thanks
B


The contents of /home/bob/test.csv
-1, -1, 1, -1, -1
-1, 1, 1, 1, -1
1, -1, -1, 1, -1

My Program
#!/usr/bin/rdmd
import std.stdio;
import std.array;
import std.conv;
import std.string;

void main()
{
  string inputFile = /home/bob/test.csv;
//  string inputFile = -1, -1, 1, -1, -1\n-1, 1, 1, 1, -1\n1, 
-1, -1, 1, -1\r\n;

  auto readInFile = File(inputFile);
  int count = 0;
  foreach(line; readInFile.byLine())
  {
int[] bob = new int[0];
// int[] bob_NUMBER_ME = new int[0];
foreach(item;line.split(,))
{
  writeln(strip(item));
  bob ~=  to!int(strip(item));
}
writeln(bob);
writefln(Line number %d, count);
count++;
  }
  writeln(Done);
}


Re: naming a variable at runtime

2014-05-12 Thread safety0ff via Digitalmars-d-learn
You should look into associative arrays ( 
http://dlang.org/hash-map .)


Example:

import std.stdio;

void main()
{
int[][string] mybobs;
mybobs[bob_1] = [-1, -1, 1, -1, -1];
mybobs[bob_2] = [-1, 1, 1, 1, -1];
mybobs[bob_3] = [-1, 1, 1, 1, -1];
writeln(mybobs);
}


Re: naming a variable at runtime

2014-05-12 Thread InfinityPlusB via Digitalmars-d-learn

On Tuesday, 13 May 2014 at 03:54:33 UTC, safety0ff wrote:
You should look into associative arrays ( 
http://dlang.org/hash-map .)


Example:

import std.stdio;

void main()
{
int[][string] mybobs;
mybobs[bob_1] = [-1, -1, 1, -1, -1];
mybobs[bob_2] = [-1, 1, 1, 1, -1];
mybobs[bob_3] = [-1, 1, 1, 1, -1];
writeln(mybobs);
}


Thanks for the quick reply, I'll look into that.

My issue is (which I didn't explain clearly, sorry) how do I do 
it with an unknown number of lines?

So my example has 3 lines. What if it had 300? or 3000?
Basically so I can run the same piece of code for any size file, 
and it will create a new named array for each line.
So I assume(?) I have to do something that will name each of 
these arrays at runtime.


So,
for(x;1 ... n)
  bob_x = ...


Re: naming a variable at runtime

2014-05-12 Thread Ali Çehreli via Digitalmars-d-learn

On 05/12/2014 08:47 PM, InfinityPlusB wrote:

 I want to be able to name the rows, as they are built.

First, no, you cannot name variables at run time because variables are 
concepts of source code; they don't exist in the compiled program.


 So when row 1 is read in I get
 int[] bob_1 = new int[0];
 when the second row is read in, I get
 int[] bob_2 = new int[0];

Well, it looks like a bob array. :) How about naming those rows as 
bob[0], bob[1], etc.


 So at the end of running my program I effectively want bob_1, bob_2 and
 bob_3.

Would zero-indexing work?

 And then I can do something more interesting with them ...

 I realise this is now slightly beyond my if-then-else capabilities, and
 was wondering if I could get some direction.

I had used the same naming scheme as a segway to my arrays chapter:

  http://ddili.org/ders/d.en/arrays.html

 The contents of /home/bob/test.csv
 -1, -1, 1, -1, -1
 -1, 1, 1, 1, -1
 1, -1, -1, 1, -1

 My Program
 #!/usr/bin/rdmd
 import std.stdio;
 import std.array;
 import std.conv;
 import std.string;

 void main()
 {
string inputFile = /home/bob/test.csv;
 //  string inputFile = -1, -1, 1, -1, -1\n-1, 1, 1, 1, -1\n1, -1, -1,
 1, -1\r\n;
auto readInFile = File(inputFile);
int count = 0;
foreach(line; readInFile.byLine())
{
  int[] bob = new int[0];
 // int[] bob_NUMBER_ME = new int[0];
  foreach(item;line.split(,))
  {
writeln(strip(item));
bob ~=  to!int(strip(item));
  }
  writeln(bob);
  writefln(Line number %d, count);
  count++;
}
writeln(Done);
 }

Here is the inner loop with minimal changes to your program:

   int[][] bob;// == Array of arrays

   foreach(line; readInFile.byLine())
   {
   int[] row;  // == Make a new row

   foreach(item;line.split(,))
   {
   writeln(strip(item));
   row ~= to!int(strip(item));
   }

   bob ~= row; // == Add the row

 writefln(Line number %d, count);
 count++;
   }
   writeln(bob);

Ali



Re: naming a variable at runtime

2014-05-12 Thread InfinityPlusB via Digitalmars-d-learn

On Tuesday, 13 May 2014 at 04:26:04 UTC, Ali Çehreli wrote:

On 05/12/2014 08:47 PM, InfinityPlusB wrote:

 I want to be able to name the rows, as they are built.

First, no, you cannot name variables at run time because 
variables are concepts of source code; they don't exist in the 
compiled program.


That's good to know, I'll stop trying to make that happen. :P


Here is the inner loop with minimal changes to your program:

   int[][] bob;// == Array of arrays

   foreach(line; readInFile.byLine())
   {
   int[] row;  // == Make a new row


yup, that will work.
If I wasn't hell bent on naming variables, I probably would have 
figured this out. :P


Thanks.



Re: Messy code in console

2014-05-12 Thread IceNature via Digitalmars-d-learn
I've just thought of a problem. Others who uses my program on their computers 
needs to change their setting. It is a bit troublesome.

On 2014年5月11日 格林尼治标准时间+0800下午3时43分41秒, FrankLike via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:
On Sunday, 11 May 2014 at 06:35:26 UTC, IceNature via 
Digitalmars-d-learn wrote:
 Thank you for your help. But if I change the default console 
 encoding,will it affect other programs,making other console 
 program show messy code?

Don't  affect,and you must set the font to  a  unicode font ,such 
as Lucida.


.