Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread ilya-stromberg
On Thursday, 14 November 2013 at 22:12:10 UTC, Jacek 
Furmankiewicz wrote:
On Thursday, 14 November 2013 at 21:36:46 UTC, ilya-stromberg 
wrote:
On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek 
Furmankiewicz wrote:
How often do you change the data? Probably, you should use 
`immutable` variables.


Customer specific. It may change once a year. It may change 
multiple times per second for a while, then nothing again for 
weeks.


Others may do mass loads of business rules, hence do mass 
changes every few hours.


Next to impossible to predict.


You can use `immutable` variables. It allows you to share the 
data without any synchronization. Like this:


class MyData
{
   int data1;
   string data2;

   //creates new object
   this(int data1, string data2)
   {
  this.data1 = data1;
  this.data2 = data2;
   }

   //modify the data
   immutable(MyData) editData(int i) const
   {
  //copy this object - we can't change immutable variables
  MyData dataCopy = new MyData(this.data1, this.data2)

  //modify the data copy
  dataCopy.data1 += i;

  //assume that `dataCopy` is immutable
  return cast(immutable(MyData)) dataCopy;
   }
}

shared myMap;

//map implementation
synchronized class MyMap
{
   HashMap!(int, immutable(MyData)) map;

   void foo()
   {
  map[1] = new immutable MyData(1, "data");
   }

   void bar()
   {
  map[1] = map[1].editData(5);
   }
}

//init map
shared static this()
{
   myMap = new MyMap();
}

void main()
{
   myMap.foo();
   myMap.bar();
}


Re: Maximum size of an string ?

2013-11-14 Thread Jean Christophe


Than you Ali :0
I assume it is for UTF8 encoding.
That's quite large enough.

JC

On Thursday, 14 November 2013 at 11:50:28 UTC, Ali Çehreli wrote:

On 11/14/2013 02:10 AM, Jean Christophe wrote:

> Has someone tested the maximum size of a D string variable
for both 32
> and 64 bits platforms ? Is it different from the maximum size
of a char[] ?

Both string and char[] are implemented in the same way: a 
size_t for length and a pointer to data. (D arrays know their 
sizes.)


So, the theoretical limit for both are size_t, which is the 
equivalent of uint or ulong dependending on 32-bit versus 
64-bit.


Ali




Re: Cannot cast char[] to string.

2013-11-14 Thread Jonathan M Davis
On Thursday, November 14, 2013 20:45:55 Brad Anderson wrote:
> On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
> > I'm trying to use http://dlang.org/phobos/std_net_curl.html and
> > when i compile the same example i get:
> > 
> > cannot implicitly convert expression
> > (get(cast(const(char)[])address, AutoProtocol())) of type
> > char[] to string
> > 
> > string address = "http://dlang.org";;
> > string _data = get(address);
> 
> You have two options:
> 
> string address = "http://dlang.org";;
> string _data = get(address).idup(); // create immutable copy
> 
> or
> 
> string address = "http://dlang.org";;
> char[] _data = get(address); // store mutable reference

If you want a string rather than char[], it's probably better to use 
std.conv.to. In the case of char[], it'll just end up calling idup for you, 
but if you use to!string(arr) as the normal means for converting arrays of 
characters to string, then you don't have to worry about the constness of the 
array, and if it turns out that the array was in fact string (which is quite 
easy to have happen if you're dealing with generic code), then it'll avoid 
iduping the array and will simply return it.

> A string (which is just an alias of immutable(char)[]) can't be
> made from a char[] without an assertion that the data pointed to
> is, in fact, immutable. You can do that using assumeUnique
> (inexplicably found in std.exception).

AFAIK, there is no way to make such an assertion. assumeUnique simply casts to 
immutable (though it will set the array passed in to null if you pass it an 
lvalue). So, it's completely up to the programmer to guarantee that the array 
is indeed unique. The primary used case for it is if you have to construct an 
array which you need to be immutable, and you need it to be mutable while 
you're setting all of its elements, in which case, you use assumeUnique on the 
array after you've set all of its elements, and you make sure that you don't 
have any other references to the array when you do that. If that's not what 
you're doing, you probably shouldn't be using assumeUnique. Certainly, using 
it on the result of a function that returns char[] is almost certainly wrong, 
and could result in very weird behavior, because the compiler is free to 
optimize based on the fact that the array is immutable, and if there's a 
mutable reference to that array, then you've subverted the type system, and 
ruined the compilers guarantees.

- Jonathan M Davis


Re: Deimos rules?

2013-11-14 Thread Jonathan M Davis
On Thursday, November 14, 2013 15:06:59 Joseph Rushton Wakeling wrote:
> On 14/11/13 13:13, Jacob Carlborg wrote:
> > I would say stay as close to the original C code as possible. Although I
> > do
> > prefer to translate typedefs like int8_t to real D types, like byte, if
> > they exist.
> In some ways I wonder why D's types aren't just specified according to the
> number of bits -- int8, int16, int32, int64 instead of byte, short, int,
> long. I suppose on balance it's probably less readable and easier to make
> mistakes writing.

It's a stylistic choice, and Walter went with not putting the sizes in the 
type names. But since their sizes are still fixed, it doesn't really matter.

> More generally -- is it considered desirable to provide not only the C-like
> translation, but also a higher-level "D-ified" wrapper? Or is that
> considered overkill for Deimos?

Deimos is specifically for bindings to C libraries and _not_ for D-ified 
wrappers. And that's the stance that Walter has taken when it's come up. But 
with dub and code.dlang.org, it should be simple enough to put a D-ified 
wrapper in a place where folks can find it.

- Jonathan M Davis


Re: D Program code on CLS

2013-11-14 Thread Jesse Phillips

On Thursday, 14 November 2013 at 21:42:34 UTC, seany wrote:

what is the tango equivalent for system?

In my case, since my dmd, tango and things are in custom 
folders, i notice that i am getting problems when importing 
both std.stdio and tango.io.stdout


For tango it looks like you want tango.sys.Process

http://www.dsource.org/projects/tango/docs/stable/tango.sys.Process.html


Re: std.json

2013-11-14 Thread Rob T

On Wednesday, 4 July 2012 at 16:55:19 UTC, Ali Çehreli wrote:

On 07/04/2012 08:25 AM, Alexsej wrote:
> On Monday, 26 March 2012 at 07:14:50 UTC, Ali Çehreli wrote:

>> // Assumes UTF-8 file
>> auto content = to!string(read("json_file"));

> Your example only works if the json file in UTF-8 (BOM), how
to make
> sure that it worked with the files in UTF-8 without BOM.

I am pretty sure that I have tested it without BOM, which is 
not recommended nor needed for UTF-8 anyway.


If anything, the file should not have any BOM because it is 
being converted to a string and is being passed to parseJSON(). 
I don't think parseJSON() expects a BOM either. Does it?


Ali


Last time I checked, parseJSON will fail if a BOM exists. Now 
that I think of it, maybe that state of affairs should be filed 
as a bug or feature enhancement.


--rt


Re: pitfalls of enum

2013-11-14 Thread bearophile

Ali Çehreli:


> When is an enum *better* than a normal (static
const/immutable) constant?

Good question. :)


When you can or want to compute something at compile-time, when 
you need values to feed to templates, etc.


Bye,
bearophile


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Charles Hixson

On 11/14/2013 01:36 PM, ilya-stromberg wrote:

On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek Furmankiewicz wrote:
hashmap per thread is not an option. The cache may be a few GBs of 
data, there is no way we can duplicate that data per thread.


Not to mention the start up time when we have to warm up the cache.


How often do you change the data? Probably, you should use `immutable` 
variables.


Immutable variables are nice when they can be used.  Often, however, 
they can't.


I think that for the "concurrent hashmap" the best answer is probably to 
run the map in a thread, with message passing access whether for read or 
write.  And I wouldn't be surprised if that's how Java's concurrent 
hashmap is implemented under the covers. (OTOH, I haven't ever debugged 
such a setup.  Someone who has may have a better answer.)


--
Charles Hixson



Re: pitfalls of enum

2013-11-14 Thread Ali Çehreli

On 11/02/2013 02:14 PM, JR wrote:

