Re: Command Line Application in D

2014-08-05 Thread Mike James via Digitalmars-d-learn

On Monday, 4 August 2014 at 22:03:24 UTC, TJB wrote:
On Monday, 4 August 2014 at 21:58:09 UTC, maarten van damme via 
Digitalmars-d-learn wrote:

I am a little bit confused as to what you want.
There is a command line example at dlang.org, and there exists 
a program

(rdmd) that compiles several D files and runs them.
http://dlang.org/rdmd.html


Sorry. I wasn't very clear. Say I want to find all of the files 
that have a certain extension within a directory and process 
them somehow at the command line. How could I do that?


Have a look at the function dirEntries in std.file.

regards,

-mike-


Re: building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn
edit : btw, I understand how to build an app that conscists out 
of a few source files, I'd just do 'dmd file1.d file2.d' I 
amtalking here about the situation where that's unpractical 
because of the amount and folder structure.





Re: building a D app with multiple source files

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 07:27:18 UTC, nikki wrote:

Hello, I am completely new to D and have been paying around with
the tutorials, some docs and little test programs.

Now I want to try and use https://github.com/elvisxzhou/artemisd
for little gamedev experiment but I am running into build 
issues.

That project doesn't have a Makefile in the repo, and I am on
linux so I need to build it on the terminal,

I've read about rdmd (and tried it without success) and found a
few 'general' usage Makefiles, can't get any to just work when I
type 'make all'.

in the repo I linked to (artemisd) there are dozens of source
files in various folders, and an example i have to compile at 
the

same time I think.

could someone show me how it's done ?


What issues have you had with rdmd?

The library seems to have a package.json file, so you could also 
try dub:

http://code.dlang.org/download


building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn

Hello, I am completely new to D and have been paying around with
the tutorials, some docs and little test programs.

Now I want to try and use https://github.com/elvisxzhou/artemisd
for little gamedev experiment but I am running into build issues.
That project doesn't have a Makefile in the repo, and I am on
linux so I need to build it on the terminal,

I've read about rdmd (and tried it without success) and found a
few 'general' usage Makefiles, can't get any to just work when I
type 'make all'.

in the repo I linked to (artemisd) there are dozens of source
files in various folders, and an example i have to compile at the
same time I think.

could someone show me how it's done ?


Re: spawnProcess command-line arguments help

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
When I use the spawnProcess function in std.process, the 
command line arguments that I provide to the function seem to 
get quoted. Is there a way to tell the spawnProcess function 
that I want the command line arguments to be non-quoted?


Example:
spawnProcess([SomePath\\Test.exe], [-silent]);


I assume you mean:

spawnProcess([SomePath\\Test.exe, -silent]);

and the command line becomes: SomePath\Test.exe -silent 
(with the quotes exaclt like shown).


Unfortunately (for some strange reason), the spawned process 
only responds to non-quoted arguments passed through the 
command line. So the command line should be exactly: 
SomePath\Test.exe -silent


Is there any way to achieve this?


No, there currently is no way to achieve this using spawnProcess. 
You could have better luck using spawnShell instead.


I would consider such behavior a bug in the application you're 
trying to run, as it does not perform command-line parsing 
according to convention (CommandLineToArgvW).


It would be possible to enhance spawnProcess and family to only 
quote arguments which need to be quoted, which would fix this 
particular case, however of course that can't address every 
program which parses its command line in a non-standard way.


Re: building a D app with multiple source files

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 07:29:46 UTC, nikki wrote:
edit : btw, I understand how to build an app that conscists out 
of a few source files, I'd just do 'dmd file1.d file2.d' I 
amtalking here about the situation where that's unpractical 
because of the amount and folder structure.


With rdmd, simply run `rdmd --build-only mainfile.d` (mainfile.d 
being the file that contains the main function). Omit 
--build-only to build the program to a temporary directory, then 
run it.


Re: building a D app with multiple source files

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

On Tuesday, 5 August 2014 at 07:29:46 UTC, nikki wrote:
edit : btw, I understand how to build an app that conscists out 
of a few source files, I'd just do 'dmd file1.d file2.d' I 
amtalking here about the situation where that's unpractical 
because of the amount and folder structure.


You can take a look at the dub build tool to automate all this 
(as mentioned above). Dub works by compiling and linking 
everything together in your source folder. You specify the main 
entry point in a dub.json file. It's pretty easy to use and good 
for handling dependencies over the internet.


To compile things manually you can use rdmd to automatically 
parse the files that need compiling. When using rdmd you only 
need to specify the file that contains the main function to build 
everything around it. for example:


rdmd program.d

This will pull in all imports inside program.d and compile and 
link them too.


Re: spawnProcess command-line arguments help

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Monday, 4 August 2014 at 17:02:27 UTC, Peter Alexander wrote:

On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
When I use the spawnProcess function in std.process, the 
command line arguments that I provide to the function seem to 
get quoted.


I can't reproduce this on OS X with 2.066rc1 (args are 
unquoted).


Arguments on POSIX systems are passed to programs in a different 
way than on Windows. On POSIX, the arguments are passed as an 
array of zero-terminated strings (when a command is given as a 
string, a shell breaks it up into an argument array before 
running the program). On Windows, the arguments are passed as a 
string, and are parsed into an array by the executed program (or 
its language runtime). Although generally Windows programs use 
the OS function CommandLineToArgvW, they have no obligation to do 
so, and may implement their own algorithm.


Re: building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn




What issues have you had with rdmd?

