Class Type Parameters

Hans-Eric Grönlund hasse42g at gmail.com
Mon Jan 21 01:34:08 PST 2008


> retryable(SomeExceptionClass)!(args...);

I of course meant 

retryable!(SomeExceptionClass)(args...);

Hans-Eric Grönlund Wrote:

> Ah, you're right. I should have been more specific. 
> 
> What I wanted to do was to imitate a ruby-method that accepts a code block, runs it and retries n times if an exception is thrown. Like the ruby-method, I wanted to let the user decide what type of exception to catch by giving it as an argument. I explain it in more detail on my weblog:
> 
> http://www.hans-eric.com/2008/01/17/loop-abstractions-in-d/
> 
> For that reason, I guess the compile time solution (templates) is to prefer in this case, although as a user of the function, I would have preferred a non-template syntax.
> 
> Like this
> 
> retryable(SomeExceptionClass, args...);
> 
> over this
> 
> retryable(SomeExceptionClass)!(args...);
> 
> 
> Cheers!
> 
> 
> Jarrett Billingsley Wrote:
> 
> > "Hans-Eric Grönlund" <hasse42g at gmail.com> wrote in message 
> > news:fmnv6b$1hi6$1 at digitalmars.com...
> > > Cool, not exactly what I was looking for, but I can use it to solve the 
> > > problem - a little differently than I'd expected.
> > >
> > > Just out of curiosity: In Delphi (Object Pascal) one can assign a class 
> > > type to a variable, like so:
> > >
> > > type
> > > TAClass = class
> > >  ...
> > > end;
> > >
> > > TAClassClass = class of TAClass;
> > >
> > > procedure do_something_with_class(AClass: TAClassClass);
> > > begin
> > >  ...
> > > end;
> > >
> > > Can something similar be done in D?
> > 
> > Depends on what you want to do.  Do you want to do compile-time stuff?  Then 
> > templates are the way to go.  Do you want to something at runtime with the 
> > class?  Then RTTI is the way to go.  typeid(AnyTypeReally) gets you an 
> > instance of the TypeInfo class which is automatically generated for every 
> > type in your program.  Runtime introspection and stuff is currently really 
> > weak in D, since the compile-time stuff is (usually) sufficient, more 
> > expressive, and faster.
> > 
> > "What do you want to _do_?" is probably the most important question here. 
> > Asking how to mechanically translate a piece of code from another language 
> > into D is not necessarily the best way to go about it, especially if the 
> > source language is one that not many people have experience with (Delphi is 
> > _reasonably_ popular but I doubt many people here have used it). 
> > 
> > 
> 



More information about the Digitalmars-d-learn mailing list