Re: Dynamically loading a D dynamic library from a c++ program

2014-09-27 Thread Jacob Carlborg via Digitalmars-d-learn

On 2014-09-26 21:52, John Colvin wrote:


Yes, but it depends on the complexity of the headers. C++ templates
aren't supported for example.


Templates are supported, if they're already instantiated.

--
/Jacob Carlborg


Re: Dynamically loading a D dynamic library from a c++ program

2014-09-27 Thread John Colvin via Digitalmars-d-learn
On Saturday, 27 September 2014 at 09:19:57 UTC, Jacob Carlborg 
wrote:

On 2014-09-26 21:52, John Colvin wrote:

Yes, but it depends on the complexity of the headers. C++ 
templates

aren't supported for example.


Templates are supported, if they're already instantiated.


Sorry, yes, I should have clarified that.


Re: Can I make a variable public and readonly (outside where was declared) at same time?

2014-09-27 Thread via Digitalmars-d-learn
On Friday, 26 September 2014 at 18:18:45 UTC, Steven 
Schveighoffer wrote:
On 9/26/14 1:36 PM, Marc =?UTF-8?B?U2Now7x0eiI=?= 
schue...@gmx.net wrote:


Alternatively, you could create a union with a private and a 
public
member with the same types, but I wouldn't recommend it. 
Besides, the

members would need to have different names:

class Foo {
union {
private int a;
public int b;
}
}


Hm.. that doesn't provide readonly access to either a or b.

But it gave me an idea:

class Foo {
   union {
  private int _a;
  public const int a;
   }
   void setA(int x) { _a = x; }
}



Yes, that's what I originally intended. Just forgot the const, 
and didn't even notice it after I reread it :-P


Recursive data-types

2014-09-27 Thread ponce via Digitalmars-d-learn
I'm dabbling with Scheme interpreter and ultimately I would need 
to declare the following types.


--

struct Function
{
Environment env;
Atom params;
Atom body_;
}

// An atom is either a string, a double, a symbol, a function or 
a list of atoms

alias Atom = Algebraic!(string, double, Symbol, Function, This[]);

--

These definitions can't work since Function and Atom need each 
other in this recursive definition.


How to get out of this trap?
Do I have to drop Algebraic and go back to manual tagged unions?


Re: Recursive data-types

2014-09-27 Thread Rikki Cattermole via Digitalmars-d-learn

On 27/09/2014 11:26 p.m., ponce wrote:

I'm dabbling with Scheme interpreter and ultimately I would need to
declare the following types.

--

struct Function
{
 Environment env;
 Atom params;
 Atom body_;
}

// An atom is either a string, a double, a symbol, a function or a list
of atoms
alias Atom = Algebraic!(string, double, Symbol, Function, This[]);

--

These definitions can't work since Function and Atom need each other in
this recursive definition.

How to get out of this trap?
Do I have to drop Algebraic and go back to manual tagged unions?


Converting Function to a class. No where near ideal. But it'll work.


Re: Recursive data-types

2014-09-27 Thread ponce via Digitalmars-d-learn
On Saturday, 27 September 2014 at 11:40:19 UTC, Rikki Cattermole 
wrote:

How to get out of this trap?
Do I have to drop Algebraic and go back to manual tagged 
unions?


Converting Function to a class. No where near ideal. But it'll 
work.


It does work! Thanks.
Actually it's quite appropriate to make it a reference type.



Problem building dmd d_do_test tool - missing link operand

2014-09-27 Thread Nick Treleaven via Digitalmars-d-learn

Hi,
I used to run the ddoc tests with no problem, but for the last month or 
so I ran into problems building the d_do_test tool from latest Git dmd. 
(As I didn't need the latest dmd at the time, I just used an older one 
for a while).


Maybe I'm doing something wrong with my build setup for 
dmd/druntime/phobos, or maybe it's something else. Here's the output:


# in dmd/test
$ make DMD=../src/dmd.exe QUIET=''
Building d_do_test tool
OS: win32
../src/dmd.exe -m32 -unittest -run d_do_test.d -unittest
/usr/bin/link: missing operand after `d_do_test,,nul,user32+kernel32/noi;'
Try `/usr/bin/link --help' for more information.
DMD v2.067 DEBUG
--- errorlevel 1
make: *** [test_results/d_do_test.exe] Error 1


If I comment out the d_do_test unittest line in dmd/test/Makefile:

$ make DMD=../src/dmd.exe QUIET=''
Building d_do_test tool
OS: win32
#../src/dmd.exe -m32 -unittest -run d_do_test.d -unittest
../src/dmd.exe -m32 -odtest_results -oftest_results\\d_do_test.exe 
d_do_test.d
/usr/bin/link: missing operand after 
`test_results\\d_do_test,test_results\\d_do_test.exe,nul,user32+kernel32/noi;'

Try `/usr/bin/link --help' for more information.
DMD v2.067 DEBUG
--- errorlevel 1
make: *** [test_results/d_do_test.exe] Error 1


Any ideas?


Re: Problem building dmd d_do_test tool - missing link operand

2014-09-27 Thread Nick Treleaven via Digitalmars-d-learn

On 27/09/2014 12:59, Nick Treleaven wrote:

# in dmd/test
$ make DMD=../src/dmd.exe QUIET=''
Building d_do_test tool
OS: win32
../src/dmd.exe -m32 -unittest -run d_do_test.d -unittest
/usr/bin/link: missing operand after `d_do_test,,nul,user32+kernel32/noi;'
Try `/usr/bin/link --help' for more information.


Found the problem - I'd accidentally commented out this line from sc.ini:

LINKCMD=C:\D\dm\bin\link.exe



Re: Recursive data-types

