Skip to content
/ lamber Public

A functional scripting language compiling to pure Lambda Calculus

License

Notifications You must be signed in to change notification settings

aartaka/lamber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lamber, a Simple Language

Lamber is a minimalist functional programming language with a focus on graspability, readability… and compilation to pure untyped Lambda Calculus, of course! It’s inspired by Lua, Haskell, and Wisp. And it smells of creamy cheese!

Lamber in a Postcard

def factorial function (n)
  if (= n 0)
   then 1
  else
   * n : factorial : dec n .

Step by step:

  • You can bind things to names/variables (like factorial) with let, def, local, and var. All of these do the same thing, so pick the one you like the most.
  • Functions are all there is to Lamber. It compiles to raw lambdas, after all. It’s only consequential that things you bind to vars are fn-s, lambda-s,a nd function-s.
  • There’s if~/~when to do conditional checks. With else branches and else if chaining. Boring stuff, right?
  • There’s no need for explicit return statement, because the last form in the function/branch is the return value.
    • So factorial returns either 1 or… wait, I need to explain some more.
  • Functions are prefix in Lamber, so = n 0 means “n is equal to zero” and dec n means decreasing n.
  • There’s no looping in Lamber, only recursion.
    • Luckily, first-class functions and abundance of list processing utilities in the standard library make explicit looping unnecessary in most cases.
  • There are several special syntax pieces, mostly stolen from Wisp:
    • : colon to chain function calls. Lamber emphasizes composable functions that are easy to chain, as in * n : factorial : dec n:
      • Decrease n.
      • Call factorial on it.
      • And multiply the result by n.
    • . period is a shortcut for end (like in Lua and the kind.) You can do explicit end too, but it’s not as pretty:
 else
  * n : factorial : dec n
end

Values

There’s a number of guiding principles Lamber is built around:

Minimalism
If something is not absolutely necessary, it’s not going to be there.
Cognitive
All there is in the language should fit into one moderately overwhelmed programmer’s head.
Footprint
Implementation should be small enough.
Build
All the libraries and apps are provided as files on CLI or in LAMBER_PATH and sorted lexicographically. Want to load your lib earlier? Just rename the file!
Syntactical
There shouldn’t be more than ten pieces of syntax in the language.
  • As of the moment of writing, there are eight:
    • let / def etc. variable definition.
    • if branching.
    • function-s.
    • type-s.
    • Literal values, like booleans, numbers, and strings.
    • Function calls.
    • Colons.
    • Periods.
Readability
Lambda Calculus is scary. Lua is not. Lamber tries to be somewhere in between the two, with the bias towards Lua.
Functional design
Functional programming won, and you have to live with it. Make your functions composable and higher-order. And no side-effects (well, there’s ./lib/8000-io.lmb, but hush!)

Installation & Getting Started

  • Clone the repo:
git clone --recursive https://github.com/aartaka/lamber  
  • Install a Lisp implementation like SBCL.
  • Compile the lamber executable with make all
  • Use the generated lamber as in
./lamber example/hello.lmb
# Hello, world!
./lamber example/factorial.lmb int
# 120