The library seems to have a package.json file, so you could 
also try dub:

http://code.dlang.org/download



nikki@crunchbang:~/projects/d/artemisd$ rdmd example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]


nikki@crunchbang:~/projects/d/artemisd$ rdmd --makedepend 
example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]




Re: building a D app with multiple source files

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 07:43:56 UTC, nikki wrote:




What issues have you had with rdmd?

The library seems to have a package.json file, so you could 
also try dub:

http://code.dlang.org/download



nikki@crunchbang:~/projects/d/artemisd$ rdmd 
example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]


nikki@crunchbang:~/projects/d/artemisd$ rdmd --makedepend 
example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]


The search path does not include the artemisd package.

Try: cd ..  rdmd artemisd/example/source/app.d
Or : rdmd -I.. example/source/app.d


Re: building a D app with multiple source files

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 5 August 2014 at 07:46:05 UTC, Vladimir Panteleev 
wrote:

On Tuesday, 5 August 2014 at 07:43:56 UTC, nikki wrote:




What issues have you had with rdmd?

The library seems to have a package.json file, so you could 
also try dub:

http://code.dlang.org/download



nikki@crunchbang:~/projects/d/artemisd$ rdmd 
example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]


nikki@crunchbang:~/projects/d/artemisd$ rdmd --makedepend 
example/source/app.d
example/source/app.d(5): Error: module all is in file 
'artemisd/all.d' which cannot be read

import path[0] = example/source
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: [dmd, -v, -o-, example/source/app.d, 
-Iexample/source]


The search path does not include the artemisd package.

Try: cd ..  rdmd artemisd/example/source/app.d
Or : rdmd -I.. example/source/app.d


Correction:

rdmd -Isource example/source/app.d


Re: building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn

Correction:

rdmd -Isource example/source/app.d


that one worked, woohoo thanks.

what did the -Isource do? it's not in the 'rdmd --help'


Re: building a D app with multiple source files

2014-08-05 Thread Vladimir Panteleev via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 07:51:53 UTC, nikki wrote:

Correction:

rdmd -Isource example/source/app.d


that one worked, woohoo thanks.

what did the -Isource do? it's not in the 'rdmd --help'


You'll find it in dmd's --help. It adds the source directory to 
the search path, the list of directories where the compiler looks 
for imported modules.


Re: building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn
On Tuesday, 5 August 2014 at 07:57:57 UTC, Vladimir Panteleev 
wrote:

On Tuesday, 5 August 2014 at 07:51:53 UTC, nikki wrote:

Correction:

rdmd -Isource example/source/app.d


that one worked, woohoo thanks.

what did the -Isource do? it's not in the 'rdmd --help'


You'll find it in dmd's --help. It adds the source directory 
to the search path, the list of directories where the compiler 
looks for imported modules.


edit: couldn't find that flag in dmd --help (only -Ipath), 
atleast I know what it does now, hope I'll remember..

thanks a lot though @ great helpful community


Re: Help with porting grammar from PEGjs to D for dustjs project!

2014-08-05 Thread Uranuz via Digitalmars-d-learn
Different formats and also different languages. I don't see how 
you
can compare a parse tree that's a D object and another tree 
made by

dustjs: you never see the AST produced by dust, you only see the
resulting JS code.


Yes. That's a point. Thanks for all the explanations. I'll try to 
make something useful of it.


Re: building a D app with multiple source files

2014-08-05 Thread Mike Parker via Digitalmars-d-learn

On 8/5/2014 5:06 PM, nikki wrote:

On Tuesday, 5 August 2014 at 07:57:57 UTC, Vladimir Panteleev wrote:

On Tuesday, 5 August 2014 at 07:51:53 UTC, nikki wrote:

Correction:

rdmd -Isource example/source/app.d


that one worked, woohoo thanks.

what did the -Isource do? it's not in the 'rdmd --help'


You'll find it in dmd's --help. It adds the source directory to the
search path, the list of directories where the compiler looks for
imported modules.


edit: couldn't find that flag in dmd --help (only -Ipath), atleast I
know what it does now, hope I'll remember..
thanks a lot though @ great helpful community


The switch itself is -I, not -Ipath. 'path' indicates a parameter for 
which you need to substitute something, in this case a directory path. 
It should be the root folder for the source modules you want to add to 
the search path. In this case, for artemisd, the source files are in the 
'source' directory, so -Isource is what you pass to dmd. If the 
directory were named 'foo' instead, you would pass -Ifoo.


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



Re: Threadpools, difference between DMD and LDC

2014-08-05 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2014-08-04 at 18:34 +, Dicebot via Digitalmars-d-learn
wrote:
[…]
 Well it is a territory not completely alien to me either ;) I am 
 less aware of academia research on topic though, just happen to 
 work in industry where it matters.

I have been out of academia now for 14 years, but tracking the various
lists and blogs, not to mention SuperComputing conferences, there is
very little new stuff, the last 10 has been about improving. The one new
thing is though GPGPU, which started out as an interesting side show but
has now come front and centre for data parallelism.

 I think initial spread of multi-threading approach has happened 
 because it was so temptingly easy - no need to worry about 
 actually modelling the concurrency execution flow, blocking I/O 
 or scheduling; just write the code as usual and OS will take care 
 of it. But there is no place for magic in programming world in it 
 has fallen hard once network services started to scale.

