Re: debugging on Mac OSX

2013-04-30 Thread Jacob Carlborg

On 2013-04-30 02:01, Timothee Cour wrote:


C) stacktraces on OSX with some modifications I did involving wrapping
atos, etc: {

shows function name, full file, line numbers, and catches segfaults.
0  file: exception.d:356 pure @safe bool
std.exception.enforce!(bool).enforce(bool, lazy const(char)[],
immutable(char)[], ulong)
1  file: path/som_file.d:100 void util.some_function(int x)
...

Some problems:
in case of segfault, the very latest stack frame is missing (so we
only have the parent of the parent of the function that caused the
segfault, plus anything older).

in some rare cases we only have the file name but no file path
information.

}


How did you get this working?

--
/Jacob Carlborg


Re: debugging on Mac OSX

2013-04-30 Thread Jacob Carlborg

On 2013-04-29 20:49, Dan wrote:


Thanks. What is the takeaway? That it does not work and can not work
until these two bugs are fixed? A simple I don't think you can get
there from here?


At least these bugs need to be fixed to get demangled symbol names.

--
/Jacob Carlborg


Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread JR

On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote:

To get rid of the cast:

[...]

Instantiating the template with a function parameter causes a 
compilation error when actually calling the function;


--
  asdf.d:13: Error: variable asdf.MatrixWalker!(@system 
void(string major, uint minor, void function(string, uint) func), 
void function(string, uint)[uint][string]).applyFunc.func cannot 
be declared to be a function
  asdf.d:16: Error: function expected before (), not func of type 
_error_

--

I have a vague feeling I had it working like that at one point 
but I cannot recall with any degree of certainty.


Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread anonymous

On Tuesday, 30 April 2013 at 08:42:57 UTC, JR wrote:

On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote:

To get rid of the cast:

[...]

Instantiating the template with a function parameter causes a 
compilation error when actually calling the function;


--
  asdf.d:13: Error: variable asdf.MatrixWalker!(@system 
void(string major, uint minor, void function(string, uint) 
func), void function(string, 
uint)[uint][string]).applyFunc.func cannot be declared to be a 
function
  asdf.d:16: Error: function expected before (), not func of 
type _error_

--

I have a vague feeling I had it working like that at one point 
but I cannot recall with any degree of certainty.


Don't know what's going wrong there. It works for me:
http://dpaste.dzfl.pl/5c71f80e


Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread JR

On Tuesday, 30 April 2013 at 09:18:56 UTC, anonymous wrote:

On Tuesday, 30 April 2013 at 08:42:57 UTC, JR wrote:

On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote:



Don't know what's going wrong there. It works for me:
http://dpaste.dzfl.pl/5c71f80e


My bad, I switched the wrong runner/runner and in the wrong 
direction. Thanks!


Any other protips?

For instance, is it possible to have MatrixWalker's F type to 
have a default value of a NOP void function(), have the innermost 
foreach loop check if the element is a function, and if so call 
it directly without needing FuncRunner at all?


Also, is there a clever approach to have MatrixWalker call its 
passed function variadically with only the arguments that its 
signature allows? As in;


-

import std.stdio;
import std.concurrency;

struct Event { /* ... type, sender, target, content and friends 
... */ };


template MatrixWalker(F,E: E[I][T],I,T) {
// note addition of Event below
void applyFunc(ref Event evt, F func, E[I][T] matrix) {
/* ... Inception foreach ... */
func(evt, /* only the arguments of E, I and/or T that 
type F accepts */);

}
}

const alias Blaawp MAJOR;
const alias Oorgle MINOR;
static void function(ref Event, MINOR)[MINOR][MAJOR] 
funcyMatrix;

// note no MAJOR in func sig

void populate() {
/* ... */
}

void traverse() {
sendMessageAdapter = void function(ref Event evt, Tid) {
std.concurrency.send(tid, evt);
};

alias 
MatrixWalker!(typeof(sendMessageAdapter),typeof(funkyMatrix)).applyFunc 
apply;


writeln(Traversing funcy matrix);
apply(sendMessageAdapter, funkyMatrix);
}

void main(string[] args) {
populate();
traverse();
}

-

That sounds too good to be true, but it would make me warm and 
fuzzy inside if I didn't have to resort to keeping a dozen 
adapter/shim functions around.


Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread anonymous

On Tuesday, 30 April 2013 at 10:02:07 UTC, JR wrote:
[...]
For instance, is it possible to have MatrixWalker's F type to 
have a default value of a NOP void function(), have the 
innermost foreach loop check if the element is a function, and 
if so call it directly without needing FuncRunner at all?


Let's start by turning MatrixWalker into a function template 
(fixing the matrix template parameter on the way):

---
void walkMatrix(F,M: E[I][T],E,I,T)(F func, M matrix) {
/* those foreaches */
}
---