> But in Andrei's thread on tristates[2] he lists this code excerpt:
>> struct Tristate
>> {
>> private static Tristate make(ubyte b)
>> {
>> Tristate r = void;
>> r.value = b;
>> return r;
>> }
>>
>> enum no = make(0), yes = make(1), unknown = make(4);  // <---
>
> Is it okay to use enum there? If so, is it because (whatwith being a
> struct) it's not on the heap?

I think it is more like because its value is known at compile time. If 
Tristate were a class, then the class variable r would not have any 
class object that it pointed to.


> What if it were a class?

I tried changing struct to class:

class Tristate
{
ubyte value;

private static Tristate make(ubyte b)
{
Tristate r = new Tristate();
r.value = b;
return r;
}

enum no = make(0), yes = make(1), unknown = make(4);
}

Error: variable deneme.Tristate.no : Unable to initialize enum with 
class or pointer to struct. Use static const variable instead.


So, class can't work.

> A string?

That would be ok. A compile-time string is known to the compiler and can 
appear in the program binary to be referenced from multiple places.


> A
> string instantiated with the value of another string, which would
> normally simply create an alias?

Would work.

> When is an enum *better* than a normal (static const/immutable) constant?

Good question. :)

Ali



Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread H. S. Teoh
On Fri, Nov 15, 2013 at 12:13:11AM +0100, bearophile wrote:
> Ali Çehreli:
> 
> >transversal() is useful too: :)
> >
> >  http://dlang.org/phobos/std_range.html#transversal
> 
> transversal() is sometimes useful, but if you need a significant
> amount of matrix processing, slicing and dicing matrices all the
> time in scientific code, then probably it's better to use a custom
> matrix library for D. Eventually one "winner" of such libraries
> should come out for D (as NumPy is in Python world). But to
> implement such libraries D should improve its management of "$" and
> "..." more for user-defined types.
[...]

'$' already works for multidimensional arrays, you just have to
implement opDollar appropriately.

Slicing syntax isn't, though. Kenji has a pull for it, but it hasn't
been merged yet for whatever reason.


T

-- 
Once bitten, twice cry...


Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread bearophile

Ali Çehreli:


transversal() is useful too: :)

  http://dlang.org/phobos/std_range.html#transversal


transversal() is sometimes useful, but if you need a significant 
amount of matrix processing, slicing and dicing matrices all the 
time in scientific code, then probably it's better to use a 
custom matrix library for D. Eventually one "winner" of such 
libraries should come out for D (as NumPy is in Python world). 
But to implement such libraries D should improve its management 
of "$" and "..." more for user-defined types.


Bye,
bearophile


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz

True.

While looking a D, I am just trying to focus on the parts which I 
know would be a showstopper for us on day one...and this 
particular issue is it.


I do like D a lot as well from what I've seen so far.

Regarding the GC, I've seen some slides on DConf about other 
garbage collectors available. Is there any resource/tutorial that 
shows how you can swap out the default GC for those alternative 
implementations?




Re: Dynamic array handling

2013-11-14 Thread bearophile

Brad Anderson:


a = a.remove(3);


But I think the remove function should be modified:
https://d.puremagic.com/issues/show_bug.cgi?id=10959

To the Original Poster I can also answer that with a filter+array 
functions you can build a new array that contains only certain 
items of the original array (according to a filtering function, 
or to a list of indexes to keep).


Bye,
bearophile


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread bearophile

Jacek Furmankiewicz:


Well, these are the types of questions I have as a Java veteran
who is having a first look at D after the recent Facebook 
announcement.


By now I have a decent idea of where most of the new languages 
(Go has same issues, for the most part) come up short when 
compared to Java's very mature SDK, so that is usually where I 
start probing first.


Sorry :-(


The development of the Java language, its GC, Oracle JVM, 
standard library (and its IDEs, etc) have received tons of money, 
time, and hours of work, so it's not strange Java is "better" 
than D.


On the other hand different languages are fitter for different 
purposes. I like D a lot, but programmers should choose languages 
wisely, and Java is a wiser choice for several commercial 
purposes. If you rewrite Minecraft from Java to D I suspect you 
produce a game that's faster and with a shorter source code, 
while keeping most of its programmer-friendly nature and its 
coding safety, despite the current limits of the D GC.


If you want to use D try to find niches where it could be useful 
and fit. I am using D where it's better than equivalent Java 
code. Today Python is used a lot, but in many cases it's not 
replacing equivalent Java code.


Probably you can replace some Java code with Scala code.

Bye,
bearophile


Re: Deimos rules?

2013-11-14 Thread Xavier Bigand

Le 14/11/2013 13:13, Jacob Carlborg a écrit :

On 2013-11-13 23:01, Xavier Bigand wrote:

I work on XCB integration, so I think that I can add bindings in deimos.

C headers are translated to d modules by using DStep or manually?
If manually need I respect some syntactical rules?


I would say stay as close to the original C code as possible. Although I
do prefer to translate typedefs like int8_t to real D types, like byte,
if they exist.

I started by changing extension of files from .h to .d, and translating 
in place everything. I take libX11 as model.


I'll certainly make a pull request when I will able to run a simple demo.

I let all originals comments as it during the translation.



Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread TheFlyingFiddle

On Thursday, 14 November 2013 at 22:26:03 UTC, Ali Çehreli wrote:

transversal() is useful too: :)

  http://dlang.org/phobos/std_range.html#transversal

Ali


Did not know about this one. Thanks for pointing it out :D



Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread Ali Çehreli

On 11/14/2013 02:18 PM, TheFlyingFiddle wrote:

On Thursday, 14 November 2013 at 22:06:28 UTC, seany wrote:

How do I access All rows (resp. columns ) of a Matrix /
multidimensional array?

In scilab, you write array_var(:,row_index), colon meaning all
columns, at that particular row given by row index will be selected.

can you, forexample, in D, write, array_var[0][] to select all
elements (columns, in this case i believe?) of array_var[0] ?


unittest
{
   int[][] matrix = new int[][](n,m);

   //Getting a collumn is simple.
   int[] collumn0 = matrix[0];

   //Getting a row is trickier
   int[] row0;

   //Loop over all collumns
   foreach(i; matrix) {
 row0 ~= matrix[i][0];
   }
}




transversal() is useful too: :)

  http://dlang.org/phobos/std_range.html#transversal

Ali



Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread TheFlyingFiddle
On Thursday, 14 November 2013 at 22:18:44 UTC, TheFlyingFiddle 
wrote:

unittest
{
  int[][] matrix = new int[][](n,m);

  //Getting a collumn is simple.
  int[] collumn0 = matrix[0];

  //Getting a row is trickier
  int[] row0;

  //Loop over all collumns
  foreach(i; matrix) {
row0 ~= matrix[i][0];
  }
}


Sry the way you get rows is wrong.
It should be

int[] row0;
foreach(collumn; matrix)
row0 ~= collumn[0];

and not


  int[] row0;

  //Loop over all collumns
  foreach(i; matrix) {
row0 ~= matrix[i][0];
  }


Re: interface and class inheritance

2013-11-14 Thread Oleg B

On Thursday, 14 November 2013 at 21:45:11 UTC, Agustin wrote:

On Thursday, 14 November 2013 at 21:42:38 UTC, Agustin wrote:

On Thursday, 14 November 2013 at 21:20:57 UTC, Oleg B wrote:

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
  auto c = new C;
  c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 
'void funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and 
interface A?


Try

interface A {
 final void funcA();
}
class B {
 final void funcA() { writeln( "B.funcA()" ); }
}

class C: B, A { }


Oh sorry i mean

interface A {
  void funcA();
}

class B : A {
  final void funcA() { writeln( "B.funcA()" ); }
}

class C : B {
}


we can't change anything in class B


Re: select all rows (resp. columns) out of matrix

2013-11-14 Thread TheFlyingFiddle

On Thursday, 14 November 2013 at 22:06:28 UTC, seany wrote:
How do I access All rows (resp. columns ) of a Matrix / 
multidimensional array?


In scilab, you write array_var(:,row_index), colon meaning all 
columns, at that particular row given by row index will be 
selected.


can you, forexample, in D, write, array_var[0][] to select all 
elements (columns, in this case i believe?) of array_var[0] ?


unittest
{
  int[][] matrix = new int[][](n,m);

  //Getting a collumn is simple.
  int[] collumn0 = matrix[0];

  //Getting a row is trickier
  int[] row0;

  //Loop over all collumns
  foreach(i; matrix) {
row0 ~= matrix[i][0];
  }
}




Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz
On Thursday, 14 November 2013 at 21:36:46 UTC, ilya-stromberg 
wrote:
On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek 
Furmankiewicz wrote:
How often do you change the data? Probably, you should use 
`immutable` variables.


