Re: RSA library

2016-08-18 Thread Andre via Digitalmars-d-learn

On Thursday, 18 August 2016 at 14:29:54 UTC, Adam D. Ruppe wrote:

On Thursday, 18 August 2016 at 09:00:58 UTC, Andre Pany wrote:
Is there a D library which can be built with a plain x86 DMD 
and without dll dependencies?


Not that I know of, and I don't think the win32 api includes 
rsa256 (though .net does!).


The botan lib though, why doesn't it work on 32 bit optlink? 
You might be able to hack it by just taking the algorithms you 
need and compiling yourself.


It is a statement from the botan github readme, maybe due to a 
dependency.


I will try the windows api, from the description it seems exactly 
what i need. I will also check wheter the specific botan part 
could be extracted.

Thanks a lot.

Kind regards
Andre


Re: string mixin and alias

2016-07-29 Thread Andre via Digitalmars-d-learn

On Friday, 29 July 2016 at 18:39:23 UTC, Jesse Phillips wrote:

On Friday, 29 July 2016 at 18:34:56 UTC, Jesse Phillips wrote:
Here the generateCode() is mixed in to the context of foo(), 
which is fine if your code is performing actions but is no 
good if you're creating declarations that you want to use in 
the context of main().


Here is a fully functioning example:

---
string generateCode(string s){return s;}

void main()
{
int a, b;
enum s = "a = 2 + 3; b = 4 + a;";
foo!(s)(a, b);
assert(a == 5);
assert(b == 9);
}

void foo(alias s)(ref int a, ref int b) {
mixin(generateCode(s));
}
---


Thanks for all the answers.

Kind regards
Andre


Re: JSONValue floating and 42

2016-04-19 Thread Andre via Digitalmars-d-learn
On Tuesday, 19 April 2016 at 13:58:05 UTC, Edwin van Leeuwen 
wrote:

On Tuesday, 19 April 2016 at 13:44:08 UTC, Andre wrote:
-> I need to analyze every value whether it is a floating or 
an integer?


This is the correct option. Something like:

double f;
if (j["value"].type == JSON_TYPE.INTEGER)
  f = j["value"].integer.to!float;
else
  f = j["value"].floating;

There are also a number of libraries available that make 
dealing with json a bit easier:

code.dlang.org/search?q=json


I will do so. Thanks.

Kind regards
André


JSONValue floating and 42

2016-04-19 Thread Andre via Digitalmars-d-learn

Hi,

I have to deal with a JSON like this
[{"value":42},{"value":1e+100}]

Value is a floating number, but the providing system does not 
write 42 as 42.00.
While trying to get the value with .floating, I get an exception 
because 42 is not

a floating value.

I try to understand what is the issue here.

-> Does the system violates the JSON Standard, and it should 
deliver 42.00?

-> .floating should be enhanced to handle 42?
-> I need to analyze every value whether it is a floating or an 
integer?


Kind regards
André


Re: Some strange behaviors of enums and string.startsWith

2016-04-08 Thread Andre via Digitalmars-d-learn

On Friday, 8 April 2016 at 14:56:51 UTC, Adam D. Ruppe wrote:

On Friday, 8 April 2016 at 14:38:10 UTC, Andre wrote:
Therefore I use std.conv.text to convert the string enum? to 
string.


That converts the *name* of the enum to string, not the 
contents. (BTW, I think the name of the enum is actually the 
more useful behavior.)


Use cast(string) if you want to get the content out.


Thanks a lot, now the behavior makes sense.
I will create a feature request for the phobos issue.

Kind regards
André


Some strange behaviors of enums and string.startsWith

2016-04-08 Thread Andre via Digitalmars-d-learn

Hi,

I have some issues with enums. Please have a look at the last 3 
assertions.
It is annoying that I cannot directly use my StringEnum for 
startsWith.
Therefore I use std.conv.text to convert the string enum? to 
string.
But then the assertion fails, that is very strange, it fails only 
for string ":" but

not for string "b".

Is this a bug? => Tested with DMD 2.071 on windows.

Kind regards
André

enum ManifestConst = ":";
enum CharEnum { a = ':' }
enum StringEnum{a = ":", b = "b"}

import std.string: startsWith, endsWith;
import std.conv: text;

void main()
{
assert( ":abc".startsWith(CharEnum.a)); // OK
assert( ":abc".startsWith(ManifestConst)); // OK
//assert( "abc".startsWith(StringEnum.a)); // Compiler error
	assert( ":abc".startsWith(StringEnum.a.text)); // Assertion 
failure

assert( "bc".startsWith(StringEnum.b.text)); // OK ???
}


Re: Issue with 2.071: Regression or valid error?

2016-04-06 Thread Andre via Digitalmars-d-learn

On Wednesday, 6 April 2016 at 19:22:44 UTC, Daniel Kozak wrote:
This should not compile. Cat cant access create because it is 
private. Ok
it can access it but only if you move cat into same module as 
animal
Dne 6. 4. 2016 17:16 napsal uživatel "Andre via 
Digitalmars-d-learn" <

digitalmars-d-learn@puremagic.com>:


Thanks for the answers.

Kind regards
André


Issue with 2.071: Regression or valid error?

2016-04-06 Thread Andre via Digitalmars-d-learn

Hi,

With 2.071 following coding does not compile anymore and somehow 
I feel it should compile.

The issue is with line "cat.create();".
Cat is a sub type of Animal. Animal "owns" method create and I 
want to call the method

create within the class Animal for cat.

Is the error message "no property create for type 'b.cat'" valid 
or not?


Kind regards
André

module a;
import b;

class Animal
{
private void create() {}

void foo(Cat cat)
{
cat.create(); // >> no property create for type 'b.cat'
}
}

void main() {}

--

module b;
import a;

class Cat: Animal {};

compile with

rdmd a b


Re: dub, copyFiles and linux

2016-03-30 Thread Andre via Digitalmars-d-learn

OK solved;)
Shared libraries doesn't need to be mentioned in libs section in 
dub.
Therefore copying after the linking is correct and is working 
fine.


Kind regards
André


Re: dub, copyFiles and linux

2016-03-30 Thread Andre via Digitalmars-d-learn

On Thursday, 31 March 2016 at 04:57:01 UTC, Andre wrote:

I can't see why it is working with vibe-d projects (openssl 
libraries copied to application folder) but not for my project. 
There is no console output "copying files for..." while using 
dub for my application project.

What is wrong?

Kind regards
André


OK, I see copying files is triggered after the linking process.
That is bad...


dub, copyFiles and linux

2016-03-30 Thread Andre via Digitalmars-d-learn

Hi,

I created a library which uses some shared objects. The dub.json 
looks like this:

{
"name": "sec",
"configurations": [
{
"name": "debug",
"targetType": "library",
"copyFiles":["lib/libssoext.so","lib/librypto.so"],
"libs-posix": ["ssoext"],
"lflags":["-L./.","-rpath=./."],
}
]
}
Within my project folder, there is a folder lib with the 2 so 
files.


Within my application project, I use this library. The dub.sdl 
looks like this:

name "demo"
targetName "app"
dependency "sec" version=">=0.0.1"

I would expect, while dub is compiling my application project, 
the 2 libs are

copied to my application folder. But that is not working.

I can't see why it is working with vibe-d projects (openssl 
libraries copied to application folder) but not for my project. 
There is no console output "copying files for..." while using dub 
for my application project.

What is wrong?

Kind regards
André


Re: Usage of custom class with JSONValue

2016-03-24 Thread Andre via Digitalmars-d-learn
On Thursday, 24 March 2016 at 16:03:13 UTC, Edwin van Leeuwen 
wrote:

On Thursday, 24 March 2016 at 11:39:13 UTC, arturg wrote:

isnt alias this supposed to do this implicitly?

convert this
auto jsValue = JSONValue(new MyClass());

into this
auto jsValue = JSONValue((new MyClass())._data);


Good point, I did not catch that. That indeed should work and 
seems to be a bug. Does it work if _data is a base type (string 
or int, etc..)


Thanks for the answers. I also wonder why alias this does not the 
job.
Unfortunatelly even if it works, the _data is not the data I want 
to be used
as value for JSONValue. _data only contains keys, the values are 
stored

in another variable. JSONValue should contain both.

I hoped there is some operator overloading for implicit 
conversion of my

class to JSONValue.
I solved the issue with an toJSON method and a generic 
functionality which

checks for this method.

Kind regards
André


Usage of custom class with JSONValue

2016-03-24 Thread Andre via Digitalmars-d-learn

Hi,

I have a class which has already an alias this to a string array,
so I can use it in a foreach loop.

class MyClass
{
string[] _data;
alias _data this;
// ...
}

void main()
{
import std.json;
auto jsValue = JSONValue(new MyClass());
}

For some generic code I need an implicit conversion of MyClass so 
I can
use it for a JSONValue. For the coding above I receive a compiler 
error:

