nonsensation

Slang - a simple and sane programming language

Name

The name Slang is neither final nor an actual good name.

Syntax

Comments

Code Comments

Comments start with # and go to the end of the line. There are no multiline comments (for now).

# this is a comment

Documentation Comments

Documantation is almost part of the language and start with ##.

Primitive Types

Name Equivalent in C Description
bool bool Boolean type (true or false)
void void  
i8 / u8 int8_t / uint8_t  
i16 / u16 int16_t / uint16_t  
i32 / u32 int32_t / uint32_t  
i64 / u64 int64_t / uint64_t  
f32 float  
f64 double  
isize intptr_t  
usize uintptr_t  
type  

Ranges

Python-like: start .. end, exclusive.

for( var idx in 0 .. 10 ) {}

Range-lowering transforms range-notation into this function call:
start .. endrange(start,end)

Inclusive/Exclusive ranges - possible notation

Inclusive range: start..>end Exclusive range: start..<end

Array Indexing

var lastItem = arr[-1];

Slices

Python-like: arr[start:stop:step]

arr[start:stop] # items start through stop - 1
arr[start:]     # items start through the rest of the array
arr[:stop]      # items from the beginning through stop - 1

See: Python slices on SO

Slice Example arr = 1..7 Description
arr[-1] 6 Index to the last item in the array
arr[-2:] [5, 6] Last two items in the array
arr[:-2] [0, 1, 2, 3, 4] everything except the last two items
arr[::-1] [6, 5, 4, 3, 2, 1, 0] All items in the array, reversed
arr[1::-1] [1, 0] the first two items, reversed
arr[:-3:-1] TODO the last two items, reversed
arr[-3::-1] TODO everything except the last two items, reversed

Slice-lowering transforms slice-notation into this function call:
arr[start:stop:step]arr.slice(start,stop,step)

Possible implementation: (TODO: maybe link to source)

func slice( arr   : self [] T               ,
            start : val Index   = undefined ,
            stop  : val Index   = undefined ,
            step  : val Integer = undefined ,
          ) -> [] T
{

}

ALternative syntax (via infix syntax)

Using the infix operators to and by.

for( var idx in 0 to 20 by 2 )

Keywords