Skip to content

guofei/Flang

Repository files navigation

Flang

A Scheme dialect written in Golang

Concept

The eval-apply cycle

Hello World

(p "hello world")
"hello world"

Basic types

Number, Symbol, String, Boolean, Lambda, List, Pair

Number

(+ 1 2)
3
(- 10 2)
8
(* 1.5 2)
3

String

Example

(string? "hello world")
#t

Boolean

Example

(eq? 1 1)
#t
(eq? 1 2)
#f

Lambda

Example

((lambda (x) (* x x)) 2)
4

List

Example

(list? (list 1 2 3))
#t

Pair

Example

(pair? (cons 1 2))
#t

Definition

Define a varable

(define <var> <value>)

Example

(define x 1)

Define a function

(define (<var> <param1> ... <paramN>) <value>)

Example

(define (factorial n)
  (if (eq? n 1)
      1
      (* (factorial (- n 1)) n)))
(factorial 5)

;; result: 120

Assignment

(set! <var> <value>)

Example

(define x 1)
(set! x 10)
(p x)

;; result: 10

Conditions

if, cond

Example

(define x 1)
(if (> x 5) 
    (p "greater than 5")
    (p "less than 5"))

Function

Lambda

((lambda (x) (* x x)) 2)
4

Standard Library

cons, car, cdr, list, pair ...

TODOS

  • REPL
  • Macro
  • Comment
  • Go Channel
  • Bootstrapping

Releases

No releases published

Packages

No packages published

Languages