Threads are infrastructure just like stack and heap, very, very, very
few people actually worry about and manage these resources explicitly,
most just leave the run time system to handle it. OK so the usual GC
argument can be plopped in here, let's not bother though as we've been
through it three times this quarter :-)

 Right now is the glorious moment when engineers are finally 
 starting to appreciate how previous academia research can help 
 them solve practical issues and all this good stuff goes 
 mainstream :)

Actors are mid 1960s, dataflow early 1970s, CSP mid 1970s, it has taken
the explicit shared-memory multithreading in applications fiasco a long
time to pass. I can think of some applications which are effectively
operating systems and so need all the best shared-memory multithreading
techniques (I was involved in one 1999–2004), but most applications
people should be using actors, dataflow, CSP or data parallelism as
their applications model supported by library frameworks/infrastructure.

[…]
 Doubt programming / engineering community will ever accept 
 research that states that choosing architecture can be done on 
 pure theoretical basis :) It simply contradicts too much all 
 daily experience which says that every concurrent application has 
 some unique traits to consider and only profiling can rule them 
 all.

Most solutions to problems or subproblems can be slotted into one of
actors, dataflow, pipeline, MVC, data parallelism, event loop for the
main picture. If tweaking is needed, profiling and small localized
tinkerings can do the trick. I have yet to find many cases in my
(computation oriented) world where that is needed. Maybe in an I/O world
there are different constraints.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: building a D app with multiple source files

2014-08-05 Thread nikki via Digitalmars-d-learn


The switch itself is -I, not -Ipath. 'path' indicates a 
parameter for which you need to substitute something, in this 
case a directory path. It should be the root folder for the 
source modules you want to add to the search path. In this 
case, for artemisd, the source files are in the 'source' 
directory, so -Isource is what you pass to dmd. If the 
directory were named 'foo' instead, you would pass -Ifoo.


aha! that would've bitten me in the future, now I get it, thanks.


Re: Help with porting grammar from PEGjs to D for dustjs project!

2014-08-05 Thread Uranuz via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 08:13:25 UTC, Uranuz wrote:
Different formats and also different languages. I don't see 
how you
can compare a parse tree that's a D object and another tree 
made by
dustjs: you never see the AST produced by dust, you only see 
the

resulting JS code.


Yes. That's a point. Thanks for all the explanations. I'll try 
to make something useful of it.


Is there multiline comments available inside PEGGED template?
As far as I understand inline comments are set via # sign.


Re: How to easily construct objects with multi-param constructors from lazy ranges?

2014-08-05 Thread Rene Zwanenburg via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 15:13:37 UTC, Rene Zwanenburg wrote:

clean looking code to parse Wavefont OBJ files [0].


[0] http://en.wikipedia.org/wiki/Wavefront_.obj_file


Re: unittest affects next unittest

2014-08-05 Thread sigod via Digitalmars-d-learn
On Saturday, 2 August 2014 at 06:46:04 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:

On Fri, 01 Aug 2014 23:09:37 +
sigod via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



Code: http://dpaste.dzfl.pl/51bd62138854
(It was reduced by DustMite.)

Have I missed something about structs? Or this simply a bug?


Don't do this with a member variable:

private Node * _root = new Node();

Directly initializing it like that sets the init value for that 
struct, and
that means that every struct of that type will have exactly the 
same value for
_root, so they will all share the same root rather than having 
different

copies. You need to initialize _root in the constructor.

- Jonathan M Davis


