[nem-en] Syntax change - your thoughts?
Alejandro Serrano
trupill at yahoo.es
Fri Feb 3 20:38:04 CET 2006
I think using .[] instead of plain [] is a good idea. In my opinion,
both have different ideas:
def a : List[int] => List[int] is the type
def a = List.[int]() => Here you are using the type as another
parameters (which indeed it is), not to specify the type, so you use the
dot.
This is consistent all through Nemerle, so I find it a good idea. Also,
mostly you will write just List() instead of List.[int]() because of
type inference. Using [] would introduce a new difficulty to the parser
/ compiler, which is not really needed, and which is used for other
things: indexers, list comprehensions.
Of course, that's just my idea
trupill
Gerard Murphy escribió:
>
> Dear all,
>
> One thing I notice from time to time is the inconsistency in the
> syntax for generic types in Nemerle.
>
> Let’s say I have a class:-
>
> public
>
> class AGenericClass[TypeParameter]
>
> {
>
> public
>
> this()
>
> {
>
> }
>
> public static
>
> ackleWithIt[AnotherTypeParameter](it: AnotherTypeParameter): void
>
> {
>
> }
>
> public static
>
> disappearUpOnesOwn(): void
>
> {
>
> disappearUpOnesOwn()
>
> }
>
> }
>
> Not the most sensible class, I agree!
>
> Now, if I want to declare a variable of this class type, then I can
> write:-
>
> public
>
> class Client
>
> {
>
> public
>
> Foo(): void
>
> {
>
> def x = AGenericClass.[int]();
>
> mutable y: AGenericClass[int] = null;
>
> // etc…
>
> }
>
> }
>
> Note the use of the dot before the type parameters when the generic
> class type is used as a constructor invocation.
>
> The same thing happens if I want to refer to a method in the generic
> class:-
>
> public
>
> class Client
>
> {
>
> public
>
> Foo(): void
>
> {
>
> AGenericClass[string].disappearUpOnesOwn();
>
> AGenericClass[string].ackleWithIt.[int](2);
>
> // etc…
>
> }
>
> }
>
> Again, a dot has mysteriously appeared before the type parameters,
> even though the non-generic method doesn’t require a dot to be called,
> nor do the type parameters in the generic method’s definition require
> separation from the method name with a dot.
>
> I get the impression that the decision to use a dot before the type
> parameters in an expression context was driven by an implementation
> decision – without the dot, the expression would look like an indexer
> call (and indeed, neglecting the dot results in such an error message).
>
> My point is that the syntax should be consistent and the compiler
> should have to work a little harder – I should be able to write:-
>
> def x = AGenericClass[int]();
>
> as well as
>
> AGenericClass[string].ackleWithIt[int](2);
>
> and the compiler should know that ‘AGenericClass’ is the leading part
> of a generic type, not the name of a variable that is about to be
> subject to an indexing operator call!
>
> Well, you might say I’m dwelling on trivial details here – but I keep
> tripping up over this syntax inconsistency and find myself either
> trying alternatives to get the compiler to vet my syntax, or going to
> the Nemerle homepage to check the language grammar.
>
> This isn’t right – a good programming language is something that
> working programmers should be able to internalise – the syntax should
> be intuitive.
>
> Consider that C++, Java and C# all have the consistent syntax approach
> in their use of generics / templates: the expression usages mirror the
> definition syntax. I would argue that if the goal is to attract a base
> of software engineers to rally in support of the language (and I would
> certainly like to see this happen, as I know others on this mailing
> list would), then perhaps this change of the language syntax should be
> included in order not to put off folk who are used to the consistent
> syntax in their ‘home’ languages.
>
> It’s all very well to have good features in a language – and I think
> Nemerle is packed full of them, put together in an elegant way – but
> don’t forget the mundane ergonomics factors. People have to sit down
> in front of a computer and type this stuff in, day after day after day!
>
> In case you aren’t convinced, ask yourselves how many Lisp, Algol 68
> and APL programmers you’ve met in your careers. Why is Java becoming
> increasingly popular in comparison with C++? It isn’t increased
> expressive power; it’s convenience of everyday use that swings these
> matters.
>
> OK, that’s the polemic over with – meanwhile there are the language
> developers and the existing user community to consider. So what are
> your thoughts on this?
>
> Is my difficulty with the syntax just a case of my brain being addled
> with age? ;-)
>
> Perhaps there is a more fundamental reason that I’m not aware of that
> prohibits using semantic context to disambiguate the parsing?
>
> In closing – I’d be delighted to investigate making the changes myself
> to the compiler to support a consistent generics syntax, if others
> become convinced that it should change. I suspect that the Wroclaw
> team might be able to carry these out a bit faster then me, though. J
>
> One last thing – I’m on holiday for the next four days, so if anyone
> directs a question at me, please don’t be offended if I don’t reply
> immediately – I’ll try to peek at the mailing list if I can, though.
>
> Kind Regards,
>
> Gerard Murphy www.sageserpent.com <http://www.sageserpent.com/>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
More information about the devel-en
mailing list