Re: Are structs saved in multi-thread delegate call?

2016-04-22 Thread Ramon via Digitalmars-d-learn

mmm, I figured the problem, but don't know how to solve it.
my struct has a destructor which clears itself:

struct json_value
{
  ~this() { .ValueClear(); }
}

so how I can I put a struct in the heap? (not in the stack, as is 
the default..)


Are structs saved in multi-thread delegate call?

2016-04-22 Thread Ramon via Digitalmars-d-learn

I have something along this way:

struct json_value
{
..
}

function DoDirSearch(..)
{
immutable json_value cbk = json_value(prms.argv[3]);
assert(cbk != json_value.init); // OK, pass

import core.thread;
new Thread({
assert(cbk != json_value.init); // FAIL!
}).start();
}

the problem is, my struct value is not saved in the spawned tread 
context, so this assert fails while at the start it passed:


assert(cbk != json_value.init);


projections in D

2014-11-24 Thread Ramon via Digitalmars-d-learn
what range/algorithm allows me to make projections from one 
sequence to another?


that is, in C#, this is the Select method 
(http://msdn.microsoft.com/en-us/library/vstudio/bb548891%28v=vs.100%29.aspx)


example in C#:

class ProjectionWanted
{
  public int field1 { get; set; }
  public int field2 { get; set; }
  public int field3 { get; set; }
}

void Foo(ListProjectionWanted list)
{
  var list_projected = list.Select(l = new { l.field1, l.field2 
});

  // list_projected elements now contain only field1 and field2
}

So how would I make it in D? First yet, does D supports creating 
anonymous type for the projection? Or maybe I need to declare the 
class/struct that I want to be projected?


Re: projections in D

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

What is the difference between lazy and eager ranges?

(I guess, the lazy one has not yet queried the elements)