Customer specific. It may change once a year. It may change 
multiple times per second for a while, then nothing again for 
weeks.


Others may do mass loads of business rules, hence do mass changes 
every few hours.


Next to impossible to predict.



Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz

On Thursday, 14 November 2013 at 21:39:53 UTC, bearophile wrote:

Jacek Furmankiewicz:

hashmap per thread is not an option. The cache may be a few 
GBs of data, there is no way we can duplicate that data per 
thread.


But is the D garbage collector able to manage efficiently 
enough associative arrays of few gigabytes? You are not dealing 
with a GC nearly as efficient as the JavaVM one.




Well, these are the types of questions I have as a Java veteran
who is having a first look at D after the recent Facebook 
announcement.


By now I have a decent idea of where most of the new languages 
(Go has same issues, for the most part) come up short when 
compared to Java's very mature SDK, so that is usually where I 
start probing first.


Sorry :-(


Re: Object destruction versus finalization

2013-11-14 Thread Florian

Michael,

thank you for these links.

Regards, Florian.


select all rows (resp. columns) out of matrix

2013-11-14 Thread seany
How do I access All rows (resp. columns ) of a Matrix / 
multidimensional array?


In scilab, you write array_var(:,row_index), colon meaning all 
columns, at that particular row given by row index will be 
selected.


can you, forexample, in D, write, array_var[0][] to select all 
elements (columns, in this case i believe?) of array_var[0] ?




Re: Dynamic array handling

2013-11-14 Thread seany

WOW

On Thursday, 14 November 2013 at 21:50:53 UTC, Ali Çehreli wrote:

On 11/14/2013 01:38 PM, seany wrote:

In Very High level languages, such as scilab, you can write

array_var = (1,2,3 ... etc)

and then you can also write

array_var = array_var(1:2,4:$)

In this case, the third element is dropped, and the same 
variable,
array_var is set to be an array of a different length, 
resizing of array

and so on is automated.

Is the same possible to be done in D?

say,

int [] a ; //initialize;

a ~= 1;
a ~= 2; //etc, polulate

. . . say, we fill up 10 such elements

Now, can you do like,

a = somefunction_that_drops_the_4th_element(a); // a is reset,
// and the 
length
// is 
reorganized

automatically


There is also chain() which works with ranges other than slices 
as well:


import std.array;
import std.range;
import std.algorithm;

void main()
{
auto a = 10.iota.array;

auto skipped = chain(a[0..3], a[4..$]);
assert (skipped.equal([ 0, 1, 2, 4, 5, 6, 7, 8, 9 ]));
}

Ali




Re: Multidimensional array in d2?

2013-11-14 Thread Ali Çehreli

On 11/14/2013 01:31 PM, seany wrote:

> I also note you have a book http://ddili.org/ders/d.en/index.html
> (too bad that there are chapters not translated, but thank you very 
much)!


You are very welcome! Just three chapters left and I must add the UDA 
chapter, which has been one of the most recent additions to the 
language. :) Also, once approved, I will have to at least mention the 
upcoming std.allocator in the memory management chapter.


Ali



Re: Dynamic array handling

2013-11-14 Thread Ali Çehreli

On 11/14/2013 01:38 PM, seany wrote:

In Very High level languages, such as scilab, you can write

array_var = (1,2,3 ... etc)

and then you can also write

array_var = array_var(1:2,4:$)

In this case, the third element is dropped, and the same variable,
array_var is set to be an array of a different length, resizing of array
and so on is automated.

Is the same possible to be done in D?

say,

int [] a ; //initialize;

a ~= 1;
a ~= 2; //etc, polulate

. . . say, we fill up 10 such elements

Now, can you do like,

a = somefunction_that_drops_the_4th_element(a); // a is reset,
 // and the length
 // is reorganized
automatically


There is also chain() which works with ranges other than slices as well:

import std.array;
import std.range;
import std.algorithm;

void main()
{
auto a = 10.iota.array;

auto skipped = chain(a[0..3], a[4..$]);
assert (skipped.equal([ 0, 1, 2, 4, 5, 6, 7, 8, 9 ]));
}

Ali



Re: Dynamic array handling

2013-11-14 Thread Adam D. Ruppe

On Thursday, 14 November 2013 at 21:38:39 UTC, seany wrote:

array_var = (1,2,3 ... etc)


In D, that'd look like:

auto array_var = [1,2,3,4,5];


array_var = array_var(1:2,4:$)


array_var = array_var[0 .. 1] ~ array_var[2 .. $];

array[x .. y] does a slice in D, with the first element of the 
array being element 0. The returned value is the array from x to 
y, not including y.


Then the ~ operator builds a new array out of the two pieces on 
either side. Note though: using ~ in a loop where you need high 
performance is generally a bad idea - it is convenient, but a 
little slow since it allocates space for a new array.



a = somefunction_that_drops_the_4th_element(a); // a is reset,
// and the


There's also a remove function in std.algorithm that can drop an 
item like this:


import std.algorithm;

array_var = array_var.remove(2); // removes the 3rd element 
(starting from 0, so index 2 is the third element)



This function btw performs better than the a[0 .. 1] ~ a[2 .. $] 
example above, since it modifies the array in place instead of 
building a new one.


Re: interface and class inheritance

2013-11-14 Thread Agustin

On Thursday, 14 November 2013 at 21:20:57 UTC, Oleg B wrote:

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
auto c = new C;
c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 
'void funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and interface 
A?


Try

interface A {
  final void funcA();
}
class B {
  final void funcA() { writeln( "B.funcA()" ); }
}

class C: B, A { }



Re: interface and class inheritance

2013-11-14 Thread Agustin

On Thursday, 14 November 2013 at 21:42:38 UTC, Agustin wrote:

On Thursday, 14 November 2013 at 21:20:57 UTC, Oleg B wrote:

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
   auto c = new C;
   c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 
'void funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and interface 
A?


Try

interface A {
  final void funcA();
}
class B {
  final void funcA() { writeln( "B.funcA()" ); }
}

class C: B, A { }


Oh sorry i mean

interface A {
  void funcA();
}

class B : A {
  final void funcA() { writeln( "B.funcA()" ); }
}

class C : B {
}


Re: D Program code on CLS

2013-11-14 Thread seany

what is the tango equivalent for system?

In my case, since my dmd, tango and things are in custom folders, 
i notice that i am getting problems when importing both std.stdio 
and tango.io.stdout



On Thursday, 14 November 2013 at 19:00:00 UTC, Ali Çehreli wrote:

On 11/13/2013 08:59 PM, Vincent wrote:

This is the code. where or what code will I use for clear the 
screen?


My Linux console environment has 'clear'. That's why I used 
system("clear") below. You may need to use system("cls") if you 
are e.g. on Windows.


import std.stdio;
import std.process;
import core.thread;

void main(string[] args)
{
while (true)
{
writeln ("Calculator Menu");
write ("Selected Number: ");

int operation;
readf (" %s", &operation);

enum duration = 3.seconds;

writefln("Thank you for %s! See you in %s.", operation, 
duration);

Thread.sleep(duration);

system("clear");
}
}

Ali




Re: Question about inheritance

2013-11-14 Thread Ali Çehreli

On 11/14/2013 01:41 PM, Akzwar wrote:

import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
 auto c = new C;
 c.funcA();
}

$ rdmd interface.d
interface.d(6): Error: class interface.C interface function 'void
funcA()' is not implemented

Why is this so? How can I use inheritance in this situation?


You should talk to Oleg B. ;)

Ali


Question about inheritance

2013-11-14 Thread Akzwar

import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
auto c = new C;
c.funcA();
}

$ rdmd interface.d
interface.d(6): Error: class interface.C interface function 'void 
funcA()' is not implemented


Why is this so? How can I use inheritance in this situation?


Re: interface and class inheritance

2013-11-14 Thread Ali Çehreli

On 11/14/2013 01:20 PM, Oleg B wrote:

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
 auto c = new C;
 c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 'void
funcA()' is not implemented

if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be interface,
not interface.B

how to workaround this without change in class B and interface A?


One way is to expose B through 'alias this' (not by inheritance) but it 
doesn't scale because currently only one 'alias this' is allowed.


