Where are we with thoughts on string interpolation and mixins?

Zoadian no at no.no
Tue Nov 20 10:09:40 UTC 2018


On Tuesday, 20 November 2018 at 09:19:41 UTC, aliak wrote:
> Hello,
>
> I do a lot of work with mixins. But, it's usually very hard to 
> read, and therefore reason about, and therefor review, and 
> therefor maintain. So I'm wondering what people's thoughts are 
> on how we can improve the experience of using mixins.
>
> [...]

While I do agree that string interp would be nice, I think it 
could be done in library code. Let me show you how I currently do 
something like it:

```
private enum LIQUID_ASGRAM_DEFINE_API(string PRE, T, TC, TI) = `
	struct %PRE%_s;
	alias %PRE% = %PRE%_s*;
	%PRE% %PRE%_create(uint nfft);
	void %PRE%_destroy(%PRE% q);
	void %PRE%_reset(%PRE% q);
	void %PRE%_set_scale(%PRE% q, float ref_lvl, float div);
	void %PRE%_set_display(%PRE% q, const(char)* ascii);
	void %PRE%_push(%PRE% q, %TI% x);
	void %PRE%_write(%PRE% q, %TI%* x, uint n);
	void %PRE%_execute(%PRE% q, char*  ascii, float * peakval, float 
* peakfreq);
	void %PRE%_print(%PRE% q);
`.replace("%PRE%", PRE).replace("%T%", 
T.stringof).replace("%TC%", TC.stringof).replace("%TI%", 
TI.stringof);

mixin(LIQUID_ASGRAM_DEFINE_API!("asgramcf", float, 
liquid_float_complex, liquid_float_complex));

mixin(LIQUID_ASGRAM_DEFINE_API!("asgramf", float, 
liquid_float_complex, float));
```


More information about the Digitalmars-d mailing list