So, it's a static initialization? Documentation didn't mention 
it. (In class' section only 2 sentences about it and none in 
struct's section.)


This is different from many languages (C#, Java... don't know 
about C and C++). What was the reason to make this initialization 
static?


How to easily construct objects with multi-param constructors from lazy ranges?

2014-08-05 Thread Rene Zwanenburg via Digitalmars-d-learn
Here's something which I've run into a few times now without 
finding a pretty solution. When parsing a text file using lazy 
ranges and algorithms you will have to convert a string range to 
an object at some point.


In this particular case I was curious to see if I could write 
clean looking code to parse Wavefont OBJ files [0]. A simple OBJ 
file could look like this:


v 0 1 0
v 1 1 0
v 1 0 0
v 0 0 0

vn 0 0 1

f 3//1 2//1 1//1
f 3//1 4//1 2//1

Now, to parse the vertex positions (the lines beginning with 'v') 
I use:


struct vec3
{
  float[3] v;

  this(float x, float y, float z){ ... }
}

void foo()
{

auto lines =
  File(SomeFile.obj)
  .byLine
  .map!(a = a.strip)
  .filter!(a = !a.empty)
  .filter!(a = !a.startsWith('#'));

auto vertices =
  lines
  .filter!(a = a.startsWith('v'))
  .map!(a = a.splitter)
  // Now what?
}

What is a nice way to convert the forward range [v, 0, 1, 
0] to a vec3, without unneccessary allocations? Creating a 
constructor function like


vec3 parseVec(R)(R range)
{
  vec3 v;
  v.v[0] = range.front.to!float;
  range.popFront();
  // Etc.
  return v;
}

seems terribly awkward to me.

Some range which takes an at compile time known number of 
elements from an input range and provides opIndex seems perfect 
to me, but as far as I know there's no such thing in Phobos. It 
would allow


auto vertices =
lines
.filter!(a = a.startsWith('v'))
.map!(a = a.splitter)
.map!(a = a.staticChunks!4)
.map!(a = vec3(a[1].to!float, a[2].to!float, a[3].to!float));

without heap allocations. Anyone know if Phobos has something 
like this? Or another approach?


If not I'm willing to create something like staticChunks if 
there's interest to add it to std.range.


Re: Preferred program config file format and parsing library?

2014-08-05 Thread Baz via Digitalmars-d-learn

On Saturday, 2 August 2014 at 12:42:00 UTC, Gary Willoughby wrote:
What is the preferred format people here use for program config 
files? Json, Xml, ini, etc?


Also what libraries exist to parse the preferred format?


Preffered one is the one a RTL(run time library) or a VCL(visual 
component library) uses.
I hate those using markups, like xml. ugly, hard to edit eg in 
notepad.

I hate ini. ini is kind of a beginner format. ini is ridiculous.

A good config file format has to
- be editable.
- be strongly used in the lang. standard library: the one used 
cause it's good.
- not ini. ini files = child happy to discover he can save and 
load settings.
- convertible: even if it's a proprietary format it must be 
convertible to json or xml or yaml (or ini for the children). 
https://en.wikipedia.org/wiki/Marshalling_(computer_science).




Re: building a D app with multiple source files

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

On Tuesday, 5 August 2014 at 08:06:57 UTC, nikki wrote:
edit: couldn't find that flag in dmd --help (only -Ipath), 
atleast I know what it does now, hope I'll remember..

thanks a lot though @ great helpful community


Remember rdmd is just a program to help collect and organise 
parameters. It still passes everything to dmd. In fact if you use 
the --chatty option with rdmd it will show you everything it is 
doing including what it is passing to dmd.


Dub failing to detect Shared Libraries

2014-08-05 Thread Rishub Nagpal via Digitalmars-d-learn
I am porting DerelictBGFX to linux, but I am having some 
problems. When I run the dub command in my example directory, I 
get the following error :


derelict.util.exception.SharedLibLoadException@../../../.dub/packages/derelict-util-1.0.2/source/derelict/util/exception.d(35): 
Failed to load one or more shared libraries:
	libbgfx-shared-libRelease.so - libbgfx-shared-libRelease.so: 
cannot open shared object file: No such file or directory
	libbgfx-shared-libDebug.so - libbgfx-shared-libDebug.so: cannot 
open shared object file: No such file or directory



Here is the file I edited to detect those libaries : 
https://github.com/shrub77/DerelictBgfx/blob/master/source/derelict/bgfx/bgfx.d#L55


Here is the dub.json :
{
name: 00-helloworld,

sourcePaths: [.],
targetType: executable,
mainSourceFile: helloworld.d,

dependencies:
{
gfm:sdl2: =1.1.4,
derelict-bgfx: {path: ../../, version: ~master}
}
}

Where should I put the *.so files so they can be detected 
properly by dub?


Rishub



Re: unittest affects next unittest

2014-08-05 Thread via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 15:39:55 UTC, sigod wrote:
On Saturday, 2 August 2014 at 06:46:04 UTC, Jonathan M Davis 
via Digitalmars-d-learn wrote:

On Fri, 01 Aug 2014 23:09:37 +
sigod via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



Code: http://dpaste.dzfl.pl/51bd62138854
(It was reduced by DustMite.)

Have I missed something about structs? Or this simply a bug?


Don't do this with a member variable:

private Node * _root = new Node();

Directly initializing it like that sets the init value for 
that struct, and
that means that every struct of that type will have exactly 
the same value for
_root, so they will all share the same root rather than having 
different

copies. You need to initialize _root in the constructor.

- Jonathan M Davis


So, it's a static initialization? Documentation didn't mention 
it. (In class' section only 2 sentences about it and none in 
struct's section.)


This is different from many languages (C#, Java... don't know 
about C and C++). What was the reason to make this 
initialization static?


It's a consequence of the fact that every type in D has a default 
initializer which is known at compile time.


Re: Help with porting grammar from PEGjs to D for dustjs project!

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
 Is there multiline comments available inside PEGGED template?
 As far as I understand inline comments are set via # sign.

No, no multiline comment. That's based on the original PEG grammar,
which allows only #-comments.


Re: Preferred program config file format and parsing library?

2014-08-05 Thread Baz via Digitalmars-d-learn
https://en.wikipedia.org/wiki/Marshalling_(computer_science) 
bla.

damn it.



static array in templated struct/class

2014-08-05 Thread ddos via Digitalmars-d-learn

alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

class TVector(T,int n)
{
T[n] val;
...

TVector as class does work as expected, as a struct i get the 
following errors, but why?


struct Vector.TVector!(float, 4).TVector no size yet for forward 
reference
struct Vector.TVector!(float, 3).TVector no size yet for forward 
reference


Re: static array in templated struct/class

2014-08-05 Thread via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:

alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

class TVector(T,int n)
{
T[n] val;
...

TVector as class does work as expected, as a struct i get the 
following errors, but why?


struct Vector.TVector!(float, 4).TVector no size yet for 
forward reference
struct Vector.TVector!(float, 3).TVector no size yet for 
forward reference


Can you show the complete code? I cannot reproduce this with 
either latest DMD git, DMD 2.065, or LDC 0.13.0:


alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

struct TVector(T,int n)
{
T[n] val;
}

Vec3f a;
Vec4f b;


Re: static array in templated struct/class

2014-08-05 Thread Daniel Gibson via Digitalmars-d-learn

Am 05.08.2014 21:13, schrieb Marc Schütz schue...@gmx.net:

On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:

alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

class TVector(T,int n)
{
T[n] val;
...

TVector as class does work as expected, as a struct i get the
following errors, but why?

struct Vector.TVector!(float, 4).TVector no size yet for forward
reference
struct Vector.TVector!(float, 3).TVector no size yet for forward
reference


Can you show the complete code? I cannot reproduce this with either
latest DMD git, DMD 2.065, or LDC 0.13.0:

 alias Vec4f = TVector!(float,4);
 alias Vec3f = TVector!(float,3);

 struct TVector(T,int n)
 {
 T[n] val;
 }

 Vec3f a;
 Vec4f b;


struct vs class?


Re: static array in templated struct/class

2014-08-05 Thread ddos via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 19:13:31 UTC, Marc Schütz wrote:

On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:

alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

class TVector(T,int n)
{
T[n] val;
...

TVector as class does work as expected, as a struct i get the 
following errors, but why?


struct Vector.TVector!(float, 4).TVector no size yet for 
forward reference
struct Vector.TVector!(float, 3).TVector no size yet for 
forward reference


Can you show the complete code? I cannot reproduce this with 
either latest DMD git, DMD 2.065, or LDC 0.13.0:


alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

struct TVector(T,int n)
{
T[n] val;
}

Vec3f a;
Vec4f b;


http://pastebin.com/34sbffSa
thx for your help :) !
i use DMD 2.065 btw


Re: How to easily construct objects with multi-param constructors from lazy ranges?

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
 Some range which takes an at compile time known number of elements from an
 input range and provides opIndex seems perfect to me, but as far as I know
 there's no such thing in Phobos.

There is chunks:

http://dlang.org/phobos/std_range.html#chunks


Re: static array in templated struct/class

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
 http://pastebin.com/34sbffSa

Your problem comes from lengthSquared:

public auto lengthSquared = function () = val.reduce!((a,b) = a + b*b);

That's an unusual way to define a method. Any reason why you are using
a pointer to a function as a member? Do you need to be able to
redefine it at runtime?

I guess that in this case, the compiler cannot determine its return
type and/or its size?
I'd use:

public auto lengthSquared () { return val.reduce!((a,b) = a + b*b);}


Re: static array in templated struct/class

2014-08-05 Thread ddos via Digitalmars-d-learn
i wasn't intentionally creating a functionpointer, i just liked 
the syntax x3 ... but i guess i should read into it now :)

thx for you help !

On Tuesday, 5 August 2014 at 19:51:33 UTC, Philippe Sigaud via 
Digitalmars-d-learn wrote:

http://pastebin.com/34sbffSa


Your problem comes from lengthSquared:

public auto lengthSquared = function () = val.reduce!((a,b) = 
a + b*b);


That's an unusual way to define a method. Any reason why you 
are using

a pointer to a function as a member? Do you need to be able to
redefine it at runtime?

I guess that in this case, the compiler cannot determine its 
return

type and/or its size?
I'd use:

public auto lengthSquared () { return val.reduce!((a,b) = a + 
b*b);}




Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn

I'd have thought that this would work:

struct A
{
int[] i;
B b;

struct B
{
void foo() { i ~= 1;}
}
}

void main()
{
A a;
a.b.foo();
}

But the compiler tells me 'need this for i of type int[]'.
Is there any way I can gain access on i inside B?


Re: Haskell calling D code through the FFI

2014-08-05 Thread David Soria Parra via Digitalmars-d-learn

On Monday, 4 August 2014 at 20:48:09 UTC, Jon wrote:

For reasons I don't completely understand, you also need a fake 
main function, dummy.d:


void main(){}



Note that this is not necessary if you compile with -lib e.g.:

  dmd -lib -oflibtest.a test.d

and then

  ghc Main.hs --make -omain libtest.a

I don't have gdc or ldc installed but as far as I know ldc has a 
-lib flag as well.


Re: Inner struct accessing host member

2014-08-05 Thread Martijn Pot via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 20:32:08 UTC, Philippe Sigaud wrote:

I'd have thought that this would work:

struct A
{
int[] i;
B b;

struct B
{
void foo() { i ~= 1;}
}
}

void main()
{
A a;
a.b.foo();
}

But the compiler tells me 'need this for i of type int[]'.
Is there any way I can gain access on i inside B?


I know I've read this in TDPL, but don't recall enough.

Does this help : 
http://www.digitalmars.com/d/archives/digitalmars/D/learn/Nested_struct_member_has_no_access_to_the_enclosing_class_data_38294.html 
?


Re: Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
On Tue, Aug 5, 2014 at 11:37 PM, Martijn Pot via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 Does this help :
 http://www.digitalmars.com/d/archives/digitalmars/D/learn/Nested_struct_member_has_no_access_to_the_enclosing_class_data_38294.html

Yes, that helps: that explains why it does not wor :).
I changed my code to use classes. It's a bit less handy, but it works.


Re: Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
 why it does not wor :).

why it does not *work*, of course. Sigh.


Re: Command Line Application in D

2014-08-05 Thread TJB via Digitalmars-d-learn

This is exactly what I was thinking.  Thanks so much for your
help!

TJB

Just a little something I made for you. Untested of course. But 
takes an argument from cli, which is a glob. Foreach file under 
current working directory, if its a file write out processing.


(I gave std.stdio an alias because std.file and std.stdio 
conflict for some symbols)


import std.file;
import stdio = std.stdio;

void main(string[] args) {
if (args.length == 2) {
foreach(entry; dirEntries(., args[1], SpanMode.Depth)) {
if (isDir(entry.name)) {
} else if (isFile(entry.name)) {
stdio.writeln(Processing  ~ entry.name);
}
}
} else {
stdio.writeln(Arguments: glob);
}
}


Re: Inner struct accessing host member

2014-08-05 Thread abanstadya via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 20:32:08 UTC, Philippe Sigaud wrote:

I'd have thought that this would work:

struct A
{
int[] i;
B b;

struct B
{
void foo() { i ~= 1;}
}
}

void main()
{
A a;
a.b.foo();
}

But the compiler tells me 'need this for i of type int[]'.
Is there any way I can gain access on i inside B?


programming Q, either youra newb or not, should rather be posted 
to 'http://forum.dlang.org/group/digitalmars.D.learn'. Your post 
appears on 'http://forum.dlang.org/group/digitalmars.D' which is 
more related to the lang. design rather to programming Q. Take 
care next time bro.




Re: Haskell calling D code through the FFI

2014-08-05 Thread Jon via Digitalmars-d-learn
Oh great thank you.  I think that might solve the majority of the 
confusion I was having.  One thing I can't figure out though, is 
getting garbage collection to work as expected.  If I have a 
function that allocates a pointer to a struct using new, I get an 
error on linking _dAlloc... not found.  But maybe compiling as a 
lib will solve this too.


On Tuesday, 5 August 2014 at 21:28:08 UTC, David Soria Parra 
wrote:

On Monday, 4 August 2014 at 20:48:09 UTC, Jon wrote:

For reasons I don't completely understand, you also need a 
fake main function, dummy.d:


   void main(){}



Note that this is not necessary if you compile with -lib e.g.:

  dmd -lib -oflibtest.a test.d

and then

  ghc Main.hs --make -omain libtest.a

I don't have gdc or ldc installed but as far as I know ldc has 
a -lib flag as well.




Re: Declaring run time variables

2014-08-05 Thread splatterdash via Digitalmars-d-learn

On Monday, 4 August 2014 at 22:45:15 UTC, anonymous wrote:

On Monday, 4 August 2014 at 22:18:24 UTC, splatterdash wrote:
Indeed I do. I'm not sure which type I should use for the 
common base type, though. MyFileReader is a templated class, 
so using it plainly did not work. I also tried 
`InputRange!string` to no avail despite `MyFileReader` 
implementing the three InputRange requirement (popFront(), 
front, and empty).


Any ideas on what I should as the class?


Let MyFileReader implement an interface that has the operations
you need. That interface can be std.range.InputRange!string, or
you can define your own.

Note that a type is an input range when it has the input range
primitives (front, popFront, empty), but it's only a
std.range.InputRange!T when it implements the interface in the
OOP sense: class C : InputRange!E {...}.

Phobos generally doesn't use InputRange, but templatizes
everything. You can go that way, too, and move the foreach loop
to a templated function:

void main()
{
 File f = File(input_file)
 // detect gzip ...
 if (isGzip)
 doThings(new MyFileReader!GzipIterator(f));
 else
 doThings(new MyFileReader!NormalIterator(f));
}
void doThings(I)(I fileIter)
{
 foreach(string line; fileIter) {
 // do things
 }
}


That does it, thanks :)!


Re: Haskell calling D code through the FFI

2014-08-05 Thread Jon via Digitalmars-d-learn
So that does indeed solve some of the problems.  However, using 
this method, when linking I get two errors, undefined reference 
rt_init() and rt_term() I had just put these methods in the 
header file.  If I put wrappers around these functions and export 
I get the rt_init, rt_term is private.


On Tuesday, 5 August 2014 at 21:28:08 UTC, David Soria Parra 
wrote:

On Monday, 4 August 2014 at 20:48:09 UTC, Jon wrote:

For reasons I don't completely understand, you also need a 
fake main function, dummy.d:


   void main(){}



Note that this is not necessary if you compile with -lib e.g.:

  dmd -lib -oflibtest.a test.d

and then

  ghc Main.hs --make -omain libtest.a

I don't have gdc or ldc installed but as far as I know ldc has 
a -lib flag as well.




Best practices for testing functions that opens files

2014-08-05 Thread splatterdash via Digitalmars-d-learn

Hi all,

Is there a recommended way to test functions that opens and 
iterates over files? The unittest block seems more suited for 
testing functions whose input and output can be defined in the 
program itself. I'm wondering if there is a better way to test 
functions that open files with specific formats.


Thanks before :).


