fill array using a lambda function

2013-10-10 Thread dominic jones

Hello,

I want to fill an array with random numbers without resorting to 
loops, i.e. by doing something like the following, if it were 
possible:


  fill!(function double(){ return uniform(0.0, 1.0);})(x[]);

Is there a simple way of doing this?

Thank you,
Dominic Jones

P.S. I am aware of the function uniformDistribution, but it makes 
the sum of the elements equal to 1, which I don't want.


operations on rectangular arrays

2012-11-14 Thread dominic jones

Hello,

This code snippet:
  int[][] A = [[1, 2], [2, 3]];
  int[][] B = [[2, 3], [1, 2]];
  int[2][2] C;
  C = A[][] + B[][];

fails with the message:
  "Error: cannot implicitly convert expression (A[][] + B[][]) of 
type int[][] to int[2LU][]"


Is there a succinct work-around (i.e. without using foreach)? And 
will such statements one day be possible?


The section in http://dlang.org/arrays.html on rectangular arrays 
offers no use cases to follow.


Thank you,
Dominic Jones



primitive type operator overload

2012-04-20 Thread dominic jones

Hello,

I want to overload a primitive type operator so that I can do 
something like


double a;
myStruct b;
writeln(a + b);

but have no idea how to do it. Something similar(?) is already 
implemented in the language, i.e.


double x;
double[] y;
writeln(x + y);

but after searching the dmd2/src, what I found didn't offer any 
help.


-Dominic Jones


template expressions in C++ to an equivalent in D

2011-10-28 Thread Dominic Jones
Hello,

I want to compute, for example
d = a + b + c
where a..d are of some derived type, without incurring the cost of temporaries 
for each overloaded operation.

In a similar post a while ago, Walter Bright proposed using function literals 
instead of template expressions to do this. After looking at function literals, 
I can't work out what he had in mind with this suggestion. May someone present 
a succinct
complete example to demonstrate how solve this?

Many thanks,
Dominic Jones


Re: FIFO stack

2011-10-28 Thread Dominic Jones
To conclude the matter regarding the absence of a FIFO stack in the
standard library and the not so good alternative of arrays (in
particular where there are a significant number of push-pops and the
maximum length is not initially known):

Does anyone in-the-know know if something like "DList" (a doubly
linked list) will be added to "std.containers" in the near future?

I, for one, would very much appreciate its implementation in the
standard library.

Regards,
Dominic


Re: FIFO stack

2011-10-26 Thread Dominic Jones
> Also an plain array is a good stack. :)

I'd rather not use a plain array because (I assume) that when I push
or pop using arrays, a swap array is created to resize the original.
If this is not the case, then an array will certainly do.
-Dominic


FIFO stack

2011-10-26 Thread Dominic Jones
Hello,

I was looking for a FIFO stack in std.containers but only found SList
and Array which both appear to essentially operate as LIFO stacks. Is
there any standard container with which I can push items on to a list,
then later pop them off from the bottom of that list? If so, then how?

Thank you,
Dominic Jones


D programs linked with C/MPI based libraries

2011-04-07 Thread Dominic Jones
Hello,

Is it possible to call within a D driver program library functions which are
programmed in C/C++ with the message passing interface (MPI)? I want to write
a program which makes use of the ParMetis library
(http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview).

Supposing it is possible, to compile and run C/MPI programs, wrapper commands
are used, such as mpicc and mpirun. What would be done in D?

Thank you,
Dominic Jones


intrinsic min and max for ints

2011-02-16 Thread Dominic Jones
Hello,

Is there a library function for min/max for integers. I would rather not use
the ?-operator, it's rather clumsy. I looked in the standard lib and only
found f(min|max).

Thank you,
Dominic Jones


Re: using a binary tree container

2011-02-11 Thread Dominic Jones
== Quote from bearophile (bearophileh...@lycos.com)'s article
> Dominic Jones:
> > I have a list of strings and I want to determine whether or not a particular
> > string in the is in that list.
> What about using:
> size_t[sting] yourStringSet;
> Bye,
> bearophile

Would that not be constructing an associated array? Whilst an associated array
would do the job, there is no value for the "key:value" pair, just a list of 
keys.
In the C++ STL there are the "set" and "map" containers. I want something like 
"set".
Dominic


using a binary tree container

2011-02-11 Thread Dominic Jones
Hello,

I have a list of strings and I want to determine whether or not a particular
string in the is in that list. Assuming I should store the list of strings in
a binary tree to facilitate fast searching, I had a look at the std.container
documentation and found RedBlackTree, but the documentation for it has no
examples. May someone offer an example of how to use it?

Thank you,
Dominic Jones


allocating an array in an associative array

2011-02-09 Thread Dominic Jones
Hello,
I want to allocate the "int[]" array for a particular key in

  int[][string] list;

by doing

  list[key].length = list[key].length + 1;

but it does not work. I get an array bounds error. I am using gdc 4.3.5. Any
suggestions?

Thank you,
Dominic Jones