Re: Associative array of const items

2016-07-01 Thread QAston via Digitalmars-d-learn

On Thursday, 30 June 2016 at 17:08:45 UTC, Jonathan Marler wrote:
Is there a way to have an associative array of const values? I 
thought it would have been:


const(T)[K] map;
map[x] = y;

but the second line gives Error: cannot modify const 
expression.  I would think that the const(T)[K] would behave 
similarly to const(T)[], where you can modify the array, just 
not the individual elements, but associative arrays don't seem 
to have the same semantics.  Is there a way to achieve these 
semantics with an associative array?


You can use std.typecons.Rebindable!(const T)[K].


Re: Cast vs Virtual Method vs TypeId?

2016-06-30 Thread QAston via Digitalmars-d-learn

On Thursday, 30 June 2016 at 00:25:53 UTC, Jonathan Marler wrote:
I'd like to hear peoples thoughts on the various solutions for 
the following problem.  Say you have some hierarchy of classes 
like:


class GameObject {
  // ...
}
class Entity : GameObject {
  // ...
}
class Player : Entity {
  // ...
}
class Enemy : Entity {
  // ...
}
// ...

Assume you have a function that accepts a GameObject but does 
something special if that GameObject happens to be an instance 
of the Player class. How would you go about determining this? 
(Note: assume you need to make the distinction at runtime, so 
you can't use a static if with an 'is' expression inside a 
template.)


I'd like to hear what people think in 2 cases
  1) Only need to know if it's an instance of the Player class.
  2) Need to know if it's an instance of the Player class AND 
need an instance of the Player class.


The potential solutions I thought of were:

1) typeid (Only handles case 1)

if(typeid(obj) == typeid(Player) {
  // treat as player object
}

If you don't need an instance of the Player class, maybe this 
one is good? I don't know in terms of efficiency if this is 
better, or casting is better.  Maybe cast uses the typeid under 
the hood to determine if the cast can be performed?


2) Custom Type Enum (Only handles case 1)

enum GameObjectType {
  gameObject, player, ...
}
class GameObject {
  GameObjectType type;
}

if(obj.type == GameObjectType.player) {
  // treat it as a player object
  // Note: if you need to use Player class specific fields
  //   then you'll need to use the cast or virtual function
  //   design which kinda defeats the purpose of this 
design in the

  //   case where it is actually a Player object.
}

This method may be similar to the typeid method, not sure since 
I don't know how typeid works under the hood.  If it's similar 
then this would just be a waste of memory and should not be 
used in favor of the typeid method.


3) Cast (Handles case 1 and 2)

auto player = cast(Player)obj;
if(player) {
  // treat it as a player object
}

I don't know how cast works under the hood so it's hard to 
compare it to other methods.  Any information on how cast works 
under the hood would be great.


4) Virtual Method (Handles case 1 and 2)

class GameObject {
  Player asPlayer() { return null; }
}
class Player {
  override Player asPlayer() { return this; }
}

auto player = obj.asPlayer;
if(player) {
  // treat it as a player object
} else {
  // treat it as any other game object
}

This solution handles the same cases as regular casting, but I 
can't compare them since I don't know how casting works under 
the hood.  One thing to consider is that this method scales 
linearly since you need to add a new virtual method for every 
type you want to support, so the vtable gets larger as you add 
more types.



Any other solutions? Thoughts?  Thanks in advance for the 
feedback.


This problem is not D specific, there are lots of different 
approaches.
If you're not going to add new types to the hierarchy very often 
the visitor pattern is a good choice, see[1]. You can also use 
composition instead of inheritance to share code by using mixins 
+ templates. Or you can try more traditional 
entity-component-systems.


Take a look at game engines written in D, they may have some good 
D specific ideas already.


http://www.deadalnix.me/2012/08/25/visitor-pattern-revisited-in-d/


Re: mutable keyword

2016-05-19 Thread QAston via Digitalmars-d-learn

On Thursday, 19 May 2016 at 20:44:54 UTC, ciechowoj wrote:
Is there D equivalent of C++'s mutable keyword? Like the one 
that allows to modify a field of struct from constant method. 
Or some alternative solution?


There isn't an equivalent of mutable keyword because D const 
differs from C++ const. D const has stronger guarantees (nothing 
reachable from const object will be mutable) so you'll use it 
less often compared to C++.