static assert  "unable to convert type "MyClass" to json"

Is there anything I can do?

Kind regards
André



Re: Determine decimal separator (comma vs point)

2016-03-07 Thread Andre via Digitalmars-d-learn

On Monday, 7 March 2016 at 12:29:39 UTC, Andre wrote:

Hi,

I execute an external application and get some decimal numbers:

auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",

"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
url]);

On my windows system, the decimal separator is "," therefore I 
want
to replace the "," with "." to avoid exceptions while 
converting the value to!double.


I thought following coding should return "," on my OS because 
it is set in the region settings but "." is returned:


import core.stdc.locale;

auto lConv = localeconv();
char decSeparator = *lConv.decimal_point;

How can I determine the correct decimal separator?

Kind regards
André


I just found the answer:

lconv* lc;
setlocale(LC_NUMERIC, "");
lc = localeconv();
writeln(to!string(lc.decimal_point));


Determine decimal separator (comma vs point)

2016-03-07 Thread Andre via Digitalmars-d-learn

Hi,

I execute an external application and get some decimal numbers:

auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",

"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
url]);

On my windows system, the decimal separator is "," therefore I 
want
to replace the "," with "." to avoid exceptions while converting 
the value to!double.


I thought following coding should return "," on my OS because it 
is set in the region settings but "." is returned:


import core.stdc.locale;

auto lConv = localeconv();
char decSeparator = *lConv.decimal_point;

How can I determine the correct decimal separator?

Kind regards
André



Re: Issues

2016-02-23 Thread Andre via Digitalmars-d-learn

On Tuesday, 23 February 2016 at 19:53:52 UTC, Johan Engelen wrote:
On Monday, 22 February 2016 at 23:21:28 UTC, Jonathan M Davis 
wrote:


Well, if you'll notice th list of resolved issues is going up 
way faster than the list of new issues.



(To put some oil on the fire:)

But the number of new issues /is/ going up. I.e. the number of 
resolved issues is going way up, the number of new new issues 
is going way way up. That's how I read the graph.


(Please help to resolve issues, rather than spending time on 
the forum talking about it ;)



:-)


For me this was helpful to get an idea what's going on, how 
people work on/think about issues, priorities, etc.
So please consider this time a little investment to get a new 
member more involved.


I'm considering working on some easy issues first. I will ignore 
the enhancement requests from bearophile that have status new, no 
votes, no one in CC, no comments. There are more than 200 (!) of 
them. These issues could be valid/valuable but I just don't agree 
with this way of shouting requests and not following up on them. 
I'd rather help someone else first who is really interested in 
solving his own requests.


Re: Issues

2016-02-23 Thread Andre via Digitalmars-d-learn

On Tuesday, 23 February 2016 at 00:13:23 UTC, ag0aep6g wrote:

On 22.02.2016 23:56, Andre wrote:
I was wondering how people in this D community think about the 
number of

issues with NEW status...

It could scare individuals/organizations to start with D, when 
they get
the impression that there are a large and growing number of 
issues that
are open (for years). I know this is not a fair interpretation 
of what's

going on, but it's a conclusion one could make.


I guess my reopening of issue 4763 [1] got you here. Old issues 
may be embarrassing, but I believe closing them without proper 
resolution, just because they're old, is very bad practice.


Regarding old enhancement request that never got anywhere, it's 
certainly tempting to just throw them away, but I think it's a 
bad move when a single member of the community just closes 
issues that have been filed by someone else. That would make 
for bad weather in the community.


Instead, I suggest to engage in discussion with the 
proponent(s) of the request. Or implement the request and try 
to get it merged.



- Is there a preferred way to clean things up?


Fix stuff :P


A resolution status?


Not sure what kind of status you're looking for. There's 
WONTFIX, but you shouldn't apply it just because an issue is 
old. As far as I know, we don't use LATER and REMIND.



A maximum time?


No.