import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

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

this(){
b = new B();
}

void funcA()
{
return b.funcA();
}
}

void main()
{
auto c = new C;
c.funcA();
}

Ali



Re: Dynamic array handling

2013-11-14 Thread Brad Anderson

On Thursday, 14 November 2013 at 21:38:39 UTC, seany wrote:

In Very High level languages, such as scilab, you can write

array_var = (1,2,3 ... etc)

and then you can also write

array_var = array_var(1:2,4:$)

In this case, the third element is dropped, and the same 
variable, array_var is set to be an array of a different 
length, resizing of array and so on is automated.


Is the same possible to be done in D?

say,

int [] a ; //initialize;

a ~= 1;
a ~= 2; //etc, polulate

. . . say, we fill up 10 such elements

Now, can you do like,

a = somefunction_that_drops_the_4th_element(a); // a is reset,
// and the 
length
// is 
reorganized automatically


a = a.remove(3);


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread ilya-stromberg
On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek 
Furmankiewicz wrote:
hashmap per thread is not an option. The cache may be a few GBs 
of data, there is no way we can duplicate that data per thread.


Not to mention the start up time when we have to warm up the 
cache.


How often do you change the data? Probably, you should use 
`immutable` variables.


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread bearophile

Jacek Furmankiewicz:

hashmap per thread is not an option. The cache may be a few GBs 
of data, there is no way we can duplicate that data per thread.


But is the D garbage collector able to manage efficiently enough 
associative arrays of few gigabytes? You are not dealing with a 
GC nearly as efficient as the JavaVM one.


Bye,
bearophile


Dynamic array handling

2013-11-14 Thread seany

In Very High level languages, such as scilab, you can write

array_var = (1,2,3 ... etc)

and then you can also write

array_var = array_var(1:2,4:$)

In this case, the third element is dropped, and the same 
variable, array_var is set to be an array of a different length, 
resizing of array and so on is automated.


Is the same possible to be done in D?

say,

int [] a ; //initialize;

a ~= 1;
a ~= 2; //etc, polulate

. . . say, we fill up 10 such elements

Now, can you do like,

a = somefunction_that_drops_the_4th_element(a); // a is reset,
// and the length
// is reorganized 
automatically


Re: Multidimensional array in d2?

2013-11-14 Thread seany

Oh, this is really nice, thank you very much

I also note you have a book http://ddili.org/ders/d.en/index.html
(too bad that there are chapters not translated, but thank you 
very much)!



On Thursday, 14 November 2013 at 21:24:25 UTC, Ali Çehreli wrote:


On 11/14/2013 01:18 PM, seany wrote:

> I See that in stack exchange, that it is possible to create
> multidimensional arrays like :
>
>  [][] arrayname ;

That works because in C, C++, D, etc. a multi-dimensional array 
is nothing but a single dimensional array where elements are 
arrays.


> I would like to know more about it, and learn about
multidimensional
> arrays in D2, dont find much in official sites.

I have a short "Multi-dimensional arrays" section here:

  http://ddili.org/ders/d.en/slices.html

That has a passing reference to the following new expression as 
well:


int[][] s = new int[][](2, 3);

Ali




Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz
hashmap per thread is not an option. The cache may be a few GBs 
of data, there is no way we can duplicate that data per thread.


Not to mention the start up time when we have to warm up the 
cache.


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread ilya-stromberg
On Thursday, 14 November 2013 at 21:16:15 UTC, TheFlyingFiddle 
wrote:


If that is the case are you not limited in the way you can 
update the map eg only in a single block?


Yes, it's probably not the best example. It's valid if you have 
only 1 synchronized block for map. But you can use something like 
this:


void bar()
{
   synchronized(map)
   {
 map[1] = 1;
   }

   synchronized(map)
   {
 map[2] = 2;
   }
}

Or this:

//Note: valid only if you have 1 function that use map
synchronized void bar()
{
 map[1] = 1;

 map[2] = 2;
}

Or this:

shared myMap;

synchronized class MyMap
{
   HashMap!(int, int) map;

   void foo()
   {
  map[1] = 1;
   }

   void bar()
   {
  map[2] = 2;
   }
}

//init map
shared static this()
{
   myMap = new MyMap();
}

Probably, it's the best example.


interface and class inheritance

2013-11-14 Thread Oleg B

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( "B.funcA()" ); } }

class C: B, A { }

void main()
{
auto c = new C;
c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 'void 
funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and interface A?


Re: Multidimensional array in d2?

2013-11-14 Thread Ali Çehreli


On 11/14/2013 01:18 PM, seany wrote:

> I See that in stack exchange, that it is possible to create
> multidimensional arrays like :
>
>  [][] arrayname ;

That works because in C, C++, D, etc. a multi-dimensional array is 
nothing but a single dimensional array where elements are arrays.


> I would like to know more about it, and learn about multidimensional
> arrays in D2, dont find much in official sites.

I have a short "Multi-dimensional arrays" section here:

  http://ddili.org/ders/d.en/slices.html

That has a passing reference to the following new expression as well:

int[][] s = new int[][](2, 3);

Ali



Re: opCmp on a struct keyed by an array of bytes

2013-11-14 Thread Ali Çehreli

On 11/13/2013 07:46 PM, Charles Hixson wrote:

> On 11/12/2013 04:47 PM, bearophile wrote:
>> Charles Hixson:
>>
>>> I had tried "return bytes.cmp(b.bytes);" , but it didn't occur to me
>>> that the error meant I should have used a copy?  Does this syntax
>>> mean that what's being compared is a dynamic array copy of the
>>> original static array?
>>
>> They are not copies, just slices. In case of doubts take a look at the
>> generated assembly.
>>
>> Bye,
>> bearophile
>>
> My assembly is pretty bad, the last one I was fluent in was i6502...I
> was never really fluent in m68000.  And those were back when I was using
> an Apple.
>
> OTOH, while slice is a better term for what I meant...generally when one
> makes a copy of an object, one is only duplicating the pointers to it,
> and that's what I meant.  (Though since the original was a struct, slice
> is a much better term.  Still, on a 64 bit machine the and an 8 byte
> key, the slice is twice the size of the original.  And the only
> benefit(?) is that if the dup was changed, so would be the original.
> Which is what the I thought the const at the end of the declaration was
> supposed to prevent.)

I think what we are agreeing here is that there should be a cmp() 
specialization for fixed-length arrays, both for performance reasons and 
for convenience.


In the absence of that specialization, your for loop works well. 
std.algorithm.cmp is another option but it requires an InputRange. Since 
fixed-length arrays do not satisfy the requirements of InputRange 
(cannot provide popFront()), we must get a slice of all of its elements.


Still, I have a feeling that ldc would be able to use the information 
that the length of the slice is based on a constant expression and 
produce faster code. (No citation known. :p)


Ali



Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread TheFlyingFiddle

2) Use `shared` storage class and mutex like this:

import vibe.utils.hashmap;

shared HashMap!(int, int) map;

void foo()
{
   synchronized
   {
  //use map
  map[1] = 1;
   }
}


Locking every time you use the map dosn't rly seem reasonable. 
It's not particulary fast and you might forget to lock the map at 
some point (or does the shared modifier not allow you to do this 
in D?)


I'm not that fammiliar with the synchronzed statement but 
shouldn't it be locked on some object?


void bar()
{
   //Can one thread be in this block...
   synchronized
   {
 map[1] = 1;
   }

   //... while another thread is in this block?
   synchronized
   {
 map[2] = 2;
   }
}

If that is the case are you not limited in the way you can update 
the map eg only in a single block?





Multidimensional array in d2?

2013-11-14 Thread seany
I See that in stack exchange, that it is possible to create 
multidimensional arrays like :


 [][] arrayname ;

and here : 
http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html


that such is not possible.

I would like to know more about it, and learn about 
multidimensional arrays in D2, dont find much in official sites.


Thank you


Re: Only run code if *not* unittesting

2013-11-14 Thread Jared
On Thursday, 14 November 2013 at 21:02:21 UTC, Adam D. Ruppe 
wrote:

There's a version(unittest), so

version(unittest)
{}
else
{
  /* only run when unittesting */
}

should work for you.


That worked... except backwards:

version(unittest) {
  /* executed when --unittest flag used */
} else {
  /* executed all other times */
}