Re: Inner struct accessing host member

2014-08-05 Thread Era Scarecrow via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 20:32:08 UTC, Philippe Sigaud wrote:

But the compiler tells me 'need this for i of type int[]'.
Is there any way I can gain access on i inside B?



 Been thinking about this a bit. I know some of my relies are in 
the 2012 fourm posts regarding it, but access permissions seems 
like the biggest reason, or rather lack of control of them.


 So take your example:


struct A
{
int[] i;
B b;
}


 Now let's make a couple instances of it; And assume it would 
work...


 A a;
 immutable A i_a;

 a.b.foo(); //fine
 i_a.b.foo(); //won't run, due to not being const/immutable

 So, a user decides let's copy the inner struct. If the struct 
copies it's attached secondary pointer going to it's outer/host, 
then:


 A.B b = a.b;
 A.B i_b = i_a.b;
 A.B broken_b = cast(A.B) i_a.b;

 b.foo(); //attached to a still, works...
 i_b.foo(); //const or immutable, won't work.
 broken_b.foo(); //i_a is accessible invisibly because overridden 
or transformed assuming it would be converted or copied/moved as 
appropriate.


 return b; //if a is a local variable then b becomes invalid even 
though it's a struct.

 return i_b; //same as return b
 return broken_b; //same as above two cases.




 inner structs in a function where the struct is never passed 
