Two standard libraries?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Jul 31 21:41:14 PDT 2007
Kirk McDonald wrote:
> Chris Nicholson-Sauls wrote:
>> Here's an odd thought: "%{08x:X}"
>> Wherein the {}'s mean, "this is looking at a variable outside", and
>> the ':' means "everything after this point is the variable's name".
>>
>> -- Chris Nicholson-Sauls
>
> I always rather liked Python's syntax for this.
>
> http://docs.python.org/lib/typesseq-strings.html
>
>>>> '%(X)08x' % {'X' : 12}
> '0000000c'
>
> That is, the identifier is placed inside of parentheses between the '%'
> and the rest of the format string. The primary difference, here, is that
> Python then expects a dictionary instead of positional format arguments.
> You can get a dictionary of the current scope's variables with the
> locals() function, thus you could easily say:
>
>>>> a = 'hello'
>>>> b = 'world'
>>>> '%(a)s %(b)s' % locals()
> 'hello world'
>
> This part is not as applicable to D (since its AAs must be statically
> typed), but I do like the format string syntax.
>
It would be cool if we got a __traits(locals) function that returned a
pointer to a struct whose members were overlaid over the function's
local stack...
...yeah, seems a bit overkill :P I still think that macros wrapping
string mixins are the way to do it.
-- Daniel
More information about the Digitalmars-d
mailing list