Re: Only run code if *not* unittesting

2013-11-14 Thread Adam D. Ruppe

There's a version(unittest), so

version(unittest)
{}
else
{
  /* only run when unittesting */
}

should work for you.


Re: Figuring out the returntype opDipatch

2013-11-14 Thread TheFlyingFiddle
After looking at the DIP some more i can see that my suggestion 
implementation does not make any sense (and i missed some of the 
syntax). If it can be done with AST's i don't have a sugestion 
for it.


Only run code if *not* unittesting

2013-11-14 Thread Jared

Hey there,

So I'd like to limit code execution in my main function to only 
execute if I haven't passed the --unittest flag during 
compilation.


Is this possible?


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread ilya-stromberg
On Thursday, 14 November 2013 at 20:00:10 UTC, Jacek 
Furmankiewicz wrote:
I looked at the dcollections docs, but none of their 
collections seem thread safe. The vibe.d I guess is because it 
is meant to be used from async I/O in a single thread...but 
once you add multi-threading to an app I am guessing it would 
not be usable.


No, you can:
1) Use different hashmap per tread. I don't know your situation, 
but it can be possible fo read-only cache like this:


import vibe.utils.hashmap;

HashMap!(int, int) map;

void foo()
{
   //use map
   map[1] = 1;
}

2) Use `shared` storage class and mutex like this:

import vibe.utils.hashmap;

shared HashMap!(int, int) map;

void foo()
{
   synchronized
   {
  //use map
  map[1] = 1;
   }
}


Re: Compile-time sets and hash tables

2013-11-14 Thread Philippe Sigaud
On Thu, Nov 14, 2013 at 9:31 PM, Andrej Mitrovic
 wrote:
> On 11/14/13, Philippe Sigaud  wrote:
>  - I'd greatly like for those sets or hash tables to be
>> CTFE-compatible.
>
> Well if it's only used in CTFE, I'd imagine a simple struct wrapping
> an array and doing "!canFind" when adding elements would do the job,
> no?

The trick is, I don't use them only during CT evaluation. In that
case, yes, linear search would do the trick.
But my code is used at runtime and also, from time to time, during
compilation (a new Pegged parser engine).
Hence my need.

But no worries, I spent the day writing and testing code for a small
set/hash implementation. It supports user-defined types (it
automatically creates a reasonable hashing function), support sets of
sets (unlike AA which do not accept other AA as keys) and is both
runtime and compile-time compatible. It's a bit slower than the
builtin, but I'm using the code only to generate other code, not in
performance-critical code.

I also wrote a small string mixin that generates a big switch
statement and it's 40% faster than a standard AA. That's fun. Not
useful, mind, but fun.


Re: Figuring out the returntype opDipatch

2013-11-14 Thread TheFlyingFiddle
On Thursday, 14 November 2013 at 20:39:35 UTC, TheFlyingFiddle 
wrote:
On Sunday, 3 November 2013 at 10:48:45 UTC, Jacob Carlborg 
wrote:

On 2013-11-03 03:15, TheFlyingFiddle wrote:


In the IReflectionable interface:

interface IReflectionable
{
   final P funcPtr(P)(string fun) if (is(P == delegate))
   {
   //Using mangeling for overloads and type safety
   auto ptr = delPtr_impl(mangle!P(fun));

   P del;
   del.ptr = cast(typeof(del.ptr))ptr[0];
   del.funcptr = cast(typeof(del.funcptr))ptr[1];
   return del;
   }

   final P funcPtr(P)(string fun) if (is(P == function))
   {
   //Using mangeling for overloads and type safety
   auto ptr = funcPtr_impl(mangle!(P)(fun));
   return cast(P)ptr;
   }

   final ?? opDispatch(string name, Params...)(Params params)
   {
  alias ?? delegate(Params) del_type;
  auto del = funcPtr!(del_type)(name);

  static if(?? == void)
 del(params);
  else
 return del(params);
   }

   protected Tuple!(void*, void*) delPtr_impl(string s);
   protected void* funcPtr_impl(string s);
}

What i'm interested in is determining what type ?? should be. 
Variant
works but if possible i would like to avoid it. This would 
require me to
know about the code at the invokation site. (So i'm guessing 
it might

not be possible)


I have the same problem as well. I haven't figured out the 
best way to solve this yet.


Might this be something you could solve using the DIP50 AST 
macros?


Something like


interface IRefectionable
{
   //I'm assuming you can use a macro as opDispatch
   macro opDispatch(string s, Params...)(Context context, 
Ast!(Params) ast)

   {
   //The name is sort of bad
   enum returnType = context.?? //Look at the stuff in the 
context to figure out what the returnType would be.


   return <|
   alias ?? delegate(Params) del_type;
   auto del = funcPtr!(del_type)(name);

   static if(?? == void)
  del(params);
   else
  return del(params);
   }
}

unittest
{
   IReflectionable refl = new Foo();

   refl.bar(1); //void is infered since not setting any value.
   int baz = refl.baz("Hello");
   auto baz2 = refl.baz("hello"); //Can't work.

}


Edit: ?? should be replaced with $returnType



Re: Figuring out the returntype opDipatch

2013-11-14 Thread TheFlyingFiddle

On Sunday, 3 November 2013 at 10:48:45 UTC, Jacob Carlborg wrote:

On 2013-11-03 03:15, TheFlyingFiddle wrote:


In the IReflectionable interface:

interface IReflectionable
{
final P funcPtr(P)(string fun) if (is(P == delegate))
{
//Using mangeling for overloads and type safety
auto ptr = delPtr_impl(mangle!P(fun));

P del;
del.ptr = cast(typeof(del.ptr))ptr[0];
del.funcptr = cast(typeof(del.funcptr))ptr[1];
return del;
}

final P funcPtr(P)(string fun) if (is(P == function))
{
//Using mangeling for overloads and type safety
auto ptr = funcPtr_impl(mangle!(P)(fun));
return cast(P)ptr;
}

final ?? opDispatch(string name, Params...)(Params params)
{
   alias ?? delegate(Params) del_type;
   auto del = funcPtr!(del_type)(name);

   static if(?? == void)
  del(params);
   else
  return del(params);
}

protected Tuple!(void*, void*) delPtr_impl(string s);
protected void* funcPtr_impl(string s);
}

What i'm interested in is determining what type ?? should be. 
Variant
works but if possible i would like to avoid it. This would 
require me to
know about the code at the invokation site. (So i'm guessing 
it might

not be possible)


I have the same problem as well. I haven't figured out the best 
way to solve this yet.


Might this be something you could solve using the DIP50 AST 
macros?


Something like


interface IRefectionable
{
   //I'm assuming you can use a macro as opDispatch
   macro opDispatch(string s, Params...)(Context context, 
Ast!(Params) ast)

   {
   //The name is sort of bad
   enum returnType = context.?? //Look at the stuff in the 
context to figure out what the returnType would be.


   return <|
   alias ?? delegate(Params) del_type;
   auto del = funcPtr!(del_type)(name);

   static if(?? == void)
  del(params);
   else
  return del(params);
   }
}

unittest
{
   IReflectionable refl = new Foo();

   refl.bar(1); //void is infered since not setting any value.
   int baz = refl.baz("Hello");
   auto baz2 = refl.baz("hello"); //Can't work.

}




Re: Compile-time sets and hash tables

2013-11-14 Thread Andrej Mitrovic
On 11/14/13, Philippe Sigaud  wrote:
 - I'd greatly like for those sets or hash tables to be
> CTFE-compatible.

Well if it's only used in CTFE, I'd imagine a simple struct wrapping
an array and doing "!canFind" when adding elements would do the job,
no?


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz

Thanks for the links.

I looked at the dcollections docs, but none of their collections 
seem thread safe. The vibe.d I guess is because it is meant to be 
used from async I/O in a single thread...but once you add 
multi-threading to an app I am guessing it would not be usable.




Re: Cannot cast char[] to string.

2013-11-14 Thread Ali Çehreli

On 11/14/2013 11:43 AM, Dicebot wrote:

On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:

I'm trying to use http://dlang.org/phobos/std_net_curl.html and when i
compile the same example i get:

cannot implicitly convert expression (get(cast(const(char)[])address,
AutoProtocol())) of type char[] to string

string address = "http://dlang.org";;
string _data = get(address);


`get` returns mutable data, one should respect it:

