gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

is __ a legal identifier ? #121

Closed apblack closed 7 years ago

apblack commented 7 years ago

Michiel asked this a couple of days ago, because minigrace accepts it, but the spec says "no". I said that the spec was right, and minigrace was wrong.

Then just today, I came across a good use case for __ as an identifier. This is in Ruby:

  __ = false
  ACTION_TYPES = [
    #               :action
    #                                         :user_initiated
    #                                         |     :salesperson
    #                                         |     |     :has_receiver
    #                                         |     |     |     :clears_new_flag
    #                                         |     |     |     |
    #                                         v     v     v     v
    ActionType.new( "visited_home_page",      true, __,   __,   __,   ),
    ActionType.new( "signed_up",              true, __,   __,   __,   ),
    ActionType.new( "logged_in",              true, __,   __,   __,   ),
    ActionType.new( "searched_for_product",   true, __,   __,   __,   ),
    ActionType.new( "viewed_product",         true, __,   __,   __,   ),
    ActionType.new( "saved_search_for_later", true, __,   __,   __,   ),
    ActionType.new( "deleted_saved_search",   true, __,   __,   __,   ),
    ActionType.new( "called",                 __,   true, true, true, ),
    ActionType.new( "left_voicemail",         __,   true, true, true, ),
    ActionType.new( "emailed",                __,   true, true, true, ),
    ActionType.new( "sent_text_message",      __,   true, true, true, ),
    ActionType.new( "made_note",              __,   true, __,   __,   ),
    ActionType.new( "logged_in_as",           __,   __,   true, true, ),
    ActionType.new( "received_text_message",  __,   __,   true, true, ),
  # ActionType.new( "action",                 __,   __,   __,   __,   ),
  ]

The point here is that with true and false as the table entries, it's really hard to distinguish one from the other, and hence to notice patterns. Defining __ = false allows one to replace the falses by the visually much-less-obtrusive __. I rather like this.

Do we want to consider allowing Grace identifiers to start with a letter or an underscore?

apblack commented 7 years ago

I guess there's no support for this.

KimBruce commented 7 years ago

I think that _ by itself would cause problems as it is a wildcard. Better to keep things simple.