shouting versus dotting
Benji Smith
dlanguage at benjismith.net
Wed Oct 8 13:22:47 PDT 2008
Simen Kjaeraas wrote:
> On Wed, 08 Oct 2008 22:02:18 +0200, Simen Kjaeraas
> <simen.kjaras at gmail.com> wrote:
>
>> On Mon, 06 Oct 2008 12:39:29 +0200, Benji Smith
>> <dlanguage at benjismith.net> wrote:
>>
>>> Andrei Alexandrescu wrote:
>>>> One morning I woke up with the sudden realization of what the
>>>> problem was: the shouting.
>>>
>>> Here's my (nutty) opinion:
>>>
>>> Neither the "!" nor the "." really want to be there. I think the
>>> language really *wants* to be using a bare set of parens for
>>> templates. Because the language actually wants templates and
>>> functions to converge.
>>>
>>> Instead of a special-case syntax for templates, and a set of special
>>> rules for CTFE, and a whole set of parallel "static" statements (if,
>>> else, foreach) and a special compile-type-only type construct
>>> (tuples), just let D be D, either at runtime or compile type.
>>>
>>> If a function could return a Type, and if that type could be used in
>>> a Type Constructor, then you'd have all the magic template sauce
>>> you'd need, and templates could happily converge themselves with
>>> regular functions.
>>>
>>> Hey! I told you it was going to be nutty!!!
>>>
>>> <g>
>>>
>>> --benji
>>
>> That would only work for templated functions, though. What about
>> templated types?
>>
>
> Forget I ever let my ass do the thinking. I'd really like to see how
> this would look, but I feel it'd make for uglier syntax.
I don't really know how it would work, but the syntax is easy to imagine:
Type Dictionary = HashMap(char[], char[]);
Dictionary d = new Dictionary();
In this case, HashMap is just a function (executable at compile-time
through CTFE), which returns a type. Once the type has been returned,
objects of that type can be instantiated.
This idea first occurred to me when CTFE was introduced. I thought to
myself "if we can have compile-time function exectuion", why can't we
also have "runtime template instantiation"? Why is it only possible to
define a new type (or to choose which type) at compile time?
In languages like Ruby, you can attach new methods to an object at
runtime. In .NET, you can generate, compile, and load new bytecode
instructions on the fly.
It's hard to think of cases where you'd really want to construct a new
type at runtime. But maybe....automatically generating a library of
types by querying a database schema?
--benji
More information about the Digitalmars-d
mailing list