Re: Are named variadic arguments possible?

2010-01-05 Thread bearophile
Alex Wrote:

 Is it possible, using templates, tuples, or some other mechanism, to 
 implement named variadic arguments in D?

Do you need high performance for this code?
If not, what about using an associative array of Variant[string] as third 
argument? It's not a nice solution.

Bye,
bearophile


Re: Are named variadic arguments possible?

2010-01-05 Thread bearophile
 Do you need high performance for this code?
 If not, what about using an associative array of Variant[string] as third 
 argument? It's not a nice solution.

It's not a nice solution, but that's essentially what Python does in such 
situation:
def foo(x, y, **kwds):
  # here kwds is a dict of str:value

In D there are Typesafe Variadic Functions, you can use:
int sum(int[] ar ...) {
To define a function that takes an arbitrary number of ints or a dynamic array 
of ints (and maybe fixed sized array of int too).
Another (weird! never used) alternative usage of the Typesafe Variadic 
Functions is to build an object on the fly.

So that syntax may be extended to support:
void foo(Variant[string] kwds ...) {
}

I may show this silly idea in the main D newsgroup later today.

Bye,
bearophile


Re: Are named variadic arguments possible?

2010-01-05 Thread downs
Alex wrote:
 Is it possible, using templates, tuples, or some other mechanism, to 
 implement named variadic arguments in D?
 
 For example, I'd like to be able to do something like...
 foo( 2, bar, age : 10, status : down);
 
 and so forth.

Yes, with a small hack.

typedef int age_type;

age_type age(int i) { return cast(age_type) i; }

void foo(T...)(int i, Bar*, T t) {
  // Test T for age_type here.
}


Are scope class useful ?

2010-01-05 Thread #ponce
When I started D, it was possible to define a scope class like this.

scope class Something
{
// blah
}

An instance declaration would then _require_ the scope storage class.


{
scope Something myVar;
   // do something with Something
}

Is there a use case for such a feature.?


Re: Are scope class useful ?

2010-01-05 Thread div0
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

#ponce wrote:
 When I started D, it was possible to define a scope class like this.
 
 scope class Something
 {
 // blah
 }
 
 An instance declaration would then _require_ the scope storage class.
 
 
 {
 scope Something myVar;
// do something with Something
 }
 
 Is there a use case for such a feature.?

Yes. One of the uses is when you are wrapping some sort of OS resource.

I've got a scope class which I use for file access;
stops you accidentally leaving the file open  locked.

I also use scope classes for storing intermediate results in complex
algorithms when I want deterministic collection. Use scope classes
and it all gets cleaned up when the algorithm finishes.

- --
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLQ4cJT9LetA9XoXwRAsv8AJ0TiP7Qy4kOKf0WmWPuyYv5qtzsNACeOoCH
sBUmQ67xWzjrSMB27o149i4=
=hGvN
-END PGP SIGNATURE-


Re: Call diagram generation

2010-01-05 Thread BCS

Hello Strt,


Lutger Wrote:


On 01/03/2010 04:31 AM, Strt wrote:


How can I generate some sort of call diagram from my D code?


you can compile with (dmd) -profile and run the executable. This
produces a file called trace.log which contains timings for each
function and a call graph. It doesn't produce a diagram and has
mangled symbols though.

You can demangle with std.demangle, read the trace.log with descent
or use this utility:
http://www.dsource.org/projects/scrapple/wiki/PtraceUtility

I haven't updated ptrace in quite a while, so I'm not sure if it
still works.


I just noticed it is called a call graph, being directed and all.

I really just needed the visual thing and seeing that I need to get
tango to work to use ptrace (and then maybe it won't work) I really
should just take pencil and paper, I think. Also, it is only a
sub-section (30 functions or so)  I'm interested in.

Thanks anyway!



With a little persitance, I'd bet that you could make a awk/grep/sed system 
that would convert that output to a graphviz file. With a little fun using 
pragma(msg,...) and .mangleof you could even get demangled symbols.