Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

jawher/litil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Litil

This is the first post of a series where I'll talk about the different techniques I've used to create a parser and un evaluator for the Litil™ programming language in Java. However, please keep the following in mind:

This is still work in progress, this a a bare-bones languages: no REPL, no tools, no language spec, nothing but code, and even that isn't that pretty to look at not particularly clean or organized.

Here's a quick overview of the Litil language

Now, some teaser examples to give you a feel for the language:

assignment, expressions & functions

let fact n =
  if n <= 2 then
    2
  else
    n * fact (n-1)

let f5 = fact 5

tuples & records

let x = (5, "a")
let person = {name: "lpe", age: 12}

destructuring

let (a, b) = (4, "d")

let d = ((4, true), ("test", 'c', a))

let ((_, bool), (_, _, _)) = d

algebraic data types

data Option a = Some a | None

let o = Some "thing"

data List a = Cons a (List a) | Nil

let l = Cons 5 (Cons 6 Nil)

data Tree a = Null | Leaf a | Node (Tree a) a (Tree a)

let t = Node (Leaf 5) 4 (Leaf 3)

pattern matching

let len l =
  match l
    []     => 0
    _ :: t => 1 + len t

len [1, 2, 3]

partial application

let add x y = x + y

let inc = add 1

let three = inc 2

closures & higher-order functions

let map f xs =
  match xs
    []     => Nil
    h :: t => (f h) :: (map f t)

let l = [1, 2]

let double x = 2 * x

-- pass a function by name
let l2 = map double l

-- or simply a lambda
let l2 = map (\x => 2 * x) l

let a = 4
let f = \x => a * x -- f captures the lexical value of a, i.e. 4
let a = 5
f 5

License

See LICENSE for details (hint: it's MIT).

About

The Litil programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages