would it be possible to use minus in identifiers ?

F

fir

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?)
 
X

Xavier Roche

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;" ?
 
F

fir

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 :




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
 
I

Ivan Shmakov

"b-c" should be looked up in bag of defined identifiers if 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

... And a human writer.

Unless one always separates the operators and their operands
with whitespace, he or she could write a=b-c with an intended
meaning of /either/ a = (b) - (c) /or/ a = (b-c).

I know of no good reason to invent one another "C-like"
language, either. (Unless the implementors are backed by some
Really Big Enterprise, that is.)
 
F

fir

... And a human writer.



Unless one always separates the operators and their operands
with whitespace, he or she could write a=b-c with an intended
meaning of /either/ a = (b) - (c) /or/ a = (b-c).

ye, youre right it maybe may be done at the big
cost of forcing of writing (sorry for my weak
english) spaces around minus signs a=b - c
- this is a big cost, so nevermind, tnx for answers
 
G

glen herrmannsfeldt

fir said:
would it be possible to use minus sign in c
identifiers (I mean function names and variable
names for example
int my-foo()
{

}

Most high-level languages, and even most assemblers, allow for the '-'
character to be used as a unary or binary operator. There is not
a requirement that one do that, though.

The TeX language allows one to redefine that category code of
characters, such that one could change the meaning of '-' to
catcode letter. (Hopefully after macros have been processed that
use it as a negation.) (TeX is interpreted in a way that the catcode
can be changed dynamically, with predictable results.)

The BCDIC character set used by the IBM 704 and successor machines
has two '-' characters: 0x0c and 0x20. (Card punch 8-4 and 11,
repectively.) The original Fortran compiler used 0x20 for program
source files, either for program input data, and 0x0c for output
from the compiled program.

There is a complicated history of character codes on the IBM
commercial and scientific computers that had to be resolved in
the definition of EBCDIC and S/360.

-- glen
 
B

BartC

fir said:
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?)

Use "_" instead of "-".

There are too many ambiguities otherwise, unless minus is always surrounded
by white-space (or anything that is not part of an identifier).

So a-b-c-d-e I think could be interpreted 16 different ways. There are also
problems with the symbols "--", "->" and "-=".

And, with your idea of having a-b mean either a-b or a - b depending on
whether "a-b" is an identifier in scope, then you'd be able to
ite: -----------------, which could mean almost anything (it could be one
identifier, or N identifiers separated with minuses), depending on whether
identifiers could start with "-" or not.

It's not practical in an established language and syntax style anyway, and
probably wouldn't be a good idea in a new language. (Some languages do allow
"-" in identifiers; but not languages you'd want to use.)
 
N

none

...
It's not practical in an established language and syntax style anyway,
and probably wouldn't be a good idea in a new language. (Some languages
do allow "-" in identifiers; but not languages you'd want to use.)

That's a bit too harsh. In LISP an identifier may consists
of just about any sequence of characters. For instance,
a-b and *c-d!?* are perfectly normal identifiers in LISP.
 
F

fir

W dniu niedziela, 9 czerwca 2013 19:50:20 UTC+2 użytkownik Bart napisał:
Use "_" instead of "-".

There are too many ambiguities otherwise, unless minus is always surrounded
by white-space (or anything that is not part of an identifier).

So a-b-c-d-e I think could be interpreted 16 different ways. There are also
problems with the symbols "--", "->" and "-=".
And, with your idea of having a-b mean either a-b or a - b depending on
whether "a-b" is an identifier in scope, then you'd be able to
ite: -----------------, which could mean almost anything (it could be one
identifier, or N identifiers separated with minuses), depending on whether
identifiers could start with "-" or not.


It's not practical in an established language and syntax style anyway, and
probably wouldn't be a good idea in a new language. (Some languages do allow
"-" in identifiers; but not languages you'd want to use.)


ye, youre right

More signs in identifiers would be good, though
(in general)

More signs would help with much more expresivenes
of names in language (more expresivveness
is more readiblity and so on).

If i am not wrong c do not use three asci signs
~ ` @

maybe if one would use ` in the way like

int `anyt$hing!` = 10;

it would allow any signs in any identifier (by the negative cost of using``this time, advantage :
any symbols identifiers downside: it look
strange :C well, nevermind
 
E

Eric Sosman

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.
 
S

Siri Cruise

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.
 
F

fir

W dniu niedziela, 9 czerwca 2013 22:46:24 UTC+2 użytkownik (e-mail address 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) -._ -._
 
K

Keith Thompson

fir said:
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.)
 
G

glen herrmannsfeldt

(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
 
J

James Kuyper

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.
 
J

James Kuyper

James Kuyper said:
On 06/10/2013 06:04 AM, paskali wrote:
....

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.
 
J

James Kuyper

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".
 
F

fir

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
 
K

Ken Brody

W dniu niedziela, 9 czerwca 2013 16:43:43 UTC+2 użytkownik Xavier Roche napisał:


"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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top