char[] data = get(address); // or just use `auto data = `


However, that data can automatically be converted to string if get() 
were pure. (I can understand how such a function cannot be.)


A simple wrapper:

import std.net.curl;
import std.exception;

string getAsString(string address)
{
auto result = get(address);
return assumeUnique(result);
}

void main()
{
string content = getAsString("dlang.org");
}

Ali



Re: Cannot cast char[] to string.

2013-11-14 Thread Brad Anderson

On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
I'm trying to use http://dlang.org/phobos/std_net_curl.html and 
when i compile the same example i get:


cannot implicitly convert expression 
(get(cast(const(char)[])address, AutoProtocol())) of type 
char[] to string


string address = "http://dlang.org";;
string _data = get(address);


You have two options:

string address = "http://dlang.org";;
string _data = get(address).idup(); // create immutable copy

or

string address = "http://dlang.org";;
char[] _data = get(address); // store mutable reference

A string (which is just an alias of immutable(char)[]) can't be 
made from a char[] without an assertion that the data pointed to 
is, in fact, immutable.  You can do that using assumeUnique 
(inexplicably found in std.exception).


Re: Cannot cast char[] to string.

2013-11-14 Thread Dicebot

On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
I'm trying to use http://dlang.org/phobos/std_net_curl.html and 
when i compile the same example i get:


cannot implicitly convert expression 
(get(cast(const(char)[])address, AutoProtocol())) of type 
char[] to string


string address = "http://dlang.org";;
string _data = get(address);


`get` returns mutable data, one should respect it:

char[] data = get(address); // or just use `auto data = `


Cannot cast char[] to string.

2013-11-14 Thread Agustin
I'm trying to use http://dlang.org/phobos/std_net_curl.html and 
when i compile the same example i get:


cannot implicitly convert expression 
(get(cast(const(char)[])address, AutoProtocol())) of type char[] 
to string


string address = "http://dlang.org";;
string _data = get(address);


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread ilya-stromberg
On Thursday, 14 November 2013 at 17:36:09 UTC, Jacek 
Furmankiewicz wrote:
In our Java code, we make heavy use of ConcurrentHashMap for 
in-memory caches:


Try to look dcollections:
http://www.dsource.org/projects/dcollections

Also, Vibe.d has own hashmap:
https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/utils/hashmap.d


Re: D Program code on CLS

2013-11-14 Thread Ali Çehreli

On 11/13/2013 08:59 PM, Vincent wrote:


This is the code. where or what code will I use for clear the screen?


My Linux console environment has 'clear'. That's why I used 
system("clear") below. You may need to use system("cls") if you are e.g. 
on Windows.


import std.stdio;
import std.process;
import core.thread;

void main(string[] args)
{
while (true)
{
writeln ("Calculator Menu");
write ("Selected Number: ");

int operation;
readf (" %s", &operation);

enum duration = 3.seconds;

writefln("Thank you for %s! See you in %s.", operation, duration);
Thread.sleep(duration);

system("clear");
}
}

