exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
14.93k stars 510 forks source link

`_` is not always considered as punctuation #258

Open ARYASINGHBJC opened 1 year ago

ARYASINGHBJC commented 1 year ago

In string.codon you have included _ in punctuation.

Scenario when _ is not considered as punctuation :

As a separator for digits: In Python, you can use underscores to make large numbers more readable by separating the digits. For example, 1_000_000 is equivalent to 1000000.

As a throwaway variable: In Python, you can use _ as a throwaway variable when you don't care about the value of a variable. For example, you can use it as follows:

_, y = some_function_that_returns_a_tuple()

In this example, _ is used to ignore the first value returned by some_function_that_returns_a_tuple().

In internationalization and localization : In Python, _ is often used as a function or a module name in internationalization and localization. For example, the gettext module in Python uses _ as a function name to translate strings.

You can use _ as a valid variable name, and it will be treated like any other variable name.

arshajii commented 1 year ago

Hi @ARYASINGHBJC -- for this we just followed Python exactly, which includes _ in its string.punctuation:

>>> import string
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'