Re: Expression transformation by symbol name

2017-09-08 Thread Dominic Jones via Digitalmars-d

On Friday, 8 September 2017 at 13:15:51 UTC, Dominic Jones wrote:

Where 'a' and 'b' are of the same type:
1. "transform(a * a)" returns an object to evaluate "2 * a"
2. "transform(a * b)" returns an object to evaluate "a * b"


1. "transform(a + a)" returns an object to evaluate "2 * a"
2. "transform(a + b)" returns an object to evaluate "a + b"



Expression transformation by symbol name

2017-09-08 Thread Dominic Jones via Digitalmars-d

Hello,

Is there a way in D of applying a transform function to the 
following expressions at compile-time such that the first is 
modified and the second left unchanged?


Where 'a' and 'b' are of the same type:
1. "transform(a * a)" returns an object to evaluate "2 * a"
2. "transform(a * b)" returns an object to evaluate "a * b"

Such transformations appear to be impossible without some kind of 
access to the symbol name in order to distinguish the two 
scenarios.


If it is possible, what are the reflection functions one would 
need to use to implement this?


If it is not possible, has there been any interest or attempts to 
add such reflection functionality to the language to make it 
possible?


Thank you,
Dominic Jones



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.


`Static If Considered' C++ article

2013-04-04 Thread dominic jones

Hello,

A response to the static if proposal for C++ was made recently 
which was a rather severe critique. Has there been a response to 
this critique or are the conclusions of the article generally 
considered to be justified? I shall be attending the ACCU meeting 
this April and would like to raise the matter, but would first 
like to know the comments of those working on and with D.


Thank you,
Dominic Jones

The article:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3613.pdf


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



MPI bindings revisited

2012-04-26 Thread dominic jones

Hello,

A while ago a thread was started on implementing MPI bindings for 
D (see 
http://forum.dlang.org/thread/dnjm6k$145u$1...@digitaldaemon.com | 
Stewart Gordon; December 12, 2005; Partial translation of MPI 
headers; digitalmars.D.announce)


I downloaded the bindings (mpi.tar.gz) and tried to compile it, 
but I had no success. I am too incompetent to get it working. May 
someone have a look into it?


I (and probably many others involved in massive numerical 
computation) would find this binding very useful, Once working, 
it seems like it would fit well in Deimos.


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


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


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


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


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


facilitating automatic differentiation

2011-10-20 Thread Dominic Jones
I have worked on differentiating algorithms written in Fortran 90/95
using Tapenade (http://www-sop.inria.fr/tropics/tapenade.html) with
moderate success.

For more expressive languages the source transformation process
rapidly tends towards the impossible. However, I speculate that in D
some of its language features (e.g. mixin, scope) may facilitate
differentiation without recourse to an external tool.

I don't know D well enough, and I am not familiar with the possible
trickery that can be done with such a language, but if there is
someone who does have some understanding of automatic
differentiation and is competent with D, I'd be very interested in
your comments as to whether or not such a pursuit is worthwhile.

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


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


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


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