open-sorcerers / madlib

Madlib: a compile-to-JS language written in Haskell, designed to make writing code a delight
https://github.com/madlib-lang/madlib
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Support Numeric Underscores #30

Open brekk opened 3 years ago

brekk commented 3 years ago

based on this haskell language extension we might want to support underscores in numeric literals:

-- decimal
million    = 1_000_000
billion    = 1_000_000_000
lightspeed = 299_792_458
version    = 8_04_1
date       = 2017_12_31

-- hexadecimal
red_mask = 0xff_00_00
size1G   = 0x3fff_ffff

-- binary
bit8th   = 0b01_0000_0000
packbits = 0b1_11_01_0000_0_111
bigbits  = 0b1100_1011__1110_1111__0101_0011

-- float
pi       = 3.141_592_653_589_793
faraday  = 96_485.332_89
avogadro = 6.022_140_857e+23

-- function
isUnderMillion = (< 1_000_000)

clip64M x
    | x > 0x3ff_ffff = 0x3ff_ffff
    | otherwise = x

test8bit x = (0b01_0000_0000 .&. x) /= 0