Skip to content

Basic Tutorial

Mohamed Rashad edited this page Jun 24, 2017 · 9 revisions

This tutorial Explains the basic functionalities of Simplex.
The language supports I/O in stdin , lists, functions, basic arithmetic,
comments, lambda expressions, if statements, case statements, select statements

Printing :

(print "Hello World")

Input :

(scan "x")

Arithmetic :

(+ 3 4 5 6 7) == 25
(- 3 2) == 1
(* 3 4) == 12
(/ 12 6) == 2

Variables :

(define [a] 100)

Lists :

(define [w] [1 2 3 4 5 6])

Functions :

(fun [add x y] [+ x y])

Comments:

# This is a comment

Conditonal Statements :

# If Statement
if (<condition>)
    [<condition true>]
    [<condition fasle>]

# Select Statement
select
    [ (<case>) <do stuff> ] 
    [ (<other case>) <do other stuff> ]
    [ otherwise (<do other other stuff>) ]

# Case Statement
case x
    [0 "stuff"]
    [1 "other stuff"]
    [2 "more stuff"]

Looping (with recursion) :

# Fibonacci
(fun [fib n] [
     select
         [ (== n 0) 0 ]
         [ (== n 1) 1 ]
         [ otherwise (+ (fib (- n 1)) (fib (- n 2))) ]
])