This way it can be called without explicitly instantiating the 
template:

---
walkMatrix(runner, funcyMatrix);
---

Now add an overload for callable elements:
---
void walkMatrix(M: E[I][T],E,I,T)(M matrix) 
if(is(typeof(FuncRunner!M.run))) {

walkMatrix(FuncRunner!M.run, matrix);
}
---

A call:
---
walkMatrix(funcyMatrix);
---

Of course, FuncRunner is now only needed by that overload, so you 
could move its implementation in there.


Also, is there a clever approach to have MatrixWalker call its 
passed function variadically with only the arguments that its 
signature allows? As in;


-

import std.stdio;
import std.concurrency;

struct Event { /* ... type, sender, target, content and 
friends ... */ };


template MatrixWalker(F,E: E[I][T],I,T) {
   // note addition of Event below
   void applyFunc(ref Event evt, F func, E[I][T] matrix) {
   /* ... Inception foreach ... */
   func(evt, /* only the arguments of E, I and/or T that 
type F accepts */);

   }
}

const alias Blaawp MAJOR;
const alias Oorgle MINOR;
static void function(ref Event, MINOR)[MINOR][MAJOR] 
funcyMatrix;

// note no MAJOR in func sig

void populate() {
   /* ... */
}

void traverse() {
   sendMessageAdapter = void function(ref Event evt, Tid) {
   std.concurrency.send(tid, evt);
   };

   alias 
MatrixWalker!(typeof(sendMessageAdapter),typeof(funkyMatrix)).applyFunc 
apply;


   writeln(Traversing funcy matrix);
   apply(sendMessageAdapter, funkyMatrix);
}

void main(string[] args) {
   populate();
   traverse();
}

-

That sounds too good to be true, but it would make me warm and 
fuzzy inside if I didn't have to resort to keeping a dozen 
adapter/shim functions around.


I don't have a clever solution for that.


Re: how hash_t toHash() works?

2013-04-30 Thread gedaiu

On Monday, 29 April 2013 at 16:01:15 UTC, Ivan Kazmenko wrote:

one more question
What is the type of cont?

auto cont = redBlackTree !(a.key  b.key, true, MyRecord) ();

I want to use this as a property in a class and i can't use 
there auto keyword... I tried different types but it did not 
work.


For me, the following declaration works:

-
import std.functional;
...
RedBlackTree !(MyRecord, binaryFun!a.key  b.key, true) cont;
...
cont = redBlackTree !(a.key  b.key, true, MyRecord) ();
-

I admit it could have been easier to figure out.  For example, 
writeln (typeof (cont).stringof); just prints RedBlackTree 
which is not enough for a proper declaration.  I've inferred 
the right declaration from the following lines in container.d:


-
/++ Ditto +/
auto redBlackTree(alias less, bool allowDuplicates, E)(E[] 
elems...)

