dynamic classes and duck typing

BCS none at anon.com
Thu Dec 3 13:35:14 PST 2009


Hello dsimcha,

> == Quote from BCS (none at anon.com)'s article
> 
>> Show me ONE thing that can be done using run time meta programming
>> that can't
>> be done as well or better with run time, non-dynamic, non-meta and/or
>> compile
>> time meta. Unless I'm totally clueless as to what people are talking
>> about
>> when they say runtime meta, I don't think you will be able to.
>> Anything that
>> amounts to making the syntax look nicer can be done as compile time
>> meta
>> and anything else can be done with data structure walking and
>> interpretation.
>> All of that is available in non dynamic languages.
>> I guess I should concede the eval function but if you don't like
>> CTFE+mixin...
> Oh come on.  I'm as much a fan of D metaprogramming as anyone, but
> even I admit that there are certain things that static languages just
> suck at.  One day I got really addicted to std.algorithm and decided I
> wanted similar functionality for text filters from a command line, so
> I wrote map, filter and count scripts that take predicates specified
> at the command line.
> 
> filter.py:
> 
> import sys
> 
> pred = eval('lambda line: ' + sys.argv[2])
> for line in open(sys.argv[1]):
> if pred(line) :
> print line.strip()
> Usage:
> filter.py foo.txt "float( line.split()[1]) < 5.0"
> Metaprogramming isn't very rigorously defined, but this has to
> qualify.  Try writing something similar in D.
> 

Yup, eval is the one thing that dynamic *really* has over static. 





More information about the Digitalmars-d mailing list