top | item 20726617

(no title)

masak | 6 years ago

Yes. Somewhat simplified, hyphens inside of identifiers are allowed and not taken to mean infix minus.

I remember when this was switched on. Larry Wall tried it out on the entire spectest suite, and nothing broke (or at most one random thing broke), because basically people already put whitespace around their infix operators.

Incidentally, apostrophes are also allowed inside Perl 6 identifiers.

Personally, I used to conservatively use underscore (`_`) in my Perl 6 identifiers for some years. Then I got used to hyphens, and it's hard to go back.

discuss

order

zwkrt|6 years ago

Hyphens and question marks in identifiers is actually the biggest feature I wish other languages would steal from Lisp. It does help that lisp doesn’t suffer from the “is it an infix operator?” parsing problem, which exists for both programmatic and meat-based compilers.

DonHopkins|6 years ago

Then you'd love FORTH. Why limit yourself to hyphens and question marks? The only character you can't use in a FORTH identifier is space.

    FORTH ?KNOW IF HONK ELSE FORTH LEARN THEN

    : C(-; LICK SMILE NOSE WINK ;

    \ FORTH PAPER TAPE PUNCHER:

    : PT# ( L --- L/2 )
      DUP 1 AND IF 
        ASCII @ 
      ELSE BL THEN
      HOLD
      2/
    ;

    : PT. ( N --- )
      <# PT# PT# PT# 
         ASCII . HOLD
         PT# PT# PT# PT#
      #> TYPE
    ;

    : CUT
      ." -----------" CR
    ;

    : PTAPE
      CUT
      BEGIN
        KEY ?DUP WHILE
        DUP ." |" PT. ." |"  SPACE EMIT CR
      REPEAT
      CUT
    ;

faitswulff|6 years ago

> I remember when this was switched on. Larry Wall tried it out on the entire spectest suite, and nothing broke (or at most one random thing broke), because basically people already put whitespace around their infix operators.

Larry Wall seems hilariously easy-going for a language BDFL!

sp332|6 years ago

He's a linguist and a self-professed post-modernist. He's interested in how people actually use language, and has very little interest in dictating language purity.

jackewiehose|6 years ago

> I remember when this was switched on [...] and nothing broke (or at most one random thing broke), because basically people already put whitespace around their infix operators

So you are saying that code like a=b-c+d completely changed its meaning? Would this example become a = b-c + d or a = b-c+d or a=b-c + d or ...?

I just can't imagine how you would change an existing language to such an extent.

floatingatoll|6 years ago

The oddest lesson of Perl is that, even though there’s a million ways to do it, not all of them are used. It turns out that coders generally realize that the constructed examples you show above are all problematic for reasons unrelated to the change!

“What is b-c, is that a variable or a math?”

“Is it (a=b-c)+d or a=(b-c+d)”

So you simply wouldn’t encounter code written like this, because it’s just as confusing as it is problematic for the hyphen change.