if(is(typeof(binaryFun!less(E.init, E.init
{
//We shouldn't need to instantiate less here, but for some 
reason,
//dmd can't handle it if we don't (even though the template 
which

//takes less but not allowDuplicates works just fine).
return new RedBlackTree!(E, binaryFun!less, 
allowDuplicates)(elems);

}
-


Error: template instance RedBlackTree!(ValueRecord, binaryFun, 
true) RedBlackTree!(ValueRecord, binaryFun, true) does not match 
template declaration RedBlackTree(T, alias less = a  b, bool 
allowDuplicates = false) if (is(typeof(binaryFun!(less)(T.init, 
T.init
Error: RedBlackTree!(ValueRecord, binaryFun, true) is used as a 
type


Do you know what this error means?

Thank,
Bogdan


starting with GUI

2013-04-30 Thread Carlos

I;m trying to add a Entry but I get the following error:

mywindow.d(12): Error: undefined identifier Entry

Here is my code :

window.add(new Entry(Minsit));

I'm just guessing to see if everything is that simple. So I have 
to define the Entry. How do I do that ? ( Any tutorials from the 
web are welcome )


I'm trying to make a program that calculates two numbers and then 
adds them together to give a result.


Here is the CLI version :

import std.stdio;
import std.c.stdlib;
void main()
{
immutable sitc = 1.66, sleepc = 1.08;
float tcsleep, tcsit, tc;
int minsleep, minsit;
write(Input number of minutes sleep and sit : \n);
readf( %s , minsleep);
readf( %s , minsit);
write(Thanks!\n);
tcsit = minsleep*sleepc;
tcsleep = minsit*sitc;
tc = (tcsleep + tcsit);
writeln(Your total burned calories is : , tc);
}


I'm using this GTK for the GUI :

http://www.dsource.org/projects/gtkd/wiki/DebianPackages;
 and this compiles fine with the following :

dmd $(pkg-config --cflags --libs gtkd-2) mywindow.d

This is the code I compiled with GTKD :

import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main (string[] args)
{
Main.init(args);
auto window = new MainWindow(My Window);
window.show();
window.setDefaultSize(200, 100);
window.add(new Label(Hello!));
window.showAll();
Main.run;
}


So basicly what I'm missing is a good way on learning to use this 
GTKD but for the moment I only want to define a Entry.

THank you for your time.


Re: starting with GUI

2013-04-30 Thread Carlos
Another version of the CLI which tries to keep 1440 minutes for a 
complete day ( this is desired on the GUI ) is :



import std.stdio;
import std.c.stdlib;
void main()
{
immutable sitc = 1.66;
immutable sleepc = 1.08;
float tcsleep, tcsit, tc;
int minsleep, minsit;
write(Input minutes sit : \n);
readf( %d, minsit);
write(Input minutes sleep : \n);
readf( %d, minsleep);
while (minsit+minsleep != 1440){
write(Error 1 \n);
write(Input minutes sit : \n);
readf( %d, minsit);
write(Input minutes sleep : \n);
readf( %d, minsleep);
}
if (minsit+minsleep == 1440){
tcsit = minsleep*sleepc;
tcsleep = minsit*sitc;
tc = (tcsleep + tcsit);
write(Your calories per day is : , tc, \n);
exit (0);
}
}



Re: starting with GUI

2013-04-30 Thread anonymous

On Tuesday, 30 April 2013 at 17:03:07 UTC, Carlos wrote:

I;m trying to add a Entry but I get the following error:

mywindow.d(12): Error: undefined identifier Entry

Here is my code :

window.add(new Entry(Minsit));

I'm just guessing to see if everything is that simple. So I 
have to define the Entry. How do I do that ? ( Any tutorials 
from the web are welcome )



[...]


This is the code I compiled with GTKD :

import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main (string[] args)
{
Main.init(args);
auto window = new MainWindow(My Window);
window.show();
window.setDefaultSize(200, 100);
window.add(new Label(Hello!));
window.showAll();
Main.run;
}


So basicly what I'm missing is a good way on learning to use 
this GTKD but for the moment I only want to define a Entry.

THank you for your time.


A wild guess: import gtk.Entry;


Re: starting with GUI

2013-04-30 Thread Carlos

A wild guess: import gtk.Entry;
Thank you I just did that some minutes ago ( a good guess ). Now 
I'm trying to work on the layout so I can finally enter in 
signals if that's how GTKD works.


Re: how hash_t toHash() works?

2013-04-30 Thread Ivan Kazmenko

-
import std.functional;
...
	RedBlackTree !(MyRecord, binaryFun!a.key  b.key, true) 
cont;

...
cont = redBlackTree !(a.key  b.key, true, MyRecord) ();
-


Error: template instance RedBlackTree!(ValueRecord, binaryFun, 
true) RedBlackTree!(ValueRecord, binaryFun, true) does not 
match template declaration RedBlackTree(T, alias less = a  
b, bool allowDuplicates = false) if 
(is(typeof(binaryFun!(less)(T.init, T.init
Error: RedBlackTree!(ValueRecord, binaryFun, true) is used as a 
type


I am able to reproduce it if I write
RedBlackTree !(MyRecord, binaryFun, true)
instead of
RedBlackTree !(MyRecord, binaryFun!a.key  b.key, true)

If you are using a plain regular function instead of a.key  
b.key there, consider the following form:


-
bool less (T) (auto ref T a, auto ref T b)
{
return a.key  b.key;
}
...
RedBlackTree !(MyRecord, less, true) cont;
...
cont = redBlackTree !(less, true, MyRecord) ();
-

Note that the straightforward notation does *not* work yet in 
2.062 if you want ref parameters:


-
bool less (ref MyRecord a, ref MyRecord b)
{
return a.key  b.key;
}
-

The current condition of binaryFun is too tight.  So, for now, we 
have to create a non-ref version too to pass it.  See (and 
perhaps comment) the following issue in BugZilla:  
http://d.puremagic.com/issues/show_bug.cgi?id=9513


Ivan Kazmenko.


Re: WinAPI callbacks and GC

2013-04-30 Thread Sean Kelly
On Apr 23, 2013, at 2:21 PM, Jack Applegame jappleg...@gmail.com wrote:
 
 According WinAPI documentation, CtrlHandler will be called in new additional 
 thread. Is it safe to allocate GC memory in NOT Phobos threads?
 If not, how to make it safe? I'm trying call thread_attachThis() at the 
 beginning of CtrlHandler fucntion, but it doesn't compile because 
 thread_attachThis() is not no throw.


thread_attachThis should probably just be labeled nothrow.  I don't think 
there's anything in that function that can throw an Exception.