There's a talk on usage of const in D and I think its author also 
wrote on the subject:

https://www.youtube.com/watch?v=mPr2UspS0fE


Re: GC allocation

2016-04-21 Thread QAston via Digitalmars-d-learn

On Thursday, 21 April 2016 at 17:27:09 UTC, Alex wrote:
Ok. So, does this mean, that they just allocate on 
creation/binding them? If so, there is no problem and there are 
no questions any more.


Just like classes - when closure expression is executed.

I have an unusual caption... On creation I capture an immutable 
id for my delegates, which are stored in an array. Indeed, the 
id of the delegate is just the position of it in its array.
Then, I call my delegate as a function with a parameter, 
depending on it, the call is delegated to another objects (with 
the stored id, of course :) )
Another possibility, which I could imagine is: not to store the 
id and let the delegate calculate it by some pointer arithmetic 
from the array wherein it is stored. Then, no independent data 
would be stored at all. This would assume however, that 
different function pointers won't be merged, although the one 
and only distinction between them would be the fact of storing 
them at different array indices.


Instead of using a delegate you can use a Struct with opCall. 
Pass what you want to copy to the struct by using a constructor 
and put your function code in opCall method.


An example here:

https://github.com/QAston/transducers-dlang/blob/master/source/transduced/transducers.d#L797

you can see there various variants of doing the same operation, 
using closure, function and struct.





Re: GC allocation

2016-04-21 Thread QAston via Digitalmars-d-learn

On Thursday, 21 April 2016 at 15:22:15 UTC, Alex wrote:

Hi all!
timing my program with valgrind/cachegrind and using -vgc 
option of the compiler found the message:

"using closure causes GC allocation"

The question is:
does the usage of the closure causes the GC allocation on every 
usage of the closure or only on creation/assigning of it? If 
the former, why?


I'm not sure, if the context of my problem (say: context of the 
closure) is relevant, but have some thoughts about and a 
working implementation of it, so if any information is needed, 
just give me a sign.


Thanks in advance :)


Closure (delegate type) objects have to allocate because they're 
reference types and have state. For stateful reference types to 
be safe they have to be put on the GC allocated heap.


In other words - closures work just like classes. The allocation 
is done for each instance of closure you create and stores the 
variables you captured from the stack. When you don't capture you 
can use plain functions which don't use GC.


See also:
https://dlang.org/spec/function.html#closures


Re: How to be more careful about null pointers?

2016-03-29 Thread QAston via Digitalmars-d-learn

On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote:
I finally found the null pointer. It took a week. I was 
assigning "db = db" when I should have been assigning "this.db 
= db". Terrible, I know. But...


I invoked db.find_chapter.bindAll(8,4), when db was a null 
pointer. There was no null pointer error. No exception raised 
for dereferencing a null. I'm not in release mode. Assertions 
are enabled. Shouldn't that have raised a null pointer 
exception?


Instead, it accesses db as if db were not null, producing a 
garbage structure in find_chapter, which bindAll chokes on, 
then causes the whole program to segfault.


I realize enforce(db).find_chapter would work, but... I thought 
D was more careful about null pointers? At least enough to die 
on dereferencing them?


You can use a lint to warn you about silly mistakes, check out 
dscanner and possibly others.


Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn

On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote:

Hi all,
  I've found discussions, but not an actual "recommended" 
solution for the problem of "statement is not reachable" 
warnings in templates with early returns, e.g.:

