[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New operators?
- From: "Andy Stark" <AStark@...>
- Date: Wed, 11 Apr 2007 22:22:38 +0100
Lua list <lua@bazar2.conectiva.com.br> writes:
>On Wed, 2007-04-11 at 20:34 +0100, Andy Stark wrote:
>> An alternative to assignment operators (+=, etc) might be to have a
>> shorthand for referring to the variables on the left hand side of the
>> assignment.
>At least two people have suggested this (or something similar) before,
>and I've always felt that it looks and feels a little bit to
>"magical"
>in the Perl sense - certainly the use of a special character.
I know what you mean but this isn't quite the same as Perl's special
pronoun variables which really are variables in the strict sense (you can
assign to them, etc). You could use special variable names like "itself"
or something, but they would need to be short names and introducing them
to the language would break existing code that used those names.
Turning the problem around... would it be possible to modify the
expression parsing code to allow something like backreferences in regular
expressions? Bracketed sub-expressions could be referred to via a shortcut
so you could change:-
longVarName = longVarName + 1
...into
\1 = (longVarName) + 1
Or maybe an alias operator that allows you to create temporary local names
for variables:-
?x = longVarName?x + 1 -- read longVarName?a as "longVarName which we
will call x"
I suppose once you created one of these aliases, you could use it on the
right hand side of the assignment too.
Personally, I don't really have a problem with the existing method of
re-typing the variable name, but presumably there is some reason why
people keep asking for this.
&.
#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal.
The Blackpool Sixth Form College.
#####################################################################################