- Or perhaps the bugtracker (https://dlang.org/bugstats.php) 
needs to be

adjusted for irrelevant things..


What do you mean by "irrelevant"? If you think an issue is 
irrelevant, please argue your point in the comments section of 
the issue.


Maybe all enhancement requests (that are not closely followed 
by an implementation) are "irrelevant"? I could understand that 
viewpoint, but that's not how we operate at the moment. If you 
want us to go in that direction, ask about it in the General 
group, and if there's consensus to do away with (long-lived) 
enhancement requests, mass-close them.


By the way, I don't like the bugstats.php page all that much. 
Some time ago I've played around with charts and put this 
together:


https://issues.dlang.org/chart.cgi?category=D===normal%20bugs=enhancement%20requests=major%20bugs=minor%20bugs=critical%20bugs=blockers=trivial%20bugs=regressions=101=104=100=102=99=98=103=97=98=data%20sets%20by%20severity=wrap=600=650

I think it's more interesting than the one on bugstats.php. But 
it doesn't go back as far - it only started counting when I 
created it. Then I gave up.


- Or is it a non-issue and should we just ignore the tail of 
the list?


Not ignore it, work towards reducing it by actually resolving 
stuff.



[1] https://issues.dlang.org/show_bug.cgi?id=4763


Judging from the quick response(s) to #4763 and this question I 
get the impression this is an active, positive and thoughtful 
community. Compliments!


I think your 'definition' of irrelevant is getting us somewhere:
- enhancement requests
- that are not closely followed by an implementation
- with outdated information
- empty CC
- no votes
- no owner

I agree with your point that a single member should not close 
something just because it's old. On the other hand, the issuer 
also has a responsibility to track/coordinate/complete issues.


In case of #4763 I closed it because 2 out of 3 enhancement 
requests were fixed/solved and the 3rd was open for about 5 
years, without recent activity, no owner, empty CC and no votes.


Instead, I suggest to engage in discussion with the 
proponent(s) of the request.

Point taken, I could have asked the proponent.


Or implement the request and try to get it merged.
I agree with all people responding, resolving is the best way to 
go.


About the >bugif it only shows bugs. For marketing and to challenge everyone to 
keep it near zero.


Thanks for everyone's insights.


Issues

2016-02-22 Thread Andre via Digitalmars-d-learn


I was wondering how people in this D community think about the 
number of issues with NEW status...


It could scare individuals/organizations to start with D, when 
they get the impression that there are a large and growing number 
of issues that are open (for years). I know this is not a fair 
interpretation of what's going on, but it's a conclusion one 
could make.


- Is there a preferred way to clean things up? A resolution 
status? A maximum time?


- Or perhaps the bugtracker (https://dlang.org/bugstats.php) 
needs to be adjusted for irrelevant things..


- Or is it a non-issue and should we just ignore the tail of the 
list?





cast fails for classes from windows dll

2016-01-12 Thread Andre via Digitalmars-d-learn

Hi,

I am not sure, whether this is a current limitation of the 
windows dll functionality of D

or I am doing s.th. which will not work.

I have developed in D a windows DLL which creates class instances 
by passing the name (using object.factory method).


In another D application I am using this DLL. My issue is, that 
the cast fails, although

typeid(bar).name shows the correct name .


module main;

// these classes are in a seperate module
// used for the dll & for this application
export class Foo {}
export class Bar : Foo {}
class Baz : Bar {}

void main()
{
// this method calls the dll and returns Foo
Foo c = dllCreateClass("main.Baz");

// no failure
assert( typeid(c).name == "main.Baz");

// > fails
if (auto myBar = cast(Bar) c){}
}

Kind regards
André


Re: Runtime.unloadLibrary terminates application on Windows

2015-12-14 Thread Andre via Digitalmars-d-learn

On Monday, 14 December 2015 at 17:50:26 UTC, Andre wrote:

Hi,

there is an issue with the example from
http://wiki.dlang.org/Win32_DLLs_in_D

While executing the DYNAMIC_LOAD version, the application
will exit on statement: if (!Runtime.unloadLibrary(h))

Neither "error freeing mydll.dll" nor "End..." is written
to the console.

The application just ends.

Kind regards
André


It seems to be a regression
https://issues.dlang.org/show_bug.cgi?id=1550

I will open a ticket for this issue


Re: Runtime.unloadLibrary terminates application on Windows

2015-12-14 Thread Andre via Digitalmars-d-learn

On Monday, 14 December 2015 at 19:17:00 UTC, Andre wrote:


It seems to be a regression
https://issues.dlang.org/show_bug.cgi?id=1550

I will open a ticket for this issue


https://issues.dlang.org/show_bug.cgi?id=15443


Runtime.unloadLibrary terminates application on Windows

2015-12-14 Thread Andre via Digitalmars-d-learn

Hi,

there is an issue with the example from
http://wiki.dlang.org/Win32_DLLs_in_D

While executing the DYNAMIC_LOAD version, the application
will exit on statement: if (!Runtime.unloadLibrary(h))

Neither "error freeing mydll.dll" nor "End..." is written
to the console.

The application just ends.

Kind regards
André




Forward declaration issue

2015-12-04 Thread Andre via Digitalmars-d-learn

Hi,

I have a strange issue with following coding.

void baz(); // forward declaration

void foo()
{
void bar()
{
baz(); // (1) without f.d. syntax error
}

void baz()
{
bar();
}

baz(); // (2) No linker error if line is removed
}

void main()
{
foo();
}

Without the forward declaration, there is a syntax error at (1)
With the forward declaration there is no syntax error but
a linker error at (2). This linker error disappears if line at (2)
is removed.
It looks like a bug, is it?

Kin regards
Andre


Re: Forward declaration issue

2015-12-04 Thread Andre via Digitalmars-d-learn

On Friday, 4 December 2015 at 09:51:30 UTC, Artur Skawina wrote:

No, it's how D is designed -- inside functions the order of 
declarations matters (and forward declarations don't work).


Your version wrongly declares another `baz` at module scope, 
and, as there's no definition, you end up with the linker error.


Two workarounds:

1) Templatize the functions:

   void foo()
   {
  void bar()()
  {
  baz();
  }

  void baz()()
  {
  bar();
  }

  baz();
   }

2) Use a struct:

   void foo()
   {
  struct Hack {
 void bar()
 {
 baz();
 }

 void baz()
 {
 bar();
 }
  }

  Hack hack;

  hack.baz();
   }

artur


Thanks for the clarifications and the example.

Kind regards
André



Re: utils.toBulkString is not accesible from utils

2015-12-02 Thread Andre via Digitalmars-d-learn

On Wednesday, 2 December 2015 at 12:37:29 UTC, Marc Schütz wrote:



I think so, yes. But according to digger, the current behaviour 
goes back to at least DMD 2.052. Please file a bug report 
anyway.


Bug report filed
https://issues.dlang.org/show_bug.cgi?id=15395


utils.toBulkString is not accesible from utils

2015-12-01 Thread Andre via Digitalmars-d-learn

Hi,

for following coding there is an error during compilation:

  module utils;

  package string toBulkString(string s)
  {
  import std.string: format;
  return "$%s\r\n%s\r\n".format(s.length, s);
  }

  unittest
  {
  string actual = "foobar".toBulkString();
  //...
  }

source\utils.d(11,39): Error: function utils.toBulkString is 
not accessible from module utils


The error disappears if I change the visibility attribute from 
package to private.

This seems to be a bug, is it?

Version: DMD v2.069.0-b2

Kind regards
André


Re: experimental.logger: safe function and stdou

2015-11-18 Thread Andre via Digitalmars-d-learn

On Thursday, 19 November 2015 at 06:27:58 UTC, Andre wrote:


override void writeLogMsg(ref LogEntry payload)
{
with (payload)
{
_stdOutLogger.logf(logLevel, `{
"file":"%s", "line":%s, "funcName":"%s", 
"prettyFuncName":"%s",
"moduleName":"%s", "logLevel":%s, "threadId":%s, 
"timestamp":"%s", "msg":"%s"}`,
file, line, funcName, prettyFuncName, moduleName, logLevel, 
threadId, timestamp);

}
}


I changed the implementation of writeLogMsg and attached the 
trusted attribute.

Is this a valid solution?

override void writeLogMsg(ref LogEntry payload) @trusted
{
with (payload)
{
			 writefln(`{"file":"%s", "line":%s, "funcName":"%s", 
"prettyFuncName":"%s",`~
	` "moduleName":"%s", "logLevel":%s, "threadId":%s, 
"timestamp":"%s", "msg":"%s"}`,
file, line, funcName, prettyFuncName, moduleName, logLevel, 
threadId, timestamp, msg);

stdout.flush();
}
}


experimental.logger: safe function and stdou

2015-11-18 Thread Andre via Digitalmars-d-learn

Hi,

I want to write log entries to stdout in JSON format. Therefore I 
created
a customer logger. Unfortunatelly there are 2 errors with 
following implementation:


module logger;

import std.experimental.logger;
import std.stdio: stdout;

class MyCustomLogger : Logger
{
private FileLogger _stdOutLogger;

this(LogLevel lv = LogLevel.all) @safe
{
super(lv);
_stdOutLogger = new FileLogger(stdout);
}

override void writeLogMsg(ref LogEntry payload)
{
with (payload)
{
_stdOutLogger.logf(logLevel, `{
"file":"%s", "line":%s, "funcName":"%s", 
"prettyFuncName":"%s",
"moduleName":"%s", "logLevel":%s, "threadId":%s, 
"timestamp":"%s", "msg":"%s"}`,
file, line, funcName, prettyFuncName, moduleName, logLevel, 
threadId, timestamp);

}
}
}

static this()
{
stdThreadLocalLog = new MyCustomLogger();
}

source\logger.d(13,34): Error: safe function 'this' cannot access 
__gshared data 'stdout'


source\logger.d(20,22): Error: safe function 
'logger.MyCustomLogger.writeLogMsg' cannot call system function 
'std.experimental.logger.core.Logger.logf!(20, 
"source\\logger.d", "logger.MyCustomLogger.writeLogMsg", "void 
logger.MyCustomLogger...



Also the example for creating an user defined logger is wrong:
http://dlang.org/phobos-prerelease/std_experimental_logger.html
There is a compilation error regarding variable newName in super.
newName seems not to be expected here.

Kind regards
André




win32 from master: unicode functions by default?

2015-11-11 Thread Andre via Digitalmars-d-learn

Hi,

by using the win32 library from master, the functions aliases
to the ansi windows functions (...A) instead of the unicode 
functions (...W).
Is there a way to control this behavior beside using the explicit 
function

names (A/W)?

Kind regards
André


Re: win32 from master: unicode functions by default?

2015-11-11 Thread Andre via Digitalmars-d-learn

On Thursday, 12 November 2015 at 05:08:25 UTC, Mike Parker wrote:

On Thursday, 12 November 2015 at 04:58:42 UTC, Andre wrote:

Hi,

by using the win32 library from master, the functions aliases
to the ansi windows functions (...A) instead of the unicode 
functions (...W).
Is there a way to control this behavior beside using the 
explicit function

names (A/W)?

Kind regards
André


version=Unicode on the compiler command line.


perfect. Thanks a lot.

Kind regards
André


Ternary if and ~ does not work quite well

2015-10-11 Thread Andre via Digitalmars-d-learn

Hi,

I am not sure, whether the output of following coding is correct:

import std.stdio;

void main()
{
writeln("foo "~ true ? "bar" : "baz");
writeln("foo "~ false ? "bar" : "baz");
	// assert("foo "~ true ? "bar" : "baz" == "foo bar"); does not 
compile

}

Output:

bar
bar


I would expect the output:

foo bar
foo baz


Also I would expect the assertion to compile.

Kind regards
André



Re: Ternary if and ~ does not work quite well

2015-10-11 Thread Andre via Digitalmars-d-learn

On Monday, 12 October 2015 at 05:25:46 UTC, H. S. Teoh wrote:
On Mon, Oct 12, 2015 at 05:19:38AM +, Andre via 
Digitalmars-d-learn wrote:

[...]

[...]

It's best to parenthesize when mixing other operators with ?, 
because ? has a pretty low precedence and may "steal" arguments 
from surrounding operators that you don't intend.  My suspicion 
is that what you wrote is being parsed as:


writeln(("foo " ~ true) ? "bar" : "baz");

which is why you're getting unexpected output. Write instead:

writeln("foo " ~ (true ? "bar" : "baz"));

If anything, it also helps readers of your code understand what 
it does without needing to consult the precedence table.



T


Thanks a lot for your answers, it really makes sense.

Kind regards
André


Re: Final templated interface method not found

2015-09-16 Thread Andre via Digitalmars-d-learn

Thanks, it works like a charme.

Kind regards
André


Final templated interface method not found

2015-09-15 Thread Andre via Digitalmars-d-learn

Hi,

following coding shoud work, or?
It doesn't compile with v2.068.0.

Kind regards
André

interface IfStatement
{
void execute();

final void execute(T...)(T t)
{
execute();
}
}

class Statement: IfStatement
{
void execute(){}
}

void main()
{
new Statement().execute(1,"Hello World");
}


Definition of SIGRTMIN

2015-08-31 Thread Andre via Digitalmars-d-learn

Hi,

I cannot use the definition of SIGRTMIN on ubuntu.
For following code I receive errors:

import core.sys.posix.time, core.sys.posix.signal, 
core.sys.posix.stdlib, core.sys.posix.unistd;

import std.stdio;

alias SIG = SIGRTMIN;

void main()
{
  writeln("Establishing handler for signal %d\n", SIG);
}


source/app.d(77): Error: function 
core.sys.posix.signal.__libc_current_sigrtmin is not accessible 
from module app



Is there s.th. wrong with the definition?

Kind regards
André


Re: PrimitiveRef ?

2015-03-23 Thread Andre via Digitalmars-d-learn

Thanks a lot.

I read it in the D Cookbook from Adam D. Ruppe.
In the chapter of memory management there is a topic,
how to build reference counted objects. Here this
construct is explained.

Kind regards
André

On Monday, 23 March 2015 at 20:58:48 UTC, Namespace wrote:

Something like that?

struct PrimitiveRef(T)
{
private T* _value;

@property
ref inout(T) get() inout pure nothrow {
assert(_value);

return *_value;
}

alias get this;

this(T val) {
_value = new T(val);
}
}

alias BoolRef = PrimitiveRef!bool;

void test(BoolRef b)
{
b = true;
}

void main()
{
BoolRef b = false;
test(b);
assert(b == true);  
}




PrimitiveRef ?

2015-03-23 Thread Andre via Digitalmars-d-learn

Hi,

I read that if a structure only contains a reference, it will 
behave like a reference type in function calls (needed for 
specifying reference behavior in a type tuple).
I need exactly that behavior. I am currently unsure whether it is 
possible at all to have such a construct which works at user side 
exactly like a boolean (booleans can be assigned and directly 
compared with ==) but internally are pointers...


(The coding does not compile)

Kind regards
André


struct PrimitiveRef(T)
{
private T* _value;

alias  _value this;

void opAssign(T v)
{
_value = v;
}

}
alias BoolRef = PrimitiveRef!bool;

void test(BoolRef b)
{
b = true;
}

void main()
{
BoolRef b = false;
test(b);
assert(b == true);  
}


Re: How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Andre via Digitalmars-d-learn

Thanks a lot!

Kind regards
André

On Tuesday, 10 March 2015 at 08:40:28 UTC, Jonathan M Davis wrote:
On Tuesday, March 10, 2015 07:24:52 Andre via 
Digitalmars-d-learn wrote:

Hi,

with the new beta I get the warning I should use
std.algorithm.sort instead the .sort property. I thought the
std.algorithm.sort method is used in this example?

void main()
{
  import std.algorithm: sort, uniq, map;
  import std.array: array;

  string[] arr = [A,B,B,C];

  string[] result = arr
  .map!(n = n) // minified
  .array
  .sort
  .uniq
  .array;
}

I want to use the sort template with the default less a  b
without specifying !(a  b)


.sort on an array is going to use the built-in sort property. 
You need to
use parens if you want to use the function in std.algorithm 
with an array

and UFCS, e.g.

arr.sort();

- Jonathan M Davis




Re: 2.067 Beta: Behavior of enum and ref changed

2015-03-10 Thread Andre via Digitalmars-d-learn

Thanks a lot!

Kind regards
André


On Tuesday, 10 March 2015 at 09:25:02 UTC, Meta wrote:
On Tuesday, 10 March 2015 at 08:37:46 UTC, Jonathan M Davis 
wrote:
It's the base type that isn't implicitly convertible to the 
enum type.


Err, yes. I had that the wrong way around. Anyway, I filed an 
issue.


https://issues.dlang.org/show_bug.cgi?id=14269


2.067 Beta: Behavior of enum and ref changed

2015-03-10 Thread Andre via Digitalmars-d-learn

Hi,

following coding raises a compiler error with the beta of 2.067.
Is this error intended or not?
It is working if I change first line of main to: ulong bits;

enum Bits: ulong
{
none = 0
}

bool hasBit(ref ulong rBits, ulong rBit)
{
return cast(bool)(rBits  rBit);
}

void main()
{
Bits bits;
hasBit(bits, Bits.none);
}

function app.hasBit (ref ulong rBits, ulong rBit) is not callable 
using argument types (Bits, Bits)


Kind regards
André


How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Andre via Digitalmars-d-learn

Hi,

with the new beta I get the warning I should use 
std.algorithm.sort instead the .sort property. I thought the 
std.algorithm.sort method is used in this example?


void main()
{   
import std.algorithm: sort, uniq, map;
import std.array: array;

string[] arr = [A,B,B,C];

string[] result = arr
.map!(n = n) // minified
.array
.sort
.uniq
.array;
}

I want to use the sort template with the default less a  b 
without specifying !(a  b)


Kind regards
André


Re: Implicit fall through not detected (Example from lex.html)

2015-03-03 Thread Andre via Digitalmars-d-learn

On Tuesday, 3 March 2015 at 07:27:33 UTC, ketmar wrote:


implicit fallthru is not a fatal bug (but i believe it should 
be), it

generates only warning.


I am also not really happy with the actual behavor (w / wi switch 
needed) because the documentation is clear about that it is an 
error:


-- from language reference:
A ScopeStatementList must either be empty, or be ended with a 
ContinueStatement, BreakStatement, ReturnStatement, 
GotoStatement, ThrowStatement or assert(0) expression unless this 
is the last case. This is to set apart with C's error-prone 
implicit fall-through behavior. goto case; could be used for 
explicit fall-through

--

Fortunately dub is using the correct switches by default

Kind regards
André


Implicit fall through not detected (Example from lex.html)

2015-03-02 Thread Andre via Digitalmars-d-learn

Hi,

I am little bit confused. I am copied the switch example from 
lex.html
and expected that case 6 will lead to a syntax error due to the 
missing
break statement. But the example compiles without error (C:dmd 
app)


I tried 3 different dmd version, also the newest beta.

Kind regards
André

import std.stdio: writeln;

void main()
{

int number;
string message;

switch (number)
{
  default:// valid
throw new Exception(unknown number);

  case 3: // valid
message ~= three ;
break;

  case 5: // valid
message ~= five ;
goto case;

  case 6: // ERROR: implicit fall-through
message ~= six ;

  case 1: // valid
  case 2: // valid
message = one or two;
}

}


curl password issue

2015-02-23 Thread Andre via Digitalmars-d-learn

Hi,

Curl has some issues with passwords containing special characters
like the hash key (#).
The password will not be accepted although it is correctly
set with the method setAuthencication(user, pass1234#);

I know this is more a Curl issue than a DLang issue but it
is very frustrating and for unexperienced users very hard to
find out why the application is working for some users
and for some others not...

Could the documentation for setAuthentication could be enhanced?

Kind regards
André




Re: Parameterized enum does not work

2015-01-09 Thread Andre via Digitalmars-d-learn

Thanks a lot.

Kind regards
André

On Friday, 9 January 2015 at 07:59:51 UTC, Daniel Kozak wrote:

On Friday, 9 January 2015 at 07:52:50 UTC, Daniel Kozak wrote:

On Friday, 9 January 2015 at 07:50:53 UTC, Daniel Kozak wrote:

On Friday, 9 January 2015 at 06:17:53 UTC, Andre wrote:

Hi,

Should following coding work?

string lpad(ubyte length, long n)
{
import std.string: rightJustify;
import std.conv: to;
return rightJustify(to!string(n), length, '0');
}

enum lpad14(long n) = lpad(14, n);

void main()
{
lpad14(123);
}

There is following error from dmd:

source\app.d(12): Error: template app.lpad14 cannot deduce 
function from argumen

t types !()(int), candidates are:
source\app.d(8):app.lpad14(long n)

Kind regards
André


What are you trying to do?


OK I probably see it now :):

import std.stdio;

string lpad(ubyte length, long n)
{
   import std.string: rightJustify;
   import std.conv: to;
   return rightJustify(to!string(n), length, '0');
}

enum lpad14(long n) = lpad(14, n);

void main()
{
   writeln(lpad14!(123));
}


However this is only for compile time, if you want runtime 
version you need something like this:


import std.stdio;

string lpad(ubyte length)(long n)
{
import std.string: rightJustify;
import std.conv: to;
return rightJustify(to!string(n), length, '0');
}

alias lpad14 = lpad!14;

void main()
{
writeln(lpad14(123));
}




Parameterized enum does not work

2015-01-08 Thread Andre via Digitalmars-d-learn

Hi,

Should following coding work?

string lpad(ubyte length, long n)
{
import std.string: rightJustify;
import std.conv: to;
return rightJustify(to!string(n), length, '0');
}

enum lpad14(long n) = lpad(14, n);

void main()
{
lpad14(123);
}

There is following error from dmd:

source\app.d(12): Error: template app.lpad14 cannot deduce 
function from argumen

t types !()(int), candidates are:
source\app.d(8):app.lpad14(long n)

Kind regards
André


Re: BigInt and

2014-12-19 Thread Andre via Digitalmars-d-learn

Great! Thanks a lot.

Kind regards
André

On Friday, 19 December 2014 at 08:47:50 UTC, bearophile wrote:

Andre:


Do you have any idea how to translate the coding correctly?


Try:

i += long(buffer[3])  24  0;

But I also suggest to add parentheses, to make the code less 
unreadable for humans.


Bye,
bearophile




BigInt and

2014-12-18 Thread Andre via Digitalmars-d-learn

Hi,

I try to translate following javascript coding to D:

i = buffer[2]  16;
i |= buffer[1]  8;
i |= buffer[0];
i += buffer[3]  24  0;

Buffer is:
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
255, 255, 111]


Expected result for i is: 4294967295
But in D the last statement returns -1, the previous 3 statements
returns the same values like in JavaScript.

I tried long and also like in the example BigInt, both do not
work correctly. In the documentation it is also mentioned that

is not supported for BigInt?


void main()
{
import std.stdio;
import std.bigInt;

	auto buffer = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
255, 255, 255, 255, 255, 111];

BigInt i;

i = buffer[2]  16;
i |= buffer[1]  8;
i |= buffer[0];
i += buffer[3]  24  0;
writeln(i: , i);
}