```
bool nobool(T...)() {
foreach (i, U; T) {
static if (is(U == bool)) {
return false;
}
}
return true;  // emits "Warning: statement is not reachable"
}

[...]


On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote:
import std.meta;
template isBool(U)() = is(U == bool);
static if (!allSatisfy!(isBool, T)) {
return true;  // no longer emits a warning
}

Something like this should work.


Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn

On Wednesday, 16 March 2016 at 17:08:20 UTC, Johan Engelen wrote:

On Wednesday, 16 March 2016 at 11:47:35 UTC, QAston wrote:


import std.meta;
template isBool(U)() = is(U == bool);
static if (!allSatisfy!(isBool, T)) {
return true;  // no longer emits a warning
}

Something like this should work.


Thanks, but:

On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen 
wrote:
(I have heavily simplified the real-world code, please don't 
discuss alternative solutions to the "is(U==bool)" in 
particular. For sake of argument, assume that the predicate is 
a complicated beast.)


This method will work regarless of the predicate, just check if 
the predicate isn't matched for the whole array using 
allSatisfy/anySatisfy.


Re: alias template parameter

2016-01-23 Thread QAston via Digitalmars-d-learn

On Friday, 21 June 2013 at 14:08:43 UTC, Sergei Nosov wrote:

Hi!

I've been thinking about how alias template parameters work and 
I'm really confused =)


It makes perfect sense for literals, names, etc. But what I 
can't get is how does it work for delegates.


If I have a function
auto apply(alias fun, T...)(T args)
{
return fun(args);
}

And then I have
int y = 2;
apply!(x => y)(1);

How in the world does this work? Is the context address known 
at compile-time?


y is allocated on the heap and the pointer is implicitly passed 
to the apply, or is a field of a struct if you use map!(x => y) 
instead.


Re: Partial application of compile time args type deduction

2016-01-20 Thread QAston via Digitalmars-d-learn

On Wednesday, 20 January 2016 at 00:50:49 UTC, Ali Çehreli wrote:

On 01/19/2016 04:22 PM, QAston wrote:

[...]


Is this it? If so, is it already in std.functional? (I could 
not find it. :) )


auto appendMapped(alias f, R, T)(R r, T elem) {
r ~= f(elem);
return r;
}

int minus(int i) {
return -i;
}

unittest {
int[] ar;

template bindFirstParam(alias original, alias func, 
Args...) {

auto bindFirstParam(Args...)(Args args) {
return original!(func, Args)(args);
}
}

alias appendMinus = bindFirstParam!(appendMapped, minus);

assert (appendMinus!(int[], int)(ar, 10) == [-10]); // 
compiles

assert (appendMinus(ar, 10) == [-10]); // doesn't compile
}

void main() {
}

Ali


Works, thanks!



Re: Overload dispatch by templated interface type doesn't seem to work

2016-01-20 Thread QAston via Digitalmars-d-learn

On Wednesday, 20 January 2016 at 14:01:23 UTC, QAston wrote:
To me this suggests that the dispatch by templated interface 
type Visitor!(RETURN) doesn't work. IMO the order of interfaces 
shouldn't matter here and the code should simply work.


Any ideas?


I'm on 2069.2 and when i remove one of the offending classes 
(Print or Eval) class the other compiles and works.


Overload dispatch by templated interface type doesn't seem to work

2016-01-20 Thread QAston via Digitalmars-d-learn

Hi,

I have the following code:

interface Visitable(RETURN) {
RETURN accept(Visitor!RETURN);
}

interface Exp :  Visitable!string,  Visitable!int {

}

interface Visitor(RETURN) {
RETURN visitLit(Lit e);
RETURN visitAdd(Add e);
}

class Lit : Exp {
int val;
this(int val) {
this.val = val;
}
override int accept(Visitor!int v) {
return v.visitLit(this);
}
override string accept(Visitor!string v) {
return v.visitLit(this);
}
}
class Add : Exp {
Exp lhs, rhs;
this(Exp lhs, Exp rhs) {
this.lhs = lhs;
this.rhs = rhs;
}
override int accept(Visitor!int v) {
return v.visitAdd(this);
}
override string accept(Visitor!string v) {
return v.visitAdd(this);
}
}

class Eval : Visitor!int {
override int visitLit(Lit e) {
return e.val;
}
override int visitAdd(Add e) {
return e.lhs.accept(this) + e.rhs.accept(this);
}
}

class Print : Visitor!string {
override string visitLit(Lit e) {
return to!string(e.val);
}
override string visitAdd(Add e) {
		return "(" ~ e.lhs.accept(this) ~ " + " ~ e.rhs.accept(this) ~ 
")";

}
}

unittest {
auto val = new Add(new Lit(1), new Lit(6)).accept(new Eval());
assert(val == 7);
auto s = new Add(new Lit(1), new Lit(6)).accept(new Print());
assert(s == "(1 + 6)");
}

Which is a dummy AST. It's an example of a visitor pattern. The 
compiler gives the following error for this code:


 Error: function Visitable!string.Visitable.accept 
(Visitor!string) is not callable using argument types (Eval)
 Error: function Visitable!string.Visitable.accept 
(Visitor!string) is not callable using argument types (Eval)


in Eval.visitAdd.

When i swap the order of implemented interfaces in Exp, there's a 
symmetrical error in Print.visitAdd with Visitor!int.


To me this suggests that the dispatch by templated interface type 
Visitor!(RETURN) doesn't work. IMO the order of interfaces 
shouldn't matter here and the code should simply work.


Any ideas?


Partial application of compile time args type deduction

2016-01-19 Thread QAston via Digitalmars-d-learn

Hi,

I have the following code:

auto appendMapped(alias f, R, T)(R r, T elem) {
r ~= f(elem);
return r;
}

int minus(int i) {
return -i;
}

unittest {
int[] ar;
// here I do partial application of minus function
alias appendMinus(S,T) = appendMapped!(minus, S, T);
assert (appendMinus!(int[], int)(ar, 10) == [-10]); // compiles
assert (appendMinus(ar, 10) == [-10]); // doesn't compile
}

Which gives me following error:
Error: template transduced.__unittestL111_2.appendMinus cannot 
deduce function from argument types !()(int[], int), candidates 
are:  transduced.__unittestL111_2.appendMinus(S, T)


Is there a way to do partial template arg application which does 
template type deduction correctly?


Re: Partial application of compile time args type deduction

2016-01-19 Thread QAston via Digitalmars-d-learn

On Wednesday, 20 January 2016 at 00:12:16 UTC, Ali Çehreli wrote:

On 01/19/2016 03:37 PM, QAston wrote:

Hi,

I have the following code:

auto appendMapped(alias f, R, T)(R r, T elem) {
 r ~= f(elem);
 return r;
}

int minus(int i) {
 return -i;
}

unittest {
 int[] ar;
 // here I do partial application of minus function
 alias appendMinus(S,T) = appendMapped!(minus, S, T);
 assert (appendMinus!(int[], int)(ar, 10) == [-10]); // 
compiles

 assert (appendMinus(ar, 10) == [-10]); // doesn't compile
}

Which gives me following error:
Error: template transduced.__unittestL111_2.appendMinus cannot 
deduce

function from argument types !()(int[], int), candidates are:
transduced.__unittestL111_2.appendMinus(S, T)

Is there a way to do partial template arg application which 
does

template type deduction correctly?


I don't know whether it's possible with 'alias' but the 
following trivial wrapper works:


auto appendMinus(S,T)(S s, T t) {
return appendMapped!minus(s, t);
}

Ali


I think I've reduced my case too much: the wrapper needs to be 
generic so that I can do something like this (basically a closure 
but compile time)


void wrapper(minus) {
alias appendMinus(S,T) = appendMapped!(minus, S, T);
assert (appendMinus(ar, 10) == [-10]);
}

Anyway, thanks for help Ali, love your book:)


Re: Theoretical Best Practices

2015-08-14 Thread QAston via Digitalmars-d-learn

On Friday, 14 August 2015 at 09:21:56 UTC, DarthCthulhu wrote:
I only want to access the logger object when the program is 
compiled with the -debug option, so I don't want to pass it 
along to the object constructor or set a member as a reference 
to it (which is both tedious and pointless if not in -debug 
mode). The simple solution is to make the Logger class a 
singleton (can D do singletons? I presume it's possible, but I 
haven't really looked into it), but is there a means in D that 
is considered a better way to do this?


D can do singletons, the regular java/c# way, or you can just 
have an object on a module level.


You can also debug{} the field.


Re: How to run opengl tutorials

2015-08-08 Thread QAston via Digitalmars-d-learn

On Sunday, 2 August 2015 at 10:04:54 UTC, nikolai wrote:
Yes, I was so excited about Dlang that i forgot to paste the 
error:

Here's the link to imagescreen http://prntscr.com/7zwe6h


Can't help you with your problem, but I have another tip:

Shift-right-click inside a dir- open cmd window here is going to 
save you some cd-ing.


Re: Array start index

2015-08-04 Thread QAston via Digitalmars-d-learn

On Monday, 3 August 2015 at 21:32:05 UTC, DLearner wrote:
Looks like 0-base is fixed, to avoid problems with existing 
code.


But nothing stops _adding_ to the language by allowing
int[x:y] foo to mean valid symbols are foo[x], foo[x+1],..., 
foo[y].
Plus rule that int[:y] means valid symbols are foo[1], 
foo[2],..., foo[y].


That way, 1-start achieved, with no conflict with existing code?


There're quite a few things stopping this from being added to the 
language.


1. People will have to learn this new feature and it's 
interaction with gazillion of other D features.


2. There would be a redundancy - core language will have 2 array 
types while one of them can be easily implemented using the other.


3. Devs will have to maintain it - as if they don't have enough 
things to fix atm.


Really, this is so simple to do as a library - just use opIndex, 
opSlice with a template struct.


As a general rule - start asking for language features only when 
things can't be done without them.


Re: Array start index

2015-08-02 Thread QAston via Digitalmars-d-learn

On Saturday, 1 August 2015 at 23:02:51 UTC, bachmeier wrote:
But what type of programming are you doing? Even after decades 
of programming and trying out dozens of languages, zero-based 
indexing still gets me at times when the arrays I work with 
represent vectors and matrices. Especially when porting code 
from other languages that use one-based indexing. One of the 
nice things about D is that it gives you the tools to easily 
make the change if you want.


Adding 1-indexed arrays to the language fixes nothing. Just write 
your 1-indexed array type and if you enjoy using it, publish it 
as a library. Who knows, if demand is high it may even end up in 
phobos.


Re: question about the semantics of unshared variables

2015-07-16 Thread QAston via Digitalmars-d-learn

On Thursday, 16 July 2015 at 07:43:10 UTC, Jonathan M Davis wrote:

[...]


On linux you can alter the limit by using ulimit command. -a 
option shows the current limits.


Re: Classes. C++ to D

2015-05-03 Thread QAston via Digitalmars-d-learn

On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote:

Hi,
How can I rewrite this code to the D?

-
#include string
#include iostream

class A {
 public:
 std::string a() {
 return std::string(foo);
 }
};

class B {
 public:
 std::string b(){
 return std::string(bar);
 }
};

class C : public A, public B {};

int main () {

 C c;

 std::cout  c.a()  c.b()  std::endl;

 return 0;
}


If you want to learn a language properly, translating the idioms
directly from what you already know is a bad approach. You're
going to be frustrated that something was easy (to you) in your
old language and the new one is weird and different than the old
one. Also - results are often suboptimal.

I've seen this happen too many times to not warn you, but if you
just want to carry over and you don't care about learning or
quality of result then please carry on.


traits getOverload of a template method

2014-02-06 Thread QAston

How do i get aliases to overloads of a template method like

Class A
{
int a(T)(T tq,T tw);
int a(T)(T tq);
}
__traits(getOverloads, A, a(int))doesnt work


Re: universal databade connector as jdbc

2013-12-11 Thread QAston
On Wednesday, 11 December 2013 at 10:49:43 UTC, bioinfornatics 
wrote:

Hi,

Little question,
I'm looking a jdbc like in D ?
Does this exists ?

Thanks


https://github.com/buggins/ddbc - see readme for more info.


Re: mixed type list?

2013-11-20 Thread QAston

On Wednesday, 20 November 2013 at 11:07:27 UTC, seany wrote:
Is there any way to represent mixed data (of various types) as 
a single array?


In scilab, we have list, and you can do list(integer, stringvar 
) etc.


Can you do something similar in D?  An idea is to use a struct 
wil all possible data types, but think that is inefficient.


Any other ideas?


You can use an array of http://dlang.org/phobos/std_variant.html .


Re: Compiling an app to a single binary - possible?

2013-11-15 Thread QAston
On Friday, 15 November 2013 at 15:27:45 UTC, Jacek Furmankiewicz 
wrote:
One of the nice features of Go is that when you compile an app, 
it pulls in ALL the dependencies (i.e. the full SDK + all 
libraries your app depends on) and generates a single binary 
(around 2 MB for a Hello World app).


This is extremely useful for deployment purposes, since it is 
so straightforward to just copy the app to multiple servers 
without having to worry if every one of them has all the 
required dependencies installed / updated, etc.


Does D offer something similar (maybe via some dmd switches)?

For example, If I am creating a vibe.d app, would I need to 
deploy the vibe.d libraries separately with my app on all the 
servers in production?


Thanks
Jacek


D, like many languages compiled to native code (C, C++) supports 
dynamically loaded libraries (.dll and .so files) as an option. 
You have an option to use DLLs (in which case you'll have to 
deploy them) but it's not a requirement - you can build just like 
in Go as long as you don't use the DDL feature.


You should check vibe.d build options whenever it's possible to 
build it without DLL dependency.


Re: genetically modified slices - is it possible?

2013-11-15 Thread QAston
On Friday, 15 November 2013 at 15:12:23 UTC, Alexandr Druzhinin 
wrote:

15.11.2013 22:09, Adam D. Ruppe пишет:

You could make it work like this:

   auto slice3 = array[
slice1.length + (slice1.ptr - array.ptr)
..
(slice2.ptr - array.ptr)];


Since the slices all start into array somewhere, subtracting 
the

pointers gives their start index.

Thank you very much! I forget about .ptr.
What about ranges in general? They haven't .ptr.


Ranges in general are not arrays, they're objects - you can't get 
what's in between two objects.


Re: Source code of a method.

2013-10-27 Thread QAston
On Saturday, 26 October 2013 at 22:56:20 UTC, TheFlyingFiddle 
wrote:
I kind of did the same thing here in the Mockable mixin: 
https://github.com/nomad-software/dunit Instead of wrapping i 
simply extended the target class so i have access to 
'super.bar()'. Then i can add the specialisation code and/or 
call the original method too.


Hmm i never considered inheritance actually...
(I'm to used to the decorator pattern i guess ^^,
 Normally i only inherit from interfaces and decorate)

But now that you pointed it out it's a perfect fit!
Thanks for the help.


You can use decorator the same way too.


Re: Source code of a method.

2013-10-27 Thread QAston

On Sunday, 27 October 2013 at 14:34:14 UTC, Gary Willoughby wrote:

Can you provide a simple example please?
Just the same way you generate code for inheritance you can use 
to generate code for composition. You just call 
membername.method instead of super.method.


I don't know if anyone can call that a simple example, but it's 
all i have by hand:

https://github.com/QAston/DMocks-revived/blob/master/dmocks/object_mock.d
I use this technique to mock structs and final classes.


Re: Source code of a method.

2013-10-26 Thread QAston
On Saturday, 26 October 2013 at 16:36:35 UTC, TheFlyingFiddle 
wrote:
Is there a way to extract the source code of a method at 
compiletime?


Short and to the point answer: no.


Re: VisualD import

2013-09-12 Thread QAston
On Wednesday, 11 September 2013 at 22:15:07 UTC, Rainer Schuetze 
wrote:



On 11.09.2013 23:42, Lemonfiend wrote:
On Wednesday, 11 September 2013 at 20:36:39 UTC, Rainer 
Schuetze wrote:



On 11.09.2013 18:13, Lemonfiend wrote:

Oops, I forgot to say what I actually did.

I added derelict to Compiler-General-Additional Imports.

The code is just this:

module main;

import std.stdio;
import derelict.opengl3.gl3;

void main()
{
   writeln(Hello D-World!);
}


And the build output is a symbol undefined linker issue:

-- Rebuild All started: Project: Test, Configuration: 
Debug Win32

--
Building Debug\Test.exe...
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
Debug\Test.obj(Test)
Error 42: Symbol Undefined 
_D8derelict7opengl33gl312__ModuleInfoZ

Building Debug\Test.exe failed!
Details saved as 
file://C:\D\Test\Test\Debug\Test.buildlog.html

Build time: 3 s
Solution build stopped.
Build has been canceled.


Did you add the derelict library/libraries as linker inputs?


I haven't compiled derelict to a lib, I'm using the source 
directly.

With rdmd I can simply do -Ipath\to\derelict\source


The compilation model of rdmd is not supported by Visual D. You 
might be able to use rdmd as other compiler in the project 
options with additional options --build-only.


On the other hand, you can also create a library from the 
project templates, then drag the source folder into the project 
to add all files. Then set a project dependency of your 
application to the library.


You can also create a dub package and generate visuald project 
from dub.


Re: static foreach and inline if

2013-07-28 Thread QAston

On Saturday, 27 July 2013 at 17:14:35 UTC, JS wrote:

I'd like to have foreach and inline if in templates:


inline if is available as std.traits.Select



Re: Build / Package system

2013-07-26 Thread QAston

On Wednesday, 30 May 2012 at 08:13:34 UTC, Sputnik wrote:

There is a build and/or package managment system for D2 that is
working?
I googled, and I only can find things like dsss or cmaked that
don't get updated from a long time ago.

I really need to manage to get a project to compile in Windows
and Linux. Actually the code not have any OS dependence, so the
real diferences in each OS are the linking to gtkd and how and
where install the project. Actually I'm using a makfile in Linux
that works well, but I can't use it in windows for thing like
pkg-config.


There's dub: http://code.dlang.org/ 
https://github.com/rejectedsoftware/dub


Need a way to get compressed mangling of a symbol.

2013-07-16 Thread QAston
I'd like to dynamically load procedures from a dll in my app. To 
load a symbol from a DLL i need it's mangled name. D currently 
offers .mangleof which I currently use to generate the name. It 
works very good, but only for short symbols. Is there any way to 
get the final mangled name of a symbol during compilation, or 
maybe there's some documentation describing how compression is 
done (code'd be fine too)? http://dlang.org/abi.html doesn't 
cover the compression scheme.


Re: Need a way to get compressed mangling of a symbol.

2013-07-16 Thread QAston

On Tuesday, 16 July 2013 at 13:58:10 UTC, Adam D. Ruppe wrote:
The reason I snipped the implementations here is the backend is 
under a more restrictive license so I don't want to get into 
copying that. But with just what I've said here combined with 
guess+check against dmd's output it might be enough to do a 
clean room implementation.


Thank you for the reply!

My current clean room implementation is limited to:

const(char)* mangledSymbol(alias symbol)()
{
static assert(((symbol.mangleof) ~ \0).length  128, long 
names won't be available in a library!);

return ((symbol.mangleof) ~ \0).ptr;
}

as it turned out i_didn't_need_that_descriptive_names. I'm 
posting it here, so maybe it'll be easier for some people to 
follow the currently bumpy road of DLLs in D :)


Re: for loop parens

2013-07-12 Thread QAston

On Saturday, 13 July 2013 at 04:56:19 UTC, Jonathan M Davis wrote:

On Saturday, July 13, 2013 06:42:57 QAston wrote:

On Friday, 12 July 2013 at 20:46:21 UTC, ixid wrote:
 Yes, I don't expect anyone to change their opinion though
 frankly the anti-groups opinions feel more like attachment to
 the status quo than something that's evidently and 
 demonstrably

 superior.

I think that Python has syntax evidently and demonstrably
superior to D. Why not Python?


I think that that's very disputable. In general, which syntax 
is better than
another syntax is very subjective. Personally, I hate Python's 
syntax and find
it far harder to deal with than that of languages like C/C++ or 
D. The lack of
braces alone is a huge annoyance for editing code (being able 
to hop between
braces in an editor is invaluable for getting to the beginning 
and end of
functions, scopes, classes, etc.), and it's easy enough to find 
rants where
people have had bugs in their python code due to spacing issues 
and how it

cost them hours to find them.

Yes. Some people prefer python's syntax, but I don't see how 
anyone could
possibly claim that it was demonstratably superior. It's 
primarily a
subjective issue, and from what I've seen, the objective 
portions of the
argument are very much against python as having braces and 
semicolons and the
like makes the code more explicit and therefore less prone to 
scoping issues.
So while that tradeoff may very well be worth it for some 
people, it's

certainly not an objective advantage for python's syntax.

- Jonathan M Davis


I agree, I was just playing games with ixid.


Re: for loop parens

2013-07-12 Thread QAston

On Saturday, 13 July 2013 at 04:42:58 UTC, QAston wrote:
Also, i don't know what's wrong with parens - 2 additional 
keystrokes? I didn't see a for loop i a long time - ranges + 
foreach are everywhere. And foreach is 4 chars more to type 
than for :P.


Replying to myself, but well, this is flawed, foreach is ususally 
shorter than for.


How can i increase max number recursive template expansions?

2013-07-07 Thread QAston
I have a large enum in my code (opcodes for a protocol) - using 
std.traits.EnumMembers gives me a recursive template error.


How can i increase max number recursive template expansions?


Re: How can i increase max number recursive template expansions?

2013-07-07 Thread QAston

On Sunday, 7 July 2013 at 20:28:12 UTC, John Colvin wrote:

On Sunday, 7 July 2013 at 20:22:59 UTC, Simen Kjaeraas wrote:

On 2013-07-07, 21:55, QAston wrote:

I have a large enum in my code (opcodes for a protocol) - 
using std.traits.EnumMembers gives me a recursive template 
error.


How can i increase max number recursive template expansions?


You can't. However, you can amend std.traits.EnumMembers to 
work

with larger enums by using this version:



import std.typetuple;

template EnumMembers(E)
   if (is(E == enum))
{
   // Supply the specified identifier to an constant value.
   template WithIdentifier(string ident)
   {
   static if (ident == Symbolize)
   {
   template Symbolize(alias value)
   {
   enum Symbolize = value;
   }
   }
   else
   {
   mixin(template Symbolize(alias ~ ident ~)
~{
~alias ~ ident ~ Symbolize;
~});
   }
   }

   template EnumSpecificMembers(names...)
   {
   static if (names.length  200)
   {
   alias TypeTuple!(
   EnumSpecificMembers!(names[0..$/2]),
   EnumSpecificMembers!(names[$/2..$]),
   ) EnumSpecificMembers;
   }
   else static if (names.length  0)
   {
   alias TypeTuple!(
   WithIdentifier!(names[0])
   .Symbolize!(__traits(getMember, E, 
names[0])),

   EnumSpecificMembers!(names[1 .. $]),
   ) EnumSpecificMembers;
   }
   else
   {
   alias TypeTuple!() EnumSpecificMembers;
   }
   }

   alias EnumSpecificMembers!(__traits(allMembers, E)) 
EnumMembers;

}



Here, this line:
   static if (names.length  200)
uses divide-and-conquer to reduce the number of template 
instantiations.


We came up with almost identical solutions, posted within 19 
seconds of each other!


Thanks guys, you're awesome!


Re: Why there is too many uneccessary casts?

2013-06-11 Thread QAston

On Tuesday, 11 June 2013 at 16:18:54 UTC, Adam D. Ruppe wrote:
I'd be extremely annoyed if that required a cast. It's bleeding 
obvious that you want it to assign back there


To me u = u + k is as obvious as u += k, but that's probably not 
a thing anyone would be much concerned about :)


Re: GtkD No GSettings schemas installed

2013-04-29 Thread QAston

On Sunday, 28 April 2013 at 17:18:48 UTC, Mike Wey wrote:

On 04/28/2013 04:32 PM, QAston wrote:

On Monday, 15 April 2013 at 18:10:00 UTC, Mike Wey wrote:

On 04/15/2013 05:45 PM, Josh wrote:

On Sunday, 14 April 2013 at 13:34:07 UTC, Mike Wey wrote:


So it looks like the shemas are installed properly.

You could try running the gsettings app from a different 
location than

where it's located, it should be in your path.
If it doesn't give the same output then there may be a 
problem with

how the path is setup.

If it gives the same output then i have no idea what else 
could be

going on.


Yeah, it gives the same output when I run it from somewhere 
else. Guess
I'm back to where I started. Thanks for all your help though 
Mike.


Josh


Could you post the output of the following gtkD app:

import glib.Util;
import std.stdio;

void main()
{
   writeln(Util.getSystemDataDirs());
}


I have the same problem as Josh, your code prints:
[C:\\ProgramData, C:\\Users\\Public\\Documents, 
C:\\Program Files

(x86)\\GtkSharp\\2.12\\share, [app location here]\\share]


It looks like a path issue you could try putting the location 
of the Gtk+ 3 installation before that of GtkSharp and see if 
that fixes the problems.


I've set GTK_BASEPATH as gtkd wiki says(didn't notice that 
before) and it helped. Thanks!


Re: GtkD No GSettings schemas installed

2013-04-28 Thread QAston

On Monday, 15 April 2013 at 18:10:00 UTC, Mike Wey wrote:

On 04/15/2013 05:45 PM, Josh wrote:

On Sunday, 14 April 2013 at 13:34:07 UTC, Mike Wey wrote:


So it looks like the shemas are installed properly.

You could try running the gsettings app from a different 
location than

where it's located, it should be in your path.
If it doesn't give the same output then there may be a 
problem with

how the path is setup.

If it gives the same output then i have no idea what else 
could be

going on.


Yeah, it gives the same output when I run it from somewhere 
else. Guess
I'm back to where I started. Thanks for all your help though 
Mike.


Josh


Could you post the output of the following gtkD app:

import glib.Util;
import std.stdio;

void main()
{
writeln(Util.getSystemDataDirs());
}


I have the same problem as Josh, your code prints:
[C:\\ProgramData, C:\\Users\\Public\\Documents, C:\\Program 
Files (x86)\\GtkSharp\\2.12\\share, [app location here]\\share]