www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - String pasting / symbol construction?

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Just checking ... there's still no way to construct symbols (maybe 
tokens is the right word?) at compile time is there?

For instance if I want to have something like

template funcs(char[] suffix) {



}

resulting in

   funcs!("f").function1()

being equivalent to the call

   function1f()

There's still no way to do that, right?
Any good workarounds?
(In this case I'd actually like to take 3 strings and paste em together 
like that to make a function name).

--bb
Jan 26 2007
next sibling parent Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
Bill Baxter wrote:
 There's still no way to do that, right?
 Any good workarounds?
Nope. But if someone is counting votes, I'd like that functionality as well.
Jan 27 2007
prev sibling parent BCS <ao pathlink.com> writes:
Reply to Bill,

 Just checking ... there's still no way to construct symbols (maybe
 tokens is the right word?) at compile time is there?
 
 For instance if I want to have something like
 
 template funcs(char[] suffix) {



 }
 resulting in
 
 funcs!("f").function1()
 
 being equivalent to the call
 
 function1f()
 
 There's still no way to do that, right?
 Any good workarounds?
 (In this case I'd actually like to take 3 strings and paste em
 together
 like that to make a function name).
 --bb
 
not directly but checkout my dparse lib (dource -> projects -> scrapple -> dparse) it uses template specializations to generate and refer to custom symbol names. It's limited (no forward reference and everything must be declared in the same scope) but I works for the most part. Allowing template specializations to overload from different scopes and allowing lazy lookup or forward referencing of specializations* would make this vary powerful. * IIRC these aren't in the spec but DMD seems to handle them some way
Jan 27 2007