2014-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 27, 2014 at 11:26:31AM +, ponce via Digitalmars-d-learn wrote:
 I'm dabbling with Scheme interpreter and ultimately I would need to
 declare the following types.
 
 --
 
 struct Function
 {
 Environment env;
 Atom params;
 Atom body_;
 }
 
 // An atom is either a string, a double, a symbol, a function or a
 // list of atoms
 alias Atom = Algebraic!(string, double, Symbol, Function, This[]);
 
 --
 
 These definitions can't work since Function and Atom need each other
 in this recursive definition.
[...]

What about using Atom*[] instead of Atom[]?


T

-- 
Microsoft is to operating systems  security ... what McDonalds is to gourmet 
cooking.


Debugging on OSX

2014-09-27 Thread Phil via Digitalmars-d-learn

I've seen a few old threads mentioning this, but couldn't find
anything more recent. What support is there for debugging on OSX?
I'm currently trying MonoD, but the option to run with debugger
is greyed out.


Re: Recursive data-types

2014-09-27 Thread Meta via Digitalmars-d-learn

On Saturday, 27 September 2014 at 11:26:33 UTC, ponce wrote:
I'm dabbling with Scheme interpreter and ultimately I would 
need to declare the following types.


--

struct Function
{
Environment env;
Atom params;
Atom body_;
}

// An atom is either a string, a double, a symbol, a function 
or a list of atoms
alias Atom = Algebraic!(string, double, Symbol, Function, 
This[]);


--

These definitions can't work since Function and Atom need each 
other in this recursive definition.


How to get out of this trap?
Do I have to drop Algebraic and go back to manual tagged unions?


You can also use a pointer to a Function. Basically, any 
indirection will solve this problem, whether it be via class or 
pointer.


struct Function
{
Environment env;

//Either do this:
Atom* params;
Atom* body_;
}

//Or this   //Now a pointer
alias Atom = Algebraic!(string, double, Symbol, Function*, 
This[]);


Also, you might want to use This* instead of This[], unless you 
want an Atom to be able to contain a whole array of other atoms.


Re: Recursive data-types

2014-09-27 Thread ponce via Digitalmars-d-learn
On Saturday, 27 September 2014 at 14:08:18 UTC, H. S. Teoh via 
Digitalmars-

What about using Atom*[] instead of Atom[]?



Atom[] seems simpler to me.



Re: Recursive data-types

2014-09-27 Thread ponce via Digitalmars-d-learn

On Saturday, 27 September 2014 at 15:45:20 UTC, Meta wrote:


Also, you might want to use This* instead of This[], unless you 
want an Atom to be able to contain a whole array of other atoms.


That's indeed what I want.



Re: Recursive data-types

2014-09-27 Thread thedeemon via Digitalmars-d-learn
On Saturday, 27 September 2014 at 11:40:19 UTC, Rikki Cattermole 
wrote:


These definitions can't work since Function and Atom need each 
other in

this recursive definition.

How to get out of this trap?
Do I have to drop Algebraic and go back to manual tagged 
unions?


Converting Function to a class. No where near ideal. But it'll 
work.


Interesting, I didn't expect this to work...
Got a longer workaround using some category theory and higher 
kinded types:

http://www.infognition.com/blog/2014/recursive_algebraic_types_in_d.html


Re: Can I make a variable public and readonly (outside where was declared) at same time?

2014-09-27 Thread AsmMan via Digitalmars-d-learn
On Friday, 26 September 2014 at 18:18:45 UTC, Steven 
Schveighoffer wrote:
On 9/26/14 1:36 PM, Marc =?UTF-8?B?U2Now7x0eiI=?= 
schue...@gmx.net wrote:


Alternatively, you could create a union with a private and a 
public
member with the same types, but I wouldn't recommend it. 
Besides, the

members would need to have different names:

class Foo {
union {
private int a;
public int b;
}
}


Hm.. that doesn't provide readonly access to either a or b.

But it gave me an idea:

class Foo {
   union {
  private int _a;
  public const int a;
   }
   void setA(int x) { _a = x; }
}

Hot damn! It works too :) Can't access _a from outside the 
module, can access a, but can't write it (even from within 
Foo). It's like an auto-inlined property function.


I don't know how it would affect the optimizer, or the GC 
scanner. Unions are ugly things...


-Steve


This is really a loot cool and works. Thanks. If private in D had 
same behavior like in C#/C++, ie, private to scope of where class 
was declared and not public to the entire module, I guess we 
could even do:


class Foo {
union {
private int a_;

public @property int a() {
return a_;
}

private @property void a(int value) {
a_ = value;
}
}

//no one need knows the 'a_' (ugly?) identifier
void setValue(int x)
{
a = x;
}
}

And then

Foo f = new Foo();
f.a = 10; // give a compile error becaus it is private and 
acessible within Foo class only


BTW: I'm not sure about memory usage where using properties. But 
it is still cool.


std.container.Array support in msgpack

2014-09-27 Thread Nordlöw
I'm trying to figure out how to add raw bytes the packed stream 
in msgpack-d. My current try is


import std.stdio;
import std.conv: to;
import std.container: Array;
import msgpack;

static void stringArrayPackHandler(E)(ref Packer p,
  ref Array!E x)
{
// p.put(192);
/* p.packArray(x); */
foreach (e; x)
p.pack(e);
}

unittest
{
registerPackHandler!(Array!string, stringArrayPackHandler);
Array!string x = [x, y];
writeln(x.pack);
writeln([x, y].pack);
}

which outputs

[161, 120, 161, 121]
[146, 161, 120, 161, 121]

How do I add the leading byte 146?


Re: Can I make a variable public and readonly (outside where was declared) at same time?

2014-09-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/27/14 5:48 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net

Yes, that's what I originally intended. Just forgot the const, and
didn't even notice it after I reread it :-P


I wondered... ;)

-Steve