Do you have any idea how to translate the coding correctly?

Kind regards
André


Re: Template bug with second mixin?

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

I think I mimized the coding too much.
What I actually want to achieve is to generate read methods
in the structure for different data types  (Ubyte, short, int):

I thought the eponymous trick would insert the content of the
enum instead the name itself?

string getReadMethods(string methodName, string dataType)
{
  return dataType~` `~methodName~`(size_t idx) {
return v_arr[idx].get!`~dataType~`; }`;
}

template insertReadMethods(string MethodName, DataType)
{
  enum insertReadMethods = getReadMethods(MethodName, 
DataType.stringof);

}

struct Data
{
mixin insertReadMethods!(readTinyInt, ubyte);
mixin insertReadMethods!(readShortInt, short);
}

void main(){}


Kind regards
André

On Friday, 5 December 2014 at 07:28:26 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 05 Dec 2014 07:06:34 +
Andre via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



Hi,

following coding fails to compile with 2.066.0 and
2.067.0-b1.


This is a bug, or?
source\app.d(9): Error: mixin 
app.Data.insertReadMethods!(readTinyInt, ubyte)

is not defined

template insertReadMethods(string MethodName, DataType)
{
enum insertReadMethods = ;
}

struct Data
{
mixin insertReadMethods!(readTinyInt, ubyte);
mixin insertReadMethods!(readTinyInt, ubyte);
}

