Milho (corn in portuguese) is a toy dialect of Lisp written as a way to learn more about compilers

Related tags

Miscellaneous milho
Overview

🌽

Milho (corn in portuguese) is a toy dialect of Lisp written as a way to learn more about compilers. There are implementations in rust and go

Primitives

  • Number

5 ;; Number
1/5 ;; Numbers can also be fractional
5/1 ;; 5/1 is the same as 5. Actually, 5 is implemented as 5/1 underneath 
  • Boolean
True ;; true
False ;; false
  • String
"Strings are written with double quotes."
  • Nil
Nil ;;
  • Identitifer
memes ;; Identifiers are defined like this
 ;; they can start with anything you want, except numbers
m3M3$_irados ;; after that, they can hold pretty much anything
  • Lists
'(2 3) ;; Lists are defined by putting anything between parenthesis.
(+ 2 3) => 5;; When you evaluate a list, it runs the first element as a function with the remaining elements as arguments.
(cons + '(2 3)) ;; We have all of your typical LISP list functions
() ;; Empty spaces evaluate to Nil
  • Error
(make-error 404 "Not found");; Erros cannot be created out of nowhere. You can, though, create your own errors using the make-error builtin
(make-error "oops, I broke" 20);; Notice that the first argument needs to be a number, and the second, a string. Otherwise you'll get an error, but not the one you're expecting. :p

Defining your things :P

  • Variables

(def a 5) ;; Variables are declared with the def built-in
(def things-i-like '( "memes" "basimga" "xd" )) ;; And they can hold pretty much everything ;)

(let (x 2 y 5) (sub x y)) ;; Local variables are defined like this.
=> -3 This odd positions are the identifiers, the even are the values.
  • Functions

(defn      ;; functions are declared with the defn built-in
  sum      ;; its first argument is the name of your function
  ( a b )  ;; the second one is a list with the name of your parameters  
  (+ a b)  ;; and the third is your function per se
) 

(defn sub ;; You can define multi-arity functions like this.
  (( x ) (negate x)) ;; And then your function will work according to the number of parameters
  (( x +rest ) (append-list (+ x) (map negate rest))) ;; They can even be variadics
) ;; But be careful: you can only have one body per number of params, and one variadic

(fn ( x ) (* 2 x)) ;; Anonymous functions are defined like this
  • Macros

(defmacro         ;; You can define macros with the defmacro keyword
  add             ;; Macros are just like functions, except their arguments are not evaluated
  (+rest)         ;; before the macro is expanded, and then ran
  (cons + rest)   ;; This means that this is the same as (rest1 + rest2 + rest 3 ...)
)                 ;; A function with the same body would evaluate to the list (.__add__ rest1 rest2 rest3...)

Dealing with errors

(def res (make-error 404 "Not found"))

(if (is-error res) ;; Errors can be checked with the is-error builtin
  (print "Oops, I broke")
  (print "Oh well, I'm working")
)

(get-error-message res) ;; You can access your error's message with the get-error-message bultin
(get-error-code res) ;; Or access the code with get-error-code 
You might also like...
This is a Telegram bot I'm working on in my free time to learn Rust.

Maldness Bot This is a Telegram bot I'm working on in my free time to learn Rust. Building docker build -t . should be enough.

A bunch of commented Anchor programs and JavaScript tests, to help me learn Anchor.

learning-anchor A bunch of commented Anchor programs and JavaScript tests, to help me learn Anchor.

An in-depth resource to learn Rust 🦀

Learning Rust 🦀 Hello friend! 👋 Welcome to my "Learning Rust" repo, a home for my notes as I'm learning Rust. I'm structuring everything into lesson

Examples from the talk Why you should learn Rust

Why you should learn Rust: Examples This repository contains the examples from the talk "Why you should learn Rust". All examples demonstrate that the

First Git on Rust is reimplementation with rust in order to learn about rust, c and git.

First Git on Rust First Git on Rust is reimplementation with rust in order to learn about rust, c and git. Reference project This project refer to the

Display strings in a safe platform-appropriate way

os_display Printing strings can be tricky. They may contain control codes that mess up the message or the whole terminal. On Unix even filenames can c

kindly is a simple Rust implementation of a set-user-ID-root program, similar to sudo but in a much reduced way.

kindly is a simple Rust implementation of a set-user-ID-root program, similar to sudo but in a much reduced way.

qn (quick note) is a simple, fast and user-friendly way to save notes 🦀⚙️
qn (quick note) is a simple, fast and user-friendly way to save notes 🦀⚙️

Quick Note qn Install This is currently for my personal use. I may push breaking changes at any time. If you want to use it, bring down the code and r

The easiest way to use BotiCord API in Rust
The easiest way to use BotiCord API in Rust

The easiest way to use BotiCord API in Rust · Docs Usage [dependencies]

Owner
Celso Bonutti
i like functional programming and low quality horror movies | prog rock boi | maintainer @funcional-ssa | he/his
Celso Bonutti
An upper-level course for CS majors on formal languages theory and compilers.

CS4100 Introduction to Formal Languages and Compilers Spring 2022 An upper-level course for CS majors on formal languages theory and compilers. Topics

null 2 May 28, 2022
Learn-rust - An in-depth resource to learn Rust 🦀

Learning Rust ?? Hello friend! ?? Welcome to my "Learning Rust" repo, a home for my notes as I'm learning Rust. I'm structuring everything into lesson

Lazar Nikolov 7 Jan 28, 2022
Advent of Code 2015, done entirely in Rust both for the challenge and as a way to learn

Advent of Code 2015 In preparation for Advent of Code 2021, I wanted to go back and try some of the older challenges. I figured it made the most sense

Matt 1 Dec 9, 2021
The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more

Bloom The all-in-one private workspace Try it for free! You no longer trust tech monopolies with your data? You are done with your privacy invaded by

Sylvain Kerkour 1.6k Dec 26, 2022
An abstraction build on top of discord-rich-presence that makes possible to use it in a more declarative way

Declarative Discord Rich Presence This library is an abstraction build on top of discord-rich-presence crate that allows you to use it in a more decla

null 2 Sep 7, 2022
Compiler from a lisp-like language to mlog

slimlog slimlog compiles a lisp-like language to mlog Architecture slimlog is divided into three distinct parts Parser Parses the source file Compiler

The Potato Chronicler 6 May 7, 2022
JIT compiler and runtime for a toy language, using Cranelift

Hello! This is a simple demo that JIT-compiles a toy language, using Cranelift. It uses the new JIT interface in development here. JIT takes care of m

Bytecode Alliance 468 Jan 7, 2023
Payments Engine is a simple toy payments engine

Payments Engine is a simple toy payments engine that reads a series of transactions from a CSV, updates client accounts, handles disputes and chargebacks, and then outputs the state of clients accounts as a CSV.

Bogdan Arabadzhi 0 Feb 3, 2022
Toy: Layout-Engine

Toy: Layout-Engine

Oanakiaja 5 Mar 29, 2022
A toy-level BLE peripheral stack

bleps - A toy-level BLE peripheral stack This is a BLE peripheral stack in Rust. (no-std / no-alloc) To use it you need an implementation of embedded-

Björn Quentin 4 Oct 17, 2022