Ali



Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread JN
On Thursday, 14 November 2013 at 18:08:22 UTC, Jacek 
Furmankiewicz wrote:
So how do existing D applications (especially the high perf 
ones in let's say the financial sector) deal with having some 
part of the data in memory and keeping it in sync with the DB 
source?


They don't, because there aren't really such apps in the wild yet.


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread TheFlyingFiddle
On Thursday, 14 November 2013 at 18:08:22 UTC, Jacek 
Furmankiewicz wrote:
So how do existing D applications (especially the high perf 
ones in let's say the financial sector) deal with having some 
part of the data in memory and keeping it in sync with the DB 
source?


Good question. I have no idea.


is there a different idiom or approach in D?


Well in D the prefered way (or recommended according to TDPL) to 
do concurrent sharing of resources is to share resources via 
message passing.


So in this case a single thread would be responsible for the 
caching of data in memory and other threads would ask this thread 
for data through message passing.


If this way is faster/better then javas ConcurrentHashMap i am 
not sure.






Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz
So how do existing D applications (especially the high perf ones 
in let's say the financial sector) deal with having some part of 
the data in memory and keeping it in sync with the DB source?


This must be a very common requirement for any app with realtime 
or close-to-realtime SLAs.


is there a different idiom or approach in D?


Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread TheFlyingFiddle
On Thursday, 14 November 2013 at 17:36:09 UTC, Jacek 
Furmankiewicz wrote:
In our Java code, we make heavy use of ConcurrentHashMap for 
in-memory caches:


http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html

We use it mostly for in-memory caches. A background thread 
wakes up every X seconds and resyncs the cache with whatever 
changes occurred in the DB. In the meantime, all the incoming 
requests can read from the same cache without any concurrency 
issues and excellent performance.


All the major Java Map implementations also support the 
NavigableMap interface:


http://docs.oracle.com/javase/7/docs/api/java/util/NavigableMap.html

which allows you to get the key closest to the one you are 
looking for (either up or down). This is very useful when you 
have hierarchies of business rules that have effective date 
ranges and you are trying to find which rules is active on a 
particular day.


I read up the chapter on associative arrays in D, but I do not 
see anything similar to this functionality in there.


Could anyone point me to what would be the closest D 
equivalents (maybe in an external library if not part of 
Phobos) so we can playing around with them?


Much appreciated
Jacek


D does not have alot of diffrent containers atm. This work has 
been postponed until a working version of std.allocators is 
implemented. So atleast in the phobos library right now you will 
not find what you are looking for.




What is the closest to ConcurrentHashMap and NavigableMap in Java?

2013-11-14 Thread Jacek Furmankiewicz
In our Java code, we make heavy use of ConcurrentHashMap for 
in-memory caches:


http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html

We use it mostly for in-memory caches. A background thread wakes 
up every X seconds and resyncs the cache with whatever changes 
occurred in the DB. In the meantime, all the incoming requests 
can read from the same cache without any concurrency issues and 
excellent performance.


All the major Java Map implementations also support the 
NavigableMap interface:


http://docs.oracle.com/javase/7/docs/api/java/util/NavigableMap.html

which allows you to get the key closest to the one you are 
looking for (either up or down). This is very useful when you 
have hierarchies of business rules that have effective date 
ranges and you are trying to find which rules is active on a 
particular day.


I read up the chapter on associative arrays in D, but I do not 
see anything similar to this functionality in there.


Could anyone point me to what would be the closest D equivalents 
(maybe in an external library if not part of Phobos) so we can 
playing around with them?


Much appreciated
Jacek


Re: function XXXX conflict with YYYY

2013-11-14 Thread Agustin
Thanks, i updated to v2.064.2 and everything works just fine. I 
had this issue long time ago and it was annoying to have multiple 
function with different names.


Re: function XXXX conflict with YYYY

2013-11-14 Thread Gary Willoughby

On Thursday, 14 November 2013 at 17:13:18 UTC, H. S. Teoh wrote:

It only takes one twig to burn down a forest.


http://www.youtube.com/watch?v=d-S1o5OmMMo


Re: function XXXX conflict with YYYY

2013-11-14 Thread Gary Willoughby

On Thursday, 14 November 2013 at 16:59:25 UTC, evilrat wrote:
mmm.. this is strange because for simple types it works 
fine(i'm using dmd 2.064.2). can you show reduced example of 
this?


See bearophile's answer.


Re: function XXXX conflict with YYYY

2013-11-14 Thread H. S. Teoh
On Thu, Nov 14, 2013 at 05:27:38PM +0100, Agustin wrote:
> final uint registerEvent(T, J)(IPlugin, void delegate(J))
> {
>  
> }
> 
> final uint registerEvent(IPlugin, EventHandler, EventInfo, ulong)
> {
>  
> }
> 
> There seems to be a problem when having two function with same name
> but different parameters. Only happend when one of the function use
> templates. Is that a compiler limitation?

On older compilers, you can work around this limitation by adding empty
compile-time parameters to the second function:

final uint registerEvent()(IPlugin, EventHandler, EventInfo, ulong)
{ ... }

>From what I heard, this limitation has been removed in the latest
compiler.


T

-- 
It only takes one twig to burn down a forest.


Re: function XXXX conflict with YYYY

2013-11-14 Thread evilrat
mmm.. this is strange because for simple types it works fine(i'm 
using dmd 2.064.2). can you show reduced example of this?


Re: function XXXX conflict with YYYY

2013-11-14 Thread Gary Willoughby

On Thursday, 14 November 2013 at 16:27:39 UTC, Agustin wrote:

final uint registerEvent(T, J)(IPlugin, void delegate(J))
{
 
}

final uint registerEvent(IPlugin, EventHandler, EventInfo, 
ulong)

{
 
}

There seems to be a problem when having two function with same 
name but different parameters. Only happend when one of the 
function use templates. Is that a compiler limitation?


This works fine with v2.064.2

import std.stdio;

class ClassName
{
final uint registerEvent(T, J)(T x, void delegate(J))
{
return 1;
}

final uint registerEvent(long, string, int, ulong)
{
return 1;
}
}

void main(string[] args)
{
auto x = new ClassName();

	writefln("%s", x.registerEvent!(int, int)(1, delegate(int x) 
{}));

writefln("%s", x.registerEvent(1, "sdsds", 3, 4));
}


Re: function XXXX conflict with YYYY

2013-11-14 Thread bearophile

Agustin:


final uint registerEvent(T, J)(IPlugin, void delegate(J))
{
 
}

final uint registerEvent(IPlugin, EventHandler, EventInfo, 
ulong)

{
 
}

There seems to be a problem when having two function with same 
name but different parameters. Only happend when one of the 
function use templates. Is that a compiler limitation?


Have you tried an updated DMD compiler? I think this was recently 
fixed.


Bye,
bearophile


Re: function XXXX conflict with YYYY

2013-11-14 Thread evilrat

On Thursday, 14 November 2013 at 16:27:39 UTC, Agustin wrote:

final uint registerEvent(T, J)(IPlugin, void delegate(J))
{
 
}

final uint registerEvent(IPlugin, EventHandler, EventInfo, 
ulong)

{
 
}

There seems to be a problem when having two function with same 
name but different parameters. Only happend when one of the 
function use templates. Is that a compiler limitation?


this is by design. templates are generic so they can take 
anything(by default), this way shadowing specialized functions 
which is more suitable for certain types.


function XXXX conflict with YYYY

2013-11-14 Thread Agustin

final uint registerEvent(T, J)(IPlugin, void delegate(J))
{
 
}

final uint registerEvent(IPlugin, EventHandler, EventInfo, ulong)
{
 
}

There seems to be a problem when having two function with same 
name but different parameters. Only happend when one of the 
function use templates. Is that a compiler limitation?


Re: Chris E. Miller ToolTip (D1)

2013-11-14 Thread Heinz
You have to manually set the tooltip's max width to a fixed value 
using the tooltip handle and Win32 API, by doing this you're 
telling the tooltip object it is a multiline tooltip and from now 
on it will accept \r\n as end of line:


ttip = new ToolTip;
SendMessageA(ttip.handle, TTM_SETMAXTIPWIDTH, 0, 250);
ttip.setToolTip(find, "a=n (not approved)\r\no=n (not 
outlooked)\r\nt>0 (total > 0));


That's it, it works (i tested it).

By the way, the DFL version on Chris' site is for D1 but there's 
this version for D2 (i use both): 
https://github.com/Rayerd/dfl/tree/master/win32/dfl


Re: Chris E. Miller ToolTip (D1)

2013-11-14 Thread jicman

On Thursday, 14 November 2013 at 14:38:49 UTC, Dicebot wrote:
Not many D1 users are still here :( I personally, have zero 
idea what library are you even speaking about.


I am talking about this library:
http://www.dprogramming.com/dfl.php

specifically, this object,
http://wiki.dprogramming.com/DflDoc/Tooltip

The idea is to have multiple lines in a hover-mouse like prompt.

Ok, thanks for the reply.  By the way, before D2, there was D1.  
We should always remember our ancestors. :-)


josé


Re: Linking from source-code

2013-11-14 Thread Adam D. Ruppe
On Thursday, 14 November 2013 at 13:49:02 UTC, Andrea Fontana 
wrote:

I think it's a better idea to make it works from dmd/rdmd.


pragma(lib) works almost everywhere with dmd* except phobos, 
due to how that is compiled.


rdmd ignores modules in the std namespace when building the 
dependency list, so dmd only sees the std.net.curl as a header 
import, and doesn't pass on the library.


If you did dmd main.d dmd2/src/phobos/std/net/curl.d, it would 
work, but not just dmd main.d where it finds phobos automatically.


* pragma(lib) doesn't work on ldc and gdc last i heard though.


But, I put the blame here on phobos being compiled as a .lib 
without curl built in.


Re: Chris E. Miller ToolTip (D1)

2013-11-14 Thread Dicebot
Not many D1 users are still here :( I personally, have zero idea 
what library are you even speaking about.


Re: Chris E. Miller ToolTip (D1)

2013-11-14 Thread jicman

On Wednesday, 13 November 2013 at 18:58:44 UTC, jicman wrote:


Greetings.

Trying to see if anyone can help with this one...

Chris Miller wrote a wonderful set of libraries for Windows 
programming.  One of the libraries was a ToolTip library that 
when called against an object, when the mouse hovered over that 
object, it will display the string that it was set for that 
sepcific object. Everything is working fine with the exception 
that I would like to break the string set to an specific object 
to multiple lines.  For example, I have set that ToolTip to be,


a=n (not approved)
o=n (not outlooked)
t>0 (total > 0)

but, when I set it, and have tried multiple ways, they all 
display in one line, ie.


a=n (not approved)o=n (not outlooked)t>0 (total > 0)

The code I am using is,

ttip = new ToolTip;
ttip.setToolTip(this, "Testing...");
ttip.setToolTip(find,
r"
a=n (not approved invoices
o=n (not outlooked projects/tasks
"
);

I have also tried to use \n and \r\n.  Any other thoughts?


Does anyone knows if this is even possible?  Thanks.

josé


Re: Deimos rules?

2013-11-14 Thread Joseph Rushton Wakeling

On 14/11/13 13:13, Jacob Carlborg wrote:

I would say stay as close to the original C code as possible. Although I do
prefer to translate typedefs like int8_t to real D types, like byte, if they 
exist.


In some ways I wonder why D's types aren't just specified according to the 
number of bits -- int8, int16, int32, int64 instead of byte, short, int, long. 
I suppose on balance it's probably less readable and easier to make mistakes 
writing.


More generally -- is it considered desirable to provide not only the C-like 
translation, but also a higher-level "D-ified" wrapper?  Or is that considered 
overkill for Deimos?


Re: Disassembly Tool

2013-11-14 Thread Namespace
On Thursday, 14 November 2013 at 10:35:26 UTC, dennis luehring 
wrote:

agner fogs:
http://www.agner.org/optimize/#objconv

I love that. :) Thanks.
But it is much assembler code. A lot more than my script should 
contain. Maybe druntime is included? Any idea to cut it down?


Re: D Program code on CLS

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 03:35:59 UTC, Vincent wrote:

how can I clear the screen for example I input first letter (A)
and second letter (B) and show the result AB then after pressing
enter it will clear the screen before it display again the Input
first letter


Input first letter : A
Input second letter: B
result: AB
Input first letter: _

it should not be displaying the previous output like this...
After showing the result it should be cleared the previous 
output

before it shows the input first letter again...


You mean something like that:

---

import std.stdio;
import core.thread;

void main() {
foreach (i; 0..10) {
write("\r", i);
stdout.flush();
Thread.sleep(250.msecs);

}

}

---

If yes, you want to play with carriage return and flushing 
terminal.


Re: Linking from source-code

2013-11-14 Thread Andrea Fontana
On Thursday, 14 November 2013 at 12:35:16 UTC, Jacob Carlborg 
wrote:

On 2013-11-14 13:12, Andrea Fontana wrote:


So I though this function didn't exist. Why doesn't it work?


I doesn't work when D modules are used like header files. See: 
https://d.puremagic.com/issues/show_bug.cgi?id=2776


Another idea would be to use dub:

http://code.dlang.org/


I think it's a better idea to make it works from dmd/rdmd.

It should be a (working) language feature. It makes no sense for 
me to use a third party tool for this. Have I to use dub to 
compile a single-file-project that use just curl or a simple 
library? If implemented inside language, all compiler should 
support it, and IDE just support it automagically :)


It would be cool to just write rdmd main.d ignoring dependencies 
hell :)


BTW: you say "used like header files". You mean files that are 
not "compiled" but "imported"?




Re: Linking from source-code

2013-11-14 Thread Jacob Carlborg

On 2013-11-14 13:12, Andrea Fontana wrote:


So I though this function didn't exist. Why doesn't it work?


I doesn't work when D modules are used like header files. See: 
https://d.puremagic.com/issues/show_bug.cgi?id=2776


Another idea would be to use dub:

http://code.dlang.org/

--
/Jacob Carlborg


Re: Linking from source-code

2013-11-14 Thread Jacob Carlborg

On 2013-11-14 12:46, Ali Çehreli wrote:


I have never used it but there is pragma(lib):

   http://dlang.org/pragma.html


Unfortunately that doesn't work with .di files. Although it might work 
for Deimos projects.


--
/Jacob Carlborg


Re: Deimos rules?

2013-11-14 Thread Jacob Carlborg

On 2013-11-13 23:01, Xavier Bigand wrote:

I work on XCB integration, so I think that I can add bindings in deimos.

C headers are translated to d modules by using DStep or manually?
If manually need I respect some syntactical rules?


I would say stay as close to the original C code as possible. Although I 
do prefer to translate typedefs like int8_t to real D types, like byte, 
if they exist.


--
/Jacob Carlborg


Re: Linking from source-code

2013-11-14 Thread Andrea Fontana

On Thursday, 14 November 2013 at 11:46:19 UTC, Ali Çehreli wrote:

On 11/14/2013 03:43 AM, Andrea Fontana wrote:
Is there a way to define a library to link inside d source? I 
can't find

anything about it.


I have never used it but there is pragma(lib):

  http://dlang.org/pragma.html

Ali


Hmmm. I see there's a pragma("lib", "curl") inside std.net.curl.

but look at simple test:

import std.net.curl;
import std.stdio;

void main()
{
get("dlang.org").writeln;
}

rdmd test.d -> linking error on curl
dmd test.d -> linking error on curl
dmd test.d -L-lcurl -L-lphobos2 -> works

So I though this function didn't exist. Why doesn't it work?



Re: about std.string.representation

2013-11-14 Thread Ali Çehreli

On 11/13/2013 04:32 PM, bioinfornatics wrote:

Hi,
I try to understand which type char, dchar, wchar will give
ubyte,ushort,uint…


And for templates, there is std.range.ElementEncodingType:

import std.stdio;
import std.range;

void foo(R)(R range)
{
// In contrast, ElementType!R for strings is always dchar
writeln(typeid(ElementEncodingType!R));
}

void main()
{
string  t  = "test";
char[]  c  = "test".dup;
dchar[] dc = "test"d.dup;
wchar[] wc = "test"w.dup;

foo(t);
foo(c);
foo(dc);
foo(wc);
}

Prints:

immutable(char)
char
dchar
wchar

Ali



Re: Maximum size of an string ?

2013-11-14 Thread Ali Çehreli

On 11/14/2013 02:10 AM, Jean Christophe wrote:

> Has someone tested the maximum size of a D string variable for both 32
> and 64 bits platforms ? Is it different from the maximum size of a 
char[] ?


Both string and char[] are implemented in the same way: a size_t for 
length and a pointer to data. (D arrays know their sizes.)


So, the theoretical limit for both are size_t, which is the equivalent 
of uint or ulong dependending on 32-bit versus 64-bit.


Ali



Re: Linking from source-code

2013-11-14 Thread Ali Çehreli

On 11/14/2013 03:43 AM, Andrea Fontana wrote:

Is there a way to define a library to link inside d source? I can't find
anything about it.


I have never used it but there is pragma(lib):

  http://dlang.org/pragma.html

Ali



Linking from source-code

2013-11-14 Thread Andrea Fontana
Is there a way to define a library to link inside d source? I 
can't find anything about it.


IMHO it would very useful for deimos libraries or curl. So when 
you import a library, it has embedded the linking instruction.


For import we write:

import std.stdio;

That means "more or less": look for std/stdio.d inside search 
directories.


Why not then:

import_lib curl;  // or other kw

It should mean link libcurl on linux, curl.dll on windows and so 
on.


Running code with rdmd will not need any extra configuration.
Using version we can link right library (debug/release/etc).

Writing:

dmd hello_world.d -L-lcurl

sounds me like we have to write:
dmd hello_world.d -I"std/stdio.d" -I"std/curl.d" -L-lcurl

To import "headers"


Re: Disassembly Tool

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 10:42:06 UTC, Namespace wrote:
On Thursday, 14 November 2013 at 10:35:26 UTC, dennis luehring 
wrote:

Am 14.11.2013 10:48, schrieb Namespace:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm

looking for an alternative. Is there one? And I don't want
obj2asm, I'm not willing to pay 15$.



maybe:

distorm:
http://www.ragestorm.net/distorm/

ida freeware:
https://www.hex-rays.com/products/ida/support/download_freeware.shtml
(32bit only)

agner fogs:
http://www.agner.org/optimize/#objconv


Are these compatible with the dmd obj files and the dmd format?


IDA supports tones of object formats and architectures.

Problems may come when it comes to free version of it.
AFAIK it supports only x86 up to 32bits.

DPASTE disassembly support will be back at some point, when we
figure out how to save bandwidth


Re: Disassembly Tool

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 10:14:05 UTC, Namespace wrote:

On Thursday, 14 November 2013 at 09:55:02 UTC, Tourist wrote:

On Thursday, 14 November 2013 at 09:53:42 UTC, Namespace wrote:
On Thursday, 14 November 2013 at 09:48:38 UTC, Namespace 
wrote:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm looking for an alternative. Is there one? And I don't 
want obj2asm, I'm not willing to pay 15$.


Forget to say: I'm on Windows.


OllyDbg, highly recommended.


Looks good, I'll give it a try later.
Is there a reason why obj2asm is free for linux and osx, but 
not for windows?


Maybe they charge it for compiling & packaging it on Windows.
AFAIK same thing happened with Xchat for Windows


Re: Disassembly Tool

2013-11-14 Thread Namespace
On Thursday, 14 November 2013 at 10:35:26 UTC, dennis luehring 
wrote:

Am 14.11.2013 10:48, schrieb Namespace:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm

looking for an alternative. Is there one? And I don't want
obj2asm, I'm not willing to pay 15$.



maybe:

distorm:
http://www.ragestorm.net/distorm/

ida freeware:
https://www.hex-rays.com/products/ida/support/download_freeware.shtml
(32bit only)

agner fogs:
http://www.agner.org/optimize/#objconv


Are these compatible with the dmd obj files and the dmd format?


Re: Disassembly Tool

2013-11-14 Thread dennis luehring

Am 14.11.2013 10:48, schrieb Namespace:

Since the disassembly on Dpaste doesn't work for me anymore, I'm
looking for an alternative. Is there one? And I don't want
obj2asm, I'm not willing to pay 15$.



maybe:

distorm:
http://www.ragestorm.net/distorm/

ida freeware:
https://www.hex-rays.com/products/ida/support/download_freeware.shtml
(32bit only)

agner fogs:
http://www.agner.org/optimize/#objconv


Maximum size of an string ?

2013-11-14 Thread Jean Christophe


Hi :)

Has someone tested the maximum size of a D string variable for 
both 32 and 64 bits platforms ? Is it different from the maximum 
size of a char[] ?


Oo`

-- JC


Re: Disassembly Tool

2013-11-14 Thread Namespace

On Thursday, 14 November 2013 at 09:55:02 UTC, Tourist wrote:

On Thursday, 14 November 2013 at 09:53:42 UTC, Namespace wrote:

On Thursday, 14 November 2013 at 09:48:38 UTC, Namespace wrote:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm looking for an alternative. Is there one? And I don't 
want obj2asm, I'm not willing to pay 15$.


Forget to say: I'm on Windows.


OllyDbg, highly recommended.


Looks good, I'll give it a try later.
Is there a reason why obj2asm is free for linux and osx, but not 
for windows?


Re: Disassembly Tool

2013-11-14 Thread Tourist

On Thursday, 14 November 2013 at 09:53:42 UTC, Namespace wrote:

On Thursday, 14 November 2013 at 09:48:38 UTC, Namespace wrote:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm looking for an alternative. Is there one? And I don't want 
obj2asm, I'm not willing to pay 15$.


Forget to say: I'm on Windows.


OllyDbg, highly recommended.


  1   2   >