void main(){}
i.e. mixin template inserts it's names into the same scope, 
and
compiler searching symbols from innermost scope up to module 
scope.


here first mixin inserts 'enum' member, and searching for 
second mixin
hits that enum member. to avoid things going out of control 
compiler is
not trying to guess what you want but stops with error, giving 
you a

chance to fix the code.




Re: Template bug with second mixin?

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

thanks a lot. That makes sense.

Kind regards
André

On Friday, 5 December 2014 at 09:29:21 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 05 Dec 2014 09:19:27 +
Andre via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



I think I mimized the coding too much.
What I actually want to achieve is to generate read methods
in the structure for different data types  (Ubyte, short, int):

I thought the eponymous trick would insert the content of the
enum instead the name itself?

string getReadMethods(string methodName, string dataType)
{
   return dataType~` `~methodName~`(size_t idx) {
 return v_arr[idx].get!`~dataType~`; }`;
}

template insertReadMethods(string MethodName, DataType)
{
   enum insertReadMethods = getReadMethods(MethodName, 
DataType.stringof);

}

struct Data
{
mixin insertReadMethods!(readTinyInt, ubyte);
mixin insertReadMethods!(readShortInt, short);
}

void main(){}


you musunderstood how mixin templates works. mixin templates 
are more

like macroses than templates per se, so you don't need to assign
anything to enum to get the result. i.e.


string getReadMethods(string methodName, string dataType)
{
   return dataType~` `~methodName~`(size_t idx) {
 return v_arr[idx].get!`~dataType~`; }`;
}

template insertReadMethods(string MethodName, DataType)
{
   /*enum insertReadMethods =*/ // no need to do this
   // do that instead ;-)
   mixin(getReadMethods(MethodName, DataType.stringof));
}

struct Data
{
mixin insertReadMethods!(readTinyInt, ubyte);
mixin insertReadMethods!(readShortInt, short);
}


think about mixin templates as macro definitions which will be 
just

inserted where you instantiated them.




Template bug with second mixin?

2014-12-04 Thread Andre via Digitalmars-d-learn

Hi,

following coding fails to compile with 2.066.0 and
2.067.0-b1.


This is a bug, or?
source\app.d(9): Error: mixin 
app.Data.insertReadMethods!(readTinyInt, ubyte)

is not defined

template insertReadMethods(string MethodName, DataType)
{
enum insertReadMethods = ;
}

struct Data
{
mixin insertReadMethods!(readTinyInt, ubyte);
mixin insertReadMethods!(readTinyInt, ubyte);
}

void main(){}

Kind regards
André


jsnode crypto createHmac createHash

2014-11-28 Thread andre via Digitalmars-d-learn

Hi,

I translate some functionality written in jsnode,
which contains a crypto library.

Although there is some sha256 support in
phobos I think, they do not provide all functionality
I need to translate following two functions.
(Input and output is ubyte[])

Is there a library which supports the methods
similiar (createHmac, update)... ?

function hmac(key, msg) {
  var hash = crypto.createHmac('sha256', key);
  hash.update(msg);
  return new Buffer(hash.digest(), 'binary');
}

function sha256(msg) {
  var hash = crypto.createHash('sha256');
  hash.update(msg);
  return new Buffer(hash.digest(), 'binary');
}

Kind regards
André


Re: jsnode crypto createHmac createHash

2014-11-28 Thread andre via Digitalmars-d-learn

fantastic, thanks a lot.

Kind regards
André

On Friday, 28 November 2014 at 13:09:34 UTC, Daniel Kozák via
Digitalmars-d-learn wrote:

V Fri, 28 Nov 2014 12:46:25 +
andre via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

napsáno:


Hi,

I translate some functionality written in jsnode,
which contains a crypto library.

Although there is some sha256 support in
phobos I think, they do not provide all functionality
I need to translate following two functions.
(Input and output is ubyte[])

Is there a library which supports the methods
similiar (createHmac, update)... ?

function hmac(key, msg) {
   var hash = crypto.createHmac('sha256', key);
   hash.update(msg);
   return new Buffer(hash.digest(), 'binary');
}

function sha256(msg) {
   var hash = crypto.createHash('sha256');
   hash.update(msg);
   return new Buffer(hash.digest(), 'binary');
}

Kind regards
André


I am using  
https://github.com/pszturmaj/phobos/tree/master/std/crypto


attribute length missing in std.array: Appender

2014-11-27 Thread Andre via Digitalmars-d-learn

Hi,

I implement a network protocol and use an Appender!(ubyte[])().
I have following issue. The first three bytes I have to fill,
the following bytes are reserved and must be 0. In this example
the overall header length must be 8.

import std.array: appender;
const HEADER_LENGTH = 8;

auto app = appender!(ubyte[])();
app.put(cast(ubyte)40);
app.put(cast(ubyte)5);
app.put(cast(ubyte)234);
// ... add 5 times 0
// variable length body will follow

In case of dynamic array I can simple set the length to 8.
Appender doesn't have a length attribute.

Is there some other nice D functionaliy I can use?
Maybe some functionality in std.array is missing: app.fill(0, 
HEADER_LENGTH)?

Currently I do a work around with a for loop.

Kind regards
André


Re: attribute length missing in std.array: Appender

2014-11-27 Thread andre via Digitalmars-d-learn

Thanks a lot for the help.

Kind regards
André



On Thursday, 27 November 2014 at 17:29:50 UTC, Marc Schütz wrote:

On Thursday, 27 November 2014 at 16:08:13 UTC, Andre wrote:

Hi,

I implement a network protocol and use an Appender!(ubyte[])().
I have following issue. The first three bytes I have to fill,
the following bytes are reserved and must be 0. In this example
the overall header length must be 8.

import std.array: appender;
const HEADER_LENGTH = 8;

auto app = appender!(ubyte[])();
app.put(cast(ubyte)40);
app.put(cast(ubyte)5);
app.put(cast(ubyte)234);
// ... add 5 times 0
// variable length body will follow

In case of dynamic array I can simple set the length to 8.
Appender doesn't have a length attribute.

Is there some other nice D functionaliy I can use?
Maybe some functionality in std.array is missing: app.fill(0, 
HEADER_LENGTH)?

Currently I do a work around with a for loop.

Kind regards
André


You can initialize the appender with an existing array, or put 
an entire array into it at once:


import std.array: appender;
ubyte[] temp;
temp.reserve(8);  // reserve first, so that only one 
allocation happens

temp[0 .. 3] = [40, 5, 234];
temp.length = 8;
auto app = appender!(ubyte[])(temp);
// or:
app.put(temp);

The array will not be copied when the appender is constructed.




Re: @property method needs ()

2014-11-24 Thread Andre via Digitalmars-d-learn

Thanks a lot for the info.

Kind regards
André

