Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > would it be possible to use minus in identifiers ?

Reply
Thread Tools

would it be possible to use minus in identifiers ?

 
 
Eric Sosman
Guest
Posts: n/a
 
      06-09-2013
On 6/9/2013 10:36 AM, fir wrote:
> would it be possible to use minus sign in c
> identifiers (I mean function names and variable
> names for example
>
> int my-foo()
> {
>
> }
>
> int some-a-wariable = 10;


No. C's definition specifies a syntax for identifiers,
and that syntax does not permit minus signs.

> I mean would it be possible to write c
> like compiler that would allow that or not?


Yes. C has a formal definition but "C like" does not,
so a "C like" language could allow whatever characters you
please in identifiers: minus signs, asterisks, commas, spaces,
percent signs, anything. It could also forbid vowels, if
you think that would be fun.

> I could without knowing it, risk the theorem
> that it would be pososible but i do not know,
> maybe some unavoidable syntax conflict would
> arise (?) (or will they not?)


It all depends on how you write the rules for your "C like"
language. Your rules might or might not lead to conflicts and/or
ambiguities.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
Siri Cruise
Guest
Posts: n/a
 
      06-09-2013
> I mean would it be possible to write c
> like compiler that would allow that or not?


Yes, Cobol shows this is possible.

A simple alternative, depending on your edittor and build system, could be to
use en dashes and then use sed or similar to convert en-dashes to underscores.
--
Daddy wants to sue David Icke for plagarising El Rond Hubbard.
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
 
Reply With Quote
 
 
 
 
fir
Guest
Posts: n/a
 
      06-09-2013
W dniu niedziela, 9 czerwca 2013 22:46:24 UTC+2 użytkownik (E-Mail Removed) napisał:
>
> Do you really want to open that can of worms? And why not just use an
> underscore instead?


i do not.

I asked if this will make troubles hard
to avoid (asked for curiosity and knowledge),
and got answer, that it seems, that it
will (make some problem )

- i may repeat:

compiler would probably compile it right
but the problem is that such things as a-b-c
would not be easily (locally) readable for
humans so this would be bad IMO

i do not see way of avoiding this other
then distinguishing by spaces, it is some
option (if this spaces requirement would
apply for other symbols such as + % * / etc..
they probably could be freely used in names
but this is at cost of separating spaces around everywhere so it probably would be not worth it

(fir) -._ -._





 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-09-2013
fir <(E-Mail Removed)> writes:
> would it be possible to use minus sign in c
> identifiers (I mean function names and variable
> names for example
>
> int my-foo()
> {
>
> }
>
> int some-a-wariable = 10;
>
> I mean would it be possible to write c
> like compiler that would allow that or not?
> I could without knowing it, risk the theorem
> that it would be pososible but i do not know,
> maybe some unavoidable syntax conflict would
> arise (?) (or will they not?)


C as it's defined, of course, does not permit '-' in identifiers.

If someone wanted to invent a C-like language that does so, I'd
suggest requiring whitespace around the "-" operator (and probably,
for consistency, around all binary operators). The alternative,
of interpreting "a-b" as a single identifier if "a-b" has been
declared, or as "a - b" if it hasn't, would cause too much confusion.

(Unless, of course, this new language is intended as a successor
to Intercal; in that case, confusion is just part of the fun.)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      06-09-2013
Keith Thompson <(E-Mail Removed)> wrote:

(snip)
> C as it's defined, of course, does not permit '-' in identifiers.


> If someone wanted to invent a C-like language that does so, I'd
> suggest requiring whitespace around the "-" operator (and probably,
> for consistency, around all binary operators). The alternative,
> of interpreting "a-b" as a single identifier if "a-b" has been
> declared, or as "a - b" if it hasn't, would cause too much confusion.


Reminds me that I used to use C compilers that accepted the =-
operator, apparently left over from an early version of C.

You had to add space to assign negative values to variables:

x =- 1;
x= -1;

were different.

> (Unless, of course, this new language is intended as a successor
> to Intercal; in that case, confusion is just part of the fun.)


Verilog allows escaped identifiers. Normal identifiers follow the usual
rules of letters, digits, and underscore, not starting with a digit.

Escaped identifiers are preceded by a backslash (\) and can have any
printable ASCII character, terminated by a blank. (I suppose no
Verilog systems use EBCDIC.)

Mostly it is needed when working with GUI (schematic capture) systems
that may allow other characters. The only time I used it was for
identifiers starting with digits.

In mixed language environments, there might be a need to match
external symbols to those of other languages.

-- glen
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-10-2013
On 06/10/2013 06:04 AM, paskali wrote:
....
> I do not see the reason to make able the use of minus in identifiers.
> I think that is not possible to write a c-like compiler for that, it gives
> a lot of problems with the general sintax in the use of minus in the math
> operations.


No, it is possible - whether it's a good idea is a separate issue. While
there are problems, they're quite solvable, several ways of doing so
have already been mentioned. The best way, IMO, would be to mandate
spaces separating operators from the things they operate on.
--
James Kuyper
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-10-2013
On 06/10/2013 04:43 PM, paskali wrote:
> James Kuyper <(E-Mail Removed)> wrote:
>
>> On 06/10/2013 06:04 AM, paskali wrote:
>> ....
>>> I do not see the reason to make able the use of minus in identifiers.
>>> I think that is not possible to write a c-like compiler for that, it gives
>>> a lot of problems with the general sintax in the use of minus in the math
>>> operations.

>>
>> No, it is possible - whether it's a good idea is a separate issue. While
>> there are problems, they're quite solvable, several ways of doing so
>> have already been mentioned. The best way, IMO, would be to mandate
>> spaces separating operators from the things they operate on.

>
> You intend a thing like this should be a mistake?!
>
> #include <stdio.h>
>
> int main(int argc, char *argv[]) {
>
> int c = 100;
>
> printf("%d\n", -c);
>
> exit();
>
> }


If you're going to define a language where "-c" is a valid identifier
name, I think it's essential that "-c" not be also interpretable as a
unary minus operator acting on a variable named c. Making the way that
statement is parsed depend upon whether or not and identifier named "-c"
has been declared is too error-prone. I make enough errors while reading
and writing code as it is, I don't need any change that makes it even
easier to make such mistakes.

> All this for the possibility to use minus on identifiers?


It's not my suggestion, and I don't think it's a good idea. But if
someone insists on doing it, preventing confusion between identifiers
and more complicated expressions seems like a necessity to me.

> It obligates to use spaces also where they could not be necessary.


No, it mandates spaces where they are necessary to prevent confusion.

> I think the code lacks a bit on the readability for a choice that you, me
> and a lot out there, mostly, never will use!


I think it's more readable than "-c", when it's unclear whether it's an
identifier name or a unary minus expression.


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-11-2013
On 06/11/2013 04:35 AM, paskali wrote:
> James Kuyper <(E-Mail Removed)> wrote:
>
>>> I think the code lacks a bit on the readability for a choice that you, me
>>> and a lot out there, mostly, never will use!

>>
>> I think it's more readable than "-c", when it's unclear whether it's an
>> identifier name or a unary minus expression.
>>

>
> Eachone has his style, i do not really want to be forced to write 'c - -' or
> '- c'. For unary operator i think is better 'c--' or '-c' as well as 'c++',


Actually, I was proposing "c --", not "c - -". I agree that the forms
without spaces are better. However, if characters that look like
operators were allowed in identifier names, some such method of avoiding
confusion between identifiers and operators would be needed. That's the
main reason why I don't approve of allowing such characters in identifiers.

> etc... In the case of two (or more) operands the form 'c - x = z' is prefered.
> If it should be not possible to write 'c--' as well should be not possible to
> write 'c++' and, therefore, the + could be used on identifiers.


The point is that it WOULD be possible to write c--; but that it would
unambiguously be parsed as a single identifier, rather than ambiguously
being either a single identifier or a post-decrement expression.

Imagine the fun of allowing:
int -;

> It makes only confusion and does not give any advantage.


I agree - assuming that the "It" you're referring to is "allowing minus
in identifiers".
--
James Kuyper
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      06-11-2013
additional question:

would it be possible to allow spaces in numbers
9between decimal digits) with no downsides?
(i do not like to write int tab[100000]
and would prefer to write tab[100 000] and
so on)

seem that could be done with not affecting
anything else, but i am not sure




 
Reply With Quote
 
Ken Brody
Guest
Posts: n/a
 
      06-11-2013
On 6/9/2013 12:32 PM, fir wrote:
> W dniu niedziela, 9 czerwca 2013 16:43:43 UTC+2 użytkownik Xavier Roche napisał:
>> Le 09/06/2013 16:36, fir a écrit :
>>
>>> would it be possible to use minus sign in c
>>> identifiers (I mean function names and variable
>>> names for example

>>
>>
>>
>> No. How would you resolve "a=b-c;" ?

>
>
> "b-c" should be looked up in bag of defined
> identifiers ir found b-c would be symbol name if
> no b and c would be symbol names - This example
> compiler could process, worse that it is 'ambiguous'
> for human reader
>


"Maximal munch" doesn't care about what symbols exist or not. If "-" can be
part of an identifier name, then "b-c" must *always* represent a single
token "b-c", whether such an identifier exists or not.

Take this a bit further:

int a, b, c, a-b, b-c;
int i;

i = a-b-c;

Basically, I think this comes down to "there is no good reason to allow it,
and plenty of reasons to forbid it".

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can function definitions only use identifiers, and not attributereferences or any other primaries? Jeremy Banks Python 12 04-24-2009 08:27 AM
Binding identifiers to known or unknown identifiers latashag@live.com Java 1 04-22-2008 04:54 AM
Overloading unary minus for use in function calls Matthew Cook C++ 6 12-20-2006 10:04 PM
how to use pyparsing for identifiers that start with a constant string phil_nospam_schmidt@yahoo.com Python 3 06-15-2005 04:36 PM
Firefox plus and minus Trond Ruud Firefox 2 12-07-2004 05:31 PM



Advertisments