outside the function would probably work though...


void func() {
  int[] i;
  struct B {
void foo() { i ~= 1;}
  }

  B b;

  b.foo(); //passed a reference to the current frame along with 
it's local 'this', but since it never leaves the function it's 
safe.

}




 Now a current way to make it safe while still leaving it structs 
could be passing a reference to either the outer struct or the 
variable in question. For simplicity it would probably be the 
struct.


struct A
{
int[] i;
B b;

struct B
{
void foo(ref A outer) { outer.i ~= 1;}
}

void bar() //call B foo
{
b.foo(this);
}
}

 Or less safe is to use a pointer and assign it when b 
instantiates to point back to A.. But if you pass B around 
without A and A goes out of scope... same problem...


 Maybe i'm over-thinking it.


Re: Inner struct accessing host member

2014-08-05 Thread Artur Skawina via Digitalmars-d-learn
On 08/05/14 22:32, Philippe Sigaud via Digitalmars-d-learn wrote:
 I'd have thought that this would work:
 
 struct A
 {
 int[] i;
 B b;
 
 struct B
 {
 void foo() { i ~= 1;}
 }
 }
 
 void main()
 {
 A a;
 a.b.foo();
 }
 
 But the compiler tells me 'need this for i of type int[]'.
 Is there any way I can gain access on i inside B?