On Monday, 24 November 2014 at 09:26:16 UTC, Marc Schütz wrote:
On Monday, 24 November 2014 at 08:35:08 UTC, ketmar via 
Digitalmars-d-learn wrote:
a known thing. not sure if this is a known *bug* (seems that 
almost
nobody cares). compiler is obviously wrong here (and i believe 
that
it's wrong to accept `()` for properties at all), but i don't 
know if

this will ever be fixed.


There's hope that this will get fixed in the near future:
https://github.com/D-Programming-Language/dmd/pull/2305




@property method needs ()

2014-11-23 Thread Andre via Digitalmars-d-learn

Hi,

in following example the @property method needs the ()
otherwise compiler error  for row 24 is thrown.
I cannot judge, whether the compiler behaves correct or not.

Kind regards
André

---

alias fnError = void delegate(string s);

interface IfSession
{
@property fnError addError();
}

class Session: IfSession
{
private fnError _addError;

@property fnError addError()
{
return _addError;
}
}

void main()
{
auto session = new Session();
session._addError = delegate(s){};

session.addError()(test); // Works
session.addError(test); // Does not work
}


InvalidMemoryOperationError@(0)

2014-11-17 Thread Andre via Digitalmars-d-learn

Hi,

the following coding is an extract from the DGUI library.
On my system (Win 8) I receive InvalidMemoryOperationError@.
I got the information that this Error doesn't not occur on
a WinXP system.

I think there is definetely a bug in the following coding.

The Grid class has a Collection of Rows. Each Row has a Collection
of Cols.
The class Row has a destructor which has an empty foreach over
the Collection of Cols. If I comment this empty foreach no
error is thrown. I assume the class Collection accesses a Col
object which is already destructed?

Does DMD behave correctly (InvalidMemoryOperationError) and
can where in the Collection class exactly the invalid object is
accessed? I tried to find the invalid coding line, but without 
success.


class Collection(T)
{
private T[] _t;

int add(T t)
{
this._t ~= t;
return this._t.length - 1;
}

void clear()
{
this._t.length = 0;
}

T[] get()
{
return this._t;
}

@property int length()
{
return this._t.length;
}

T opIndex(int i) nothrow
{
if(i = 0  i  this._t.length)
{
return this._t[i];
}
assert(false, Index out of range);
}

int opApply(int delegate(ref T) dg)
{
int res = 0;

if(this._t.length)
{
for(int i = 0; i  this._t.length; i++)
{
res = dg(this._t[i]);

if(res)
{
break;
}
}
}
return res;
}
}

class Col {}

class Row
{
private Collection!(Col) _columns;

this()
{
this._columns = new Collection!(Col)();
}

~this()
{
foreach(cp; this._columns)
{   
}
}


Col addColumn()
{
Col cp = new Col();
this._columns.add(cp);
return cp;
}
}

class Grid
{
private Collection!(Row) _rows;

this()
{
this._rows = new Collection!(Row)();
}

@property public Row[] rows()
{
return this._rows.get();
}

Row addRow()
{   
Row rp = new Row();
this._rows.add(rp);
return rp;
}

void clear()
{
_rows.clear();
}
}

void main()
{
auto grid = new Grid();

for(int i=0; i 10; i++)
{
grid.clear();

with(grid.addRow())
{
addColumn();
addColumn();
addColumn();
}
}
}


Get full class name at compile time - Not yet implemented

2014-11-12 Thread Andre via Digitalmars-d-learn

Hi,

I currently have some issues to get the full class name at 
compile time by the variable which might point to null.
With .stringof I get the class name without the module. It seems 
typeid(typeof())

is the solution, but DMD throws the error:

source\app.d(10): Error: typeid(app.A).name is not yet 
implemented at compile t

ime

Do I have any other possibilities?

Kind regards
André

module app;

class A {};

void main()
{
A a;

pragma(msg, typeof(a).stringof); // A
pragma(msg, typeid(typeof(a)).name); // Should print app.A
}


Re: Get full class name at compile time - Not yet implemented

2014-11-12 Thread Andre via Digitalmars-d-learn

perfekt, thanks a lot.

Kind regards
André

On Thursday, 13 November 2014 at 05:37:26 UTC, Rikki Cattermole 
wrote:

On 13/11/2014 6:22 p.m., Andre wrote:

http://dlang.org/phobos/std_traits.html#fullyQualifiedName




Re: Intended behavior or bug (private vs public static)

2014-11-07 Thread Andre via Digitalmars-d-learn

Thanks a lot. I will create a bug report.

Kind regards
André


On Friday, 7 November 2014 at 06:09:02 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:


That looks like a bug. All you have to do is change the order 
of the two
function declarations or rename the non-static one to something 
else, and it
compiles. So, somehow, the fact that the non-static one has the 
same name as
the static one and the fact that it comes first screws up 
accessing the
static one. And explicitly marking the static one as public 
doesn't help.

So, you should report is a compiler bug:

https://issues.dlang.org

- Jonathan M Davis




Re: Issue with WIKI example Win32_DLLs_in_D

2014-10-22 Thread andre via Digitalmars-d-learn

I think there is a bigger issue with the mentioned example.
The command cannot work:
dmd test mydll.lib -g

test.d has an import statement to mydll. mydll has to be included 
in the command. But as mydll not only contains the exported dll 
functions but also DllMain, it cannot be compiled together with 
test which contains the main entry point.


Maybe the example can be corrected.

Kind regards
André

On Tuesday, 21 October 2014 at 21:57:06 UTC, Laeeth Isharc wrote:
Funnily enough I was just playing with this last night trying 
to get Excel to talk to dlang DLL.  I borrowed a C example 
elsewhere on web and used a different .def file.  Something 
like this:


LIBRARY dprop
DESCRIPTION 'My DLL written in D'

EXETYPE NT
CODEPRELOAD DISCARDABLE
DATAWRITE

EXPORTS
useArray = useArray
usemyTest = usemyTest

Where the two functions exported from D to excel were as above.
 Try that and let me know.  If that doesn't work I will send 
you a link to from repository.





Issue with WIKI example Win32_DLLs_in_D

2014-10-21 Thread Andre via Digitalmars-d-learn

Hi,

by copy and paste the example from
http://wiki.dlang.org/Win32_DLLs_in_D
exactly as described, the following errors is thrown:

J:\Projects\Tests\Exampledmd test mydll.lib -g
OPTLINK (R) for Win32  Release 8.00.15
test.obj(test)
 Error 42: Symbol Undefined _D5mydll12__ModuleInfoZ

I created a batch program which executes the commands
as described on the wiki page:

dmd -c mydll -g
dmd mydll.obj mydll.def -g -L/map
C:\D\dmd2\windows\bin\implib /noi /system mydll.lib mydll.dll
dmd test mydll.lib -g

Could you check whats wrong with the example and maybe update the 
WIKI page?

Thanks.

Kind regards
André


__traits(getMember) works only the second time

2014-10-10 Thread andre via Digitalmars-d-learn

Hi,

by executing the example source code,
following output is returned:

Reference: Child
false
true

At first childStr is not found, then it is found?
Is this a bug?

Kind regards
André

-

module app;

import test;

class Child : Parent
{
  mixin ComponentTemplate;
  @property string childStr(){return ;}
}

void main()
{
  auto child = new Child();
  child.getParameters();
}

-

module test;

template Params(this MyType)
{
  string[] Params()
  {
pragma(msg, Reference:  ~ MyType.stringof);
pragma(msg, is(typeof(__traits(getMember, MyType, 
childStr;
pragma(msg, is(typeof(__traits(getMember, MyType, 
childStr;

return [];
  }
}

mixin template ComponentTemplate()
{
  private enum parameters = Params!(typeof(this));

  string[] getParameters()
  {
return parameters;
  }
}

class Parent
{
  @property string parentStr(){return ;}
}





Re: __traits(getMember) works only the second time

2014-10-10 Thread andre via Digitalmars-d-learn
I use the syntax is(typeof(__traits(getMember, MyType, 
childStr))) to check whether a member is public visible or 
not. (The example above is only a reduced example)


By the way hasMember works correctly.
I will file an issue.

Kind regards
André

On Friday, 10 October 2014 at 07:25:28 UTC, Rikki Cattermole 
wrote:

On 10/10/2014 8:08 p.m., andre wrote:




Wrong trait for the job. Use hasMember instead.
Although interesting use case. Could be a bug somewhere in 
there.




(this MyType) automatic deduction?

2014-10-08 Thread andre via Digitalmars-d-learn

Hi,

could you check whether it is correct, that second line in main
failes with a compiler error?
I think the compiler should be able to deduce the type without
explicitly passing it to the method call.

Kind regards
André

template ClassTemplate()
{
  static auto deserialize(this MyType)()
  {
return new MyType();
  }
}

class A
{
  mixin ClassTemplate;
}

void main()
{
  A a = A.deserialize!A(); // Working
  A b = A.deserialize(); // Not working
}

source\app.d(17): Error: template 
app.A.ClassTemplate!().deserialize cannot dedu

ce function from argument types !()(), candidates are:
source\app.d(3):app.A.ClassTemplate!().deserialize(this 
MyType)()


(this MyType) and interface: Symbol undefined

2014-10-08 Thread andre via Digitalmars-d-learn

Hi,

please consider following example. I want to acces class B by 
interface I.

Method work should print the actual class (B).

The linker say:
 Error 42: Symbol Undefined _D3app1I17__T4workTC3app1IZ4workMFZv

Is this is missing feature or even a bug?
Is there any other way to get the actual class (B) printed
by the inherited method from A?

Kind regards
André

interface I
{
void work(this MyType)();
}

class A : I
{
void work(this MyType)()
{
import std.stdio;
writeln(MyType.stringof);
}
}

class B : A {}

void main()
{
I i = new B();
i.work(); // Expected output: B
}


Re: (this MyType) automatic deduction?

2014-10-08 Thread andre via Digitalmars-d-learn

Thanks a lot for the helpful explanation.

Kind regards
André

On Wednesday, 8 October 2014 at 21:10:02 UTC, anonymous wrote:

On Wednesday, 8 October 2014 at 10:36:33 UTC, andre wrote:

Hi,

could you check whether it is correct, that second line in main
failes with a compiler error?
I think the compiler should be able to deduce the type without
explicitly passing it to the method call.

Kind regards
André

template ClassTemplate()
{
 static auto deserialize(this MyType)()
 {
   return new MyType();
 }
}

class A
{
 mixin ClassTemplate;
}

void main()
{
 A a = A.deserialize!A(); // Working
 A b = A.deserialize(); // Not working
}

source\app.d(17): Error: template 
app.A.ClassTemplate!().deserialize cannot dedu

ce function from argument types !()(), candidates are:
source\app.d(3):
app.A.ClassTemplate!().deserialize(this MyType)()


As far as I can tell, 'this' parameters don't work with static
methods. You can use typeof(this) instead:


template ClassTemplate()
{
   static auto deserialize()
   {
 return new typeof(this)();
   }
}

class A
{
   mixin ClassTemplate;
}

void main()
{
   A b = A.deserialize();
}


Be aware of the difference between template 'this' parameters 
and

typeof(this). A 'this' parameter is set to the (static) type of
the object, while typeof(this) is always the type of the
surrounding class.


class A
{
   import std.stdio;
   void printTypeofThis() {writeln(typeof(this).stringof);}
   void printThisParameter(this T)() {writeln(T.stringof);}
}

class B : A {}

void main()
{
   auto b = new B;
   b.printTypeofThis(); /* A, because the method is in A */
   b.printThisParameter(); /* B, because b is a B 
(statically) */

   A a = b;
   a.printThisParameter(); /* A, because a is an A 
(statically)

*/
}





Re: Curl - Set cookie value

2014-10-06 Thread andre via Digitalmars-d-learn
I found out the real issue. Using addRequestHeader also works for 
cookies, but there is an issue with HTTP attribute 
responseHeaders.
As this attribute is an associative array (string[string]) it 
contains only 1 value for 1 key.
In case there are several HTTP keys with the same name, it only 
contains the last value.

Example:

set-cookie = A; path=/; HttpOnly
set-cookie = B; path=/; HttpOnly
content-type = text/plain

reponseHeaders[set-cookie] contains only the seccond value.
To work around this issue you have to react on onReceiveHeader
and catch the values there.

Kind regards
André

On Monday, 6 October 2014 at 06:43:58 UTC, andre wrote:

Hi,

from a GET request I receive an value set-cookie in the 
reponse header. The value from set-cookie I have to provide 
as cookie value for the next post request. CURL provides a 
command line command

  --cookie USER_TOKEN=Yes

In the std.net.curl HTTP API, there is no possibility to set a 
cookie value.


Could you check?

Kind regards
André




Re: isCallable is not an expression

2014-09-25 Thread andre via Digitalmars-d-learn

Thanks a lot.

Kind regards
André


isCallable is not an expression

2014-09-24 Thread andre via Digitalmars-d-learn

Hi,
following code throws an error when I uncomment method 
getPropertyDuplicate.
getPropertyDuplicate is just a copy of getProperty except the 
method name.


Why these errors are thrown?

C:\D\dmd2\windows\bin\..\..\src\phobos\std\traits.d(1257): Error: 
isCallable!(ge

tPropertyDuplicate) is not an expression
source\app.d(25):while looking for match for 
functionAttributes!(getProp

ertyDuplicate)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\traits.d(1257): Error: 
template insta
nce std.traits.isCallable!(getPropertyDuplicate) error 
instantiating
source\app.d(11):instantiated from here: 
functionAttributes!(getProperty

Duplicate)
source\app.d(11):while looking for match for 
functionAttributes!(getProp

ertyDuplicate)

Kind regards
André

template MyTemplate()
{
	import std.traits : isSomeFunction, functionAttributes, 
FunctionAttribute, ReturnType;


string[] getPropertyNames()
{
string[] result;
foreach(m;__traits(allMembers, typeof(this)))
{
			static if (isSomeFunction!(__traits(getMember, typeof(this), 
m))
			   functionAttributes!(__traits(getMember, typeof(this), m)) 
 FunctionAttribute.property)

{
result ~= m;
}
}
return result;
}

/*string[] getPropertyDuplicate()
{
string[] result;
foreach(m;__traits(allMembers, typeof(this)))
{
			static if (isSomeFunction!(__traits(getMember, typeof(this), 
m))
			   functionAttributes!(__traits(getMember, typeof(this), m)) 
 FunctionAttribute.property)

{
result ~= m;
}
}
return result;
}*/
}

class A {
mixin MyTemplate;
}

void main() {
auto a = new A();
}


Re: with (auto p = new ...)

2014-09-24 Thread Andre via Digitalmars-d-learn

Enhancement 13526 filed:
https://issues.dlang.org/show_bug.cgi?id=13526



with (auto p = new ...)

2014-09-23 Thread Andre via Digitalmars-d-learn

Hi,

I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:

with (auto p = new Panel())
{
parent = this;
text = bla;
with (auto b = new Button())
{
parent = p; // Here p is needed
text = bla2;
}
}

source\app.d(8): Error: expression expected, not 'auto'
source\app.d(8): Error: found 'p' when expecting ')'
source\app.d(8): Error: found '=' instead of statement
...

Kind regards
André


Re: with (auto p = new ...)

2014-09-23 Thread andre via Digitalmars-d-learn
Yes, that is also working. As far as I remember (only my tablet 
currently available) also this works:


Panel p;
with(p = new Panel ()) {}

Therefore it seems strange,the same does not work with auto.

Kind regards
André


On Tuesday, 23 September 2014 at 19:49:22 UTC, Graham Fawcett 
wrote:

Sorry, I sent that last message before I intended to.

How about:

 auto b = new Button(); with (b) {
   ...
 }

'b' is explicitly outside of the scope of the 'with' block, 
which may not be what you intended. But you could use more 
braces to add an extra level of scope if that's an issue:


...
text = blah;
{
   auto b = new Button(); with (b) {
   ...
   }
}
// b is no longer in scope

Graham




On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:

Hi,

I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:

with (auto p = new Panel())
{
parent = this;
text = bla;
with (auto b = new Button())
{
parent = p; // Here p is needed
text = bla2;
}
}

source\app.d(8): Error: expression expected, not 'auto'
source\app.d(8): Error: found 'p' when expecting ')'
source\app.d(8): Error: found '=' instead of statement
...

Kind regards
André




alias this cast

2014-09-11 Thread andre via Digitalmars-d-learn

Hi,

I am 80% sure, the failing assertion is correct but please have a 
look.

Second assertion fails.

Kind regards
André

class A{}

class B{}

class C : B
{
A a;
alias a this;

this()
{
a = new A();
}
}

void main()
{
B b = new C();

// OK
assert(cast(C)b);

// fails
assert(cast(A)b);   
}


Re: alias this cast

2014-09-11 Thread andre via Digitalmars-d-learn
I am not sure. b is C but everything not in super class B is 
hidden.

Using cast I can cast b to a full C.

The cast cast(C)b has the same information about b like the 
cast cast(A)b: The memory area of b knows compatitibility to C 
and also the alias.


For me, using alias this, the object b has 3 represenations: A, B 
and C. It is a matter of steps.


Kind regards
André

On Thursday, 11 September 2014 at 11:53:30 UTC, Daniel Kozak via 
Digitalmars-d-learn wrote:

V Thu, 11 Sep 2014 11:40:05 +
andre via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

napsáno:


Hi,

I am 80% sure, the failing assertion is correct but please 
have a look.


No it is not

assert(cast(A)cast(C)b); // this is OK

b is B so it does not know about having alias to A;


Second assertion fails.

Kind regards
André

class A{}

class B{}

class C : B
{
A a;
alias a this;

this()
{
a = new A();
}
}

void main()
{
B b = new C();

// OK
assert(cast(C)b);

// fails
assert(cast(A)b);   
}




Re: DUB: link to local library

2014-09-10 Thread andre via Digitalmars-d-learn
Dub command line supports something like Dub add-local. Then you 
can use the package directly.


Kind regards
Andre

On Wednesday, 10 September 2014 at 15:40:11 UTC, Edwin van 
Leeuwen wrote:

On Wednesday, 10 September 2014 at 13:40:16 UTC, rcor wrote:

dub.json contains what I think should do the same as above:
{
 name: test,
 importPaths: [ext/dallegro5],
 lflags: [-Lext/dallegro5]
}


Does adding:

libs: [dallegro5]

make a difference?

Cheers, Edwin




Re: dgui - Button continually repainting

2014-09-09 Thread andre via Digitalmars-d-learn

Hi,

Just checked, on WM_PAINT all event listeners (event paint) are 
called.


Overwriting onPaint seems to work better (issue 18 in dgui 
bitbucket site). Please file this issue also on the dgui bibucket 
home page.


Kind regards
Andre


On Tuesday, 9 September 2014 at 10:50:11 UTC, Mike James wrote:

Hi.

I've created a graphic button as per this example on the dgui 
website:


import dgui.all;

class MyForm: Form
{
this()
{
text = An Exception was thrown...;
size = Size(130, 100);

// Or use `Bitmap.fromFile`:
auto img = new Bitmap(90, 15, SystemColors.yellow);
auto pen = SystemPens.blackPen;

with(new Button())
{
bounds = Rect(10, 10, 100, 25);
parent = this;
paint.attach((s, e)
{
e.canvas.drawImage(img, 5, 5);
e.canvas.drawLine(pen, 5, 10, 95, 10);
e.canvas.drawLine(pen, 10, 5, 10, 20);
});
}
}
}

int main()
{
return Application.run(new MyForm());
}

and added a writeln(paint) in the paint.attach to show when 
the button is repainting. When the form with the button is 
visible the button is being continually repainted. Is this a 
'feature' of dgui or is there a flag to set to only re-paint 
when the button is invalidated?


Regards, -=mike=-.




dgui - self defined components with double buffering

2014-09-09 Thread andre via Digitalmars-d-learn

Hi,
I habe several self defined components in my Windows.
During resizing of the Windows, the Windows controls
gets ugly and then disappear. I want to implement
double buffering but found no obvious way to create
a memory canvas and after having done the drawing copying
It to the canvas of the control.

Current implementation looks this:

class TitleBox : PictureBox
{
private Color startColor_ = SystemColors.darkGray;
private Color endColor_ = SystemColors.white;

protected override void onPaint(PaintEventArgs e)
{
   Canvas c = e.canvas;
   c.fillRectGradient(Rect(nullPoint, this.size), 
startColor_, endColor_, GradientFillRectMode.vertical);

   c.drawText(text, Rect(Point(2,2), this.size));

   super.onPaint(e);
}
}

Does anyone have an idea?

Kind regards
André


User defined forward range - foreach initializes f.r.

2014-06-13 Thread Andre via Digitalmars-d-learn

Hi,

I have a template class List which should provide generic list 
functionality. In my use case, using a class instead a struct

is more comfortable.

Following unittest fails, although the forward range
implements the save method.

unittest
{
auto intList = new List!int(1,2,3);
assert(intList.length == 3);
foreach(item; intList) {}
assert(intList.length == 3);
}


class List(T)
{
private T[] items;

this(T[] items...)
{
this.items = items;
}

bool empty() const
{
return items.length == 0;
}

@property int length() const
{
return items.length;
}

void popFront()
{
items = items[1..$];
}

@property List!T save() const
{
return new List!T( cast(T[]) items);
}

T front() const
{
return opIndex(0);
}

T opIndex(size_t index) const
{
return cast(T) items[index];
}
}

I already tried different thinks, like using dup or importing std.array.
But nothing helps, the unittest fails.
Why it fails?

Kind regards
André


Re: User defined forward range - foreach initializes f.r.

2014-06-13 Thread Andre via Digitalmars-d-learn

Am 13.06.2014 20:22, schrieb H. S. Teoh via Digitalmars-d-learn:

[...]

Generally, it's a bad idea to conflate a container with a range over its
contents. In this sense, built-in arrays are a very bad example, because
they show precisely this sort of conflation. But they get away with it
because of their hybrid value/reference semantics. Most containers,
however, don't have this sort of complex semantics, so they don't mix
very well with ranges directly.

It's much better to separate the container from a range over its
contents. So I wouldn't put the range API methods in the List class, but
implement an opSlice method that returns a struct that performs the list
iteration, that implements the range API. This allows you to write:

auto myList = new List(...);
foreach (item; myList[]) { // N.B., myList[] calls myList.opSlice()
...
}

Since the range struct returned by opSlice is separate from the
container itself, you don't have any risk of iteration also consuming
the container.


T



Thank you, this information is really helpful.

Kind regards
André



Issue with contracts and assertions

2014-05-23 Thread Andre via Digitalmars-d-learn

Hi,

for the attached code I noticed some strange behaviors.
I compile the programm with: dmd main -unittest
The expected assertion of the method c pre condition is
not raised.
It is only raised if class A not implements interface I.

On the otherside the commented assertion in the invariant is working
fine.

Is this a bug?

Kind regards
André


interface I {
void c();
}

class A : I {
invariant() {
//assert(false, Assert INVARIANT); // Working
}

void c()
in {
assert(false, Assert IN);
}
body {

}
}

unittest {
A a = new A();
a.c();
}

void main(){}


Re: Issue with contracts and assertions

2014-05-23 Thread Andre via Digitalmars-d-learn

Am 23.05.2014 16:34, schrieb Rene Zwanenburg:

On Friday, 23 May 2014 at 13:45:07 UTC, Andre wrote:

Hi,

for the attached code I noticed some strange behaviors.
I compile the programm with: dmd main -unittest
The expected assertion of the method c pre condition is
not raised.
It is only raised if class A not implements interface I.

On the otherside the commented assertion in the invariant is working
fine.

Is this a bug?

Kind regards
André


interface I {
void c();
}

class A : I {
invariant() {
//assert(false, Assert INVARIANT); // Working
}

void c()
in {
assert(false, Assert IN);
}
body {

}
}

unittest {
A a = new A();
a.c();
}

void main(){}


I'm not sure. An implementation shouldn't be allowed to have stricter
pre-conditions than it's base class or interface. On the other hand it
should be able to relax them.


In case there is a reason that the assertion is not run,
if feels very dangerous for me that all assertions can be
disabled by mistake just by adding an interface to a class.

At least a compiler messsage should be thrown to warn about
useless assertions

Kind regards
André



Re: Issue with contracts and assertions

2014-05-23 Thread Andre via Digitalmars-d-learn

Am 23.05.2014 16:44, schrieb Rene Zwanenburg:

On Friday, 23 May 2014 at 14:38:27 UTC, Andre wrote:

Am 23.05.2014 16:34, schrieb Rene Zwanenburg:
In case there is a reason that the assertion is not run,
if feels very dangerous for me that all assertions can be
disabled by mistake just by adding an interface to a class.

At least a compiler messsage should be thrown to warn about
useless assertions

Kind regards
André


I completely agree. A quick search on the issue tracker shows there are
some serious bugs involving in contracts and interfaces[0]. It's
probably best to keep away from them until the situation improves.

[0]:
https://issues.dlang.org/buglist.cgi?quicksearch=in%20contract%20interface


): I found my issue: https://issues.dlang.org/show_bug.cgi?id=12321

I just think about whether it is possible to build a contracts library
similiar to C4J (Contracts 4 Java).
I like the classed based approach.

Kind regards
André


Array of interface only with cast()?

2014-04-22 Thread Andre via Digitalmars-d-learn

Hi,

I just stumbled about this issue with array of interface. I want
to pass several objects (C and D) which shares the same interface A.
It seems somehow cumbersome that it only works if there is a cast on
the first element of the array.

interface A{}

class B: A{}

class C: B{};
class D: B{};

void main()
{
//A[] arr = [new C(), new D()]; // Does not work
A[] arr = [cast(A) new C(), new D()]; // Does work
}

Is the cast really needed?

Kind regards
André


Re: Array of interface only with cast()?

2014-04-22 Thread Andre via Digitalmars-d-learn

Am 22.04.2014 17:23, schrieb Andrej Mitrovic:

On Tuesday, 22 April 2014 at 15:19:55 UTC, Andre wrote:

Is the cast really needed?


It's a known issue and a filed bug report. I don't have the Issue number
at hand though, someone else will likely provide it.


Nice to hear that it is not by design but will be fixed.
Thanks a lot.

Kind regards
André