Skip to content

osdrv/liss

Repository files navigation

Liss Programming Language

Liss Logo

About

Liss is an educational functional programming language with a Lisp-inspired syntax. It is a compiled language that runs on its own virtual machine.

The current VM implementation is based on Thorsten Ball's book "Writing a Compiler in Go" [link].

Features

  • Lisp-inspired Syntax: Uses S-expressions for a simple and consistent syntax.
  • Functional: Emphasizes a functional programming style.
  • Compiler and VM: Compiles to bytecode that runs on a custom virtual machine.
  • Tail Call Optimization: A proper handling for deep recursive calls.
  • REPL: Includes an interactive Read-Eval-Print Loop for experimentation.
  • Regexp Support: Built-in support for regular expressions (Thompson's construction).
  • Closures: Supports first-class functions and closures.
  • Modules: Std lib and local LISS code imports.
  • Error Handling: A native epxression support for dealing with exceptional cases.

Examples

Here are some examples demonstrating key features of the Liss programming language:

Example 1: Palindrome Checker (String Manipulation)

This example showcases basic string manipulation (strings:reverse) and conditional logic to check if a word is a palindrome.

(import "strings" ["reverse"])

(fn is_palindrome? [word]
    (cond (or (is_null? word) (is_empty? word))
        false
        (= word (reverse word))
    )
)

(println "'hello' is a palindrome? " (is_palindrome? "hello"))
(println "'racecar' is a palindrome? " (is_palindrome? "racecar"))

Example 2: Data Processing Pipeline (List & String stdlib)

This example demonstrates a common data processing task: splitting a sentence, filtering words by length and rejoining. It highlights the functional style and the use of the list and strings standard library modules.

(import "list" ["filter"])
(import "strings" ["split" "join"])

(let sentence "Liss is a fun and powerful language")

(let long_words (filter (split sentence " ") (fn [word]
    (> (len word) 2)
)))

(let result (strings:join long_words ", "))

(println "Original: " sentence)
(println "Processed: " result)
; Expected Output: "Processed: Liss, fun, and, powerful, language"

Example 3: Summing a Long List (Tail Recursion)

This example demonstrates a tail-recursive function to sum a list of numbers. This implementation is optimized for memory efficiency, preventing stack overflows even with very large lists, showcasing a key feature of Liss's VM.

(import "list" ["seq"])

; A tail-recursive function to sum a list
(fn sum_list [lst]
    (fn _sum [acc l]
        (cond (is_empty? l)
            acc
            (_sum (+ acc (head l)) (tail l))
        )
    )
    (_sum 0 lst)
)

; Create a list with 10,000 numbers from 1 to 10,000
(let numbers (seq 1 10001))

(println "Summing 10,000 numbers...")
(let total (sum_list numbers))
(println "Total: " total)
; Expected Output: "Total: 50005000"

References

  • "Writing a Compiler in Go" by Thorsten Ball, 2020 (ISBN: 978-3982016108)
  • "Crafting Interpreters" by Robert Nystrom, 2021 (ISBN: 978-0990582939)
  • "Compilers: Principles, Techniques, and Tools" by Aho, Lam, Sethi and Ullman, 2013 (ISBN: 978-1292024349)
  • "Structure and Interpretation of Computer Programs" by Abelson and Sussman, 1996 (ISBN: 978-0262510875)
  • "Advanced Data Structures" by Peter Brass, 2019 (ISBN: 978-1108735513)
  • "Regular Expression Matching Can Be Simple And Fast" by Russ Cox, 2007 [link]
  • "Regular Expression Matching: the Virtual Machine Approach" by Russ Cox, 2009 [link]
  • "Regular Expression Matching in the Wild" by Russ Cox, 2010 [link]

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright

Copyright (c) 2025 Oleg Sidorov

Releases

No releases published

Packages

No packages published