Not directly, but as you ask for /any/ way -- yes:

   struct B
   {
 void foo() { outer.i ~= 1; }
 ref A outer() inout @property { return 
*cast(A*)(cast(void*)this-A.b.offsetof); }
   }

Note this will work only as long as you have just one B
instance in A and B is never created or copied outside of A.

artur


Re: Haskell calling D code through the FFI

2014-08-05 Thread safety0ff via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 23:23:43 UTC, Jon wrote:
So that does indeed solve some of the problems.  However, using 
this method, when linking I get two errors, undefined reference 
rt_init() and rt_term() I had just put these methods in the 
header file.  If I put wrappers around these functions and 
export I get the rt_init, rt_term is private.




It works for me, here are the main parts of my Makefile:

DC = ~/bin/dmd

main: Main.hs FunctionsInD.a
ghc -o main Main.hs FunctionsInD.a ~/lib/libphobos2.a -lpthread

FunctionsInD.a: FunctionsInD.d
$(DC) -c -lib FunctionsInD.d

I passed in the phobos object directly because I don't know how 
to specify the ~/lib directory on the ghc command line.


Re: Dub failing to detect Shared Libraries

2014-08-05 Thread Mike Parker via Digitalmars-d-learn

On 8/6/2014 2:53 AM, Rishub Nagpal wrote:

I am porting DerelictBGFX to linux, but I am having some problems. When
I run the dub command in my example directory, I get the following error :

derelict.util.exception.SharedLibLoadException@../../../.dub/packages/derelict-util-1.0.2/source/derelict/util/exception.d(35):
Failed to load one or more shared libraries:
 libbgfx-shared-libRelease.so - libbgfx-shared-libRelease.so: cannot
open shared object file: No such file or directory
 libbgfx-shared-libDebug.so - libbgfx-shared-libDebug.so: cannot
open shared object file: No such file or directory


Here is the file I edited to detect those libaries :
https://github.com/shrub77/DerelictBgfx/blob/master/source/derelict/bgfx/bgfx.d#L55


Here is the dub.json :
{
 name: 00-helloworld,

 sourcePaths: [.],
 targetType: executable,
 mainSourceFile: helloworld.d,

 dependencies:
 {
 gfm:sdl2: =1.1.4,
 derelict-bgfx: {path: ../../, version: ~master}
 }
}

Where should I put the *.so files so they can be detected properly by dub?

Rishub



This has nothing to do with dub. You need to install the shared 
libraries manually so that Derelict can pick them up at run time. They 
need to be on the global library search path, whatever that may be for 
your system.


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



Re: unittest affects next unittest

2014-08-05 Thread Jonathan M Davis via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 17:41:06 UTC, Marc Schütz wrote:

On Tuesday, 5 August 2014 at 15:39:55 UTC, sigod wrote:
On Saturday, 2 August 2014 at 06:46:04 UTC, Jonathan M Davis 
via Digitalmars-d-learn wrote:

On Fri, 01 Aug 2014 23:09:37 +
sigod via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



Code: http://dpaste.dzfl.pl/51bd62138854
(It was reduced by DustMite.)

Have I missed something about structs? Or this simply a bug?


Don't do this with a member variable:

private Node * _root = new Node();

Directly initializing it like that sets the init value for 
that struct, and
that means that every struct of that type will have exactly 
the same value for
_root, so they will all share the same root rather than 
having different

copies. You need to initialize _root in the constructor.

- Jonathan M Davis


So, it's a static initialization? Documentation didn't mention 
it. (In class' section only 2 sentences about it and none in 
struct's section.)


This is different from many languages (C#, Java... don't know 
about C and C++). What was the reason to make this 
initialization static?


It's a consequence of the fact that every type in D has a 
default initializer which is known at compile time.


That and it solves a lot of problems with undefined behavior 
(this is particularly true when talking about module-level 
variables). static initialization ordering problems are hell in 
other languages (especially in C++). By making it so that all 
direct initializations of variables other than local variables 
are done statically, all kinds of nasty, subtle bugs go away. The 
one nasty, subtle issue that it causes that I'm aware of is that 
if you directly initialize any member variables which are 
reference types, then all instances of that type end up referring 
to the same object - and that's what you ran into. But 
fortunately, that's easy to fix, whereas the static 
initialization problems that were fixed by making all of those 
variables have to be initialized at compile time are much harder 
to fix.


- Jonathan M Davis


Re: unittest affects next unittest

2014-08-05 Thread Era Scarecrow via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 17:41:06 UTC, Marc Schütz wrote:
It's a consequence of the fact that every type in D has a 
default initializer which is known at compile time.


 Then doesn't this mean it should pop out a warning in case 
that's the behavior you wanted, perhaps a reference to the D 
specs?


 Beyond that it would be easy to forget it does that, since class 
initializes things different than structs because of the 'known 
at compile time' logic.


Re: Best practices for testing functions that opens files

2014-08-05 Thread abanstadya via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 23:22:24 UTC, splatterdash wrote:

Hi all,

Is there a recommended way to test functions that opens and 
iterates over files? The unittest block seems more suited for 
testing functions whose input and output can be defined in the 
program itself. I'm wondering if there is a better way to test 
functions that open files with specific formats.


Thanks before :).


The concern would be more on functions that delete files. 
Yesterday I've made a programming error which resulted into the 
deletion if the source files of another project. Fortunately the 
other project was git-i-fyed and I just had to stash/pull to 
recover my files.
Take care. Opening files with wrong args can overwrite, delete 
the curent one.

Maybe make a sandbox environment (clean brand new account).



Re: Member access of __gshared global object

2014-08-05 Thread Puming via Digitalmars-d-learn

On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:

On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy 
it?


This is probably your problem. They are reference types, but 
initially that reference is `null`. When you write:


auto cmds = CONFIG.commands;

`cmds` contains a copy of the `null` value. On assignment, the 
actual AA is created, and assigned to `cmds`, but not back to 
`CONFIG.commands`. Try initializing the AA in your class 
constructor.


I checked the code and could concur your suggestion.

What I found strange were:

1. The only way that I can initialize it is to assign a value. 
But I want to initialize an empty AA, is that possible?


2. CONFIG.commands is not `null` before initialized, it is 
'[]'(when I writeln it). But it still behave like what you 
described (except that it won't produce an NullPointer Exception.




HTP Handler

2014-08-05 Thread HUSSAIN via Digitalmars-d-learn

Hi ,

I am new to D, I would like to build HTTP Server in D. Can any 
one throw some light on what are all the libraries available in D 
and if there is any example it would be helpful.


Thanks
Hussain


Re: HTP Handler

2014-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 04:10:27AM +, HUSSAIN via Digitalmars-d-learn wrote:
 Hi ,
 
 I am new to D, I would like to build HTTP Server in D. Can any one
 throw some light on what are all the libraries available in D and if
 there is any example it would be helpful.
[...]

http://vibed.org/


T

-- 
This sentence is false.


Re: HTP Handler

2014-08-05 Thread Puming via Digitalmars-d-learn

See this list:

https://github.com/zhaopuming/awesome-d#web-frameworks



On Wednesday, 6 August 2014 at 04:10:28 UTC, HUSSAIN wrote:

Hi ,

I am new to D, I would like to build HTTP Server in D. Can any 
one throw some light on what are all the libraries available in 
D and if there is any example it would be helpful.


Thanks
Hussain




Re: Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn

On Tuesday, 5 August 2014 at 22:14:23 UTC, abanstadya wrote:

programming Q, either youra newb or not, should rather be 
posted to 'http://forum.dlang.org/group/digitalmars.D.learn'. 
Your post appears on 
'http://forum.dlang.org/group/digitalmars.D' which is more 
related to the lang. design rather to programming Q. Take care 
next time bro.


This *is* D.learn, bro.


Re: Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn
On Tuesday, 5 August 2014 at 23:47:00 UTC, Artur Skawina via 
Digitalmars-d-learn wrote:



Is there any way I can gain access on i inside B?


Not directly, but as you ask for /any/ way -- yes:

   struct B
   {
 void foo() { outer.i ~= 1; }
 ref A outer() inout @property { return 
*cast(A*)(cast(void*)this-A.b.offsetof); }

   }

Note this will work only as long as you have just one B
instance in A and B is never created or copied outside of A.


OK. I have en entire graph, whose nodes are Bs inside A. So that 
might not be totally appropriate for me. Thanks anyway, I always 
forget about offsetof


Re: Inner struct accessing host member

2014-08-05 Thread Philippe Sigaud via Digitalmars-d-learn

Era:
 broken_b.foo(); //i_a is accessible invisibly because 
overridden or transformed assuming it would be converted or 
copied/moved as appropriate.


 return b; //if a is a local variable then b becomes invalid 
even though it's a struct.

 return i_b; //same as return b
 return broken_b; //same as above two cases.


I see. I didn't know one could create an A.B 'outside'. I saw 
inner types as Voldemort types, but that is true only for inner 
structs in functions.




 Now a current way to make it safe while still leaving it 
structs could be passing a reference to either the outer struct 
or the variable in question. For simplicity it would probably 
be the struct.

(...)
 Or less safe is to use a pointer and assign it when b 
instantiates to point back to A.. But if you pass B around 
without A and A goes out of scope... same problem...


 Maybe i'm over-thinking it.


I already tried to propagate a ref through A's methods, but that 
made a mess: I have lots of methods, which have all to transmit 
this ref, only for *one* of them being able to update it.


Thanks for you explanations :)
I'm now using classes and inner classes. I'm not fond of classes, 
but that's working correctly.