would it be possible to use minus in identifiers ?

Discussion in 'C Programming' started by fir, Jun 9, 2013.

  1. fir

    fir Guest

    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?)
     
    fir, Jun 9, 2013
    #1
    1. Advertising

  2. fir

    Xavier Roche Guest

    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;" ?
     
    Xavier Roche, Jun 9, 2013
    #2
    1. Advertising

  3. fir

    Noob Guest

    fir wrote:

    > Would it be possible to write C like compiler that would allow [feature X] ?


    -> comp.compilers is over there.
     
    Noob, Jun 9, 2013
    #3
  4. fir

    fir Guest

    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
     
    fir, Jun 9, 2013
    #4
  5. fir

    Ivan Shmakov Guest

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

    --
    FSF associate member #7257
     
    Ivan Shmakov, Jun 9, 2013
    #5
  6. fir

    fir Guest

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


    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
     
    fir, Jun 9, 2013
    #6
  7. 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()
    > {
    >
    > }


    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
     
    glen herrmannsfeldt, Jun 9, 2013
    #7
  8. fir

    BartC Guest

    "fir" <> wrote in message
    news:...
    > 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.)

    --
    Bartc
     
    BartC, Jun 9, 2013
    #8
  9. fir

    none Guest

    In article <Kf3tt.22437$4>, BartC <> wrote:
    >"fir" <> wrote in message
    >news:...
    >>
    >> would it be possible to use minus sign in c
    >> identifiers (I mean function names and variable
    >> names
    >> int my-foo()

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

    --
    Rouben Rostamian
     
    none, Jun 9, 2013
    #9
  10. fir

    fir Guest

    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
     
    fir, Jun 9, 2013
    #10
  11. fir

    Eric Sosman Guest

    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
    d
     
    Eric Sosman, Jun 9, 2013
    #11
  12. fir

    Siri Cruise Guest

    > 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.
     
    Siri Cruise, Jun 9, 2013
    #12
  13. fir

    fir Guest

    W dniu niedziela, 9 czerwca 2013 22:46:24 UTC+2 użytkownik 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) -._ -._
     
    fir, Jun 9, 2013
    #13
  14. fir <> 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) <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"
     
    Keith Thompson, Jun 9, 2013
    #14
  15. Keith Thompson <> 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
     
    glen herrmannsfeldt, Jun 9, 2013
    #15
  16. fir

    James Kuyper Guest

    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
     
    James Kuyper, Jun 10, 2013
    #16
  17. fir

    James Kuyper Guest

    On 06/10/2013 04:43 PM, paskali wrote:
    > James Kuyper <> 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.
     
    James Kuyper, Jun 10, 2013
    #17
  18. fir

    James Kuyper Guest

    On 06/11/2013 04:35 AM, paskali wrote:
    > James Kuyper <> 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
     
    James Kuyper, Jun 11, 2013
    #18
  19. fir

    fir Guest

    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
     
    fir, Jun 11, 2013
    #19
  20. fir

    Ken Brody Guest

    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".
     
    Ken Brody, Jun 11, 2013
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mm
    Replies:
    1
    Views:
    6,145
  2. =?Utf-8?B?Q2hyaXM=?=

    getfiles, minus the path?

    =?Utf-8?B?Q2hyaXM=?=, Dec 29, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    518
    Ken Cox [Microsoft MVP]
    Dec 30, 2004
  3. =?Utf-8?B?QXNoYQ==?=

    how to minus a date?

    =?Utf-8?B?QXNoYQ==?=, Jan 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    10,050
    Juan T. Llibre
    Jan 18, 2005
  4. Matthew  Cook
    Replies:
    6
    Views:
    516
  5. Replies:
    1
    Views:
    369
    Roedy Green
    Apr 22, 2008
Loading...

Share This Page