Git Product home page Git Product logo

fsgl's Introduction

fsgl

Simple dynamically-typed functional(ish) programming language

Setup

Make sure you have Python with version at least 3.4.1.

Hello World

prints('Hello World!')

Primitive Types

a = 5  ; integer
b = true  ; boolean
c = :something  ; symbol
d = 'a string of characters'  ; string

a = 5  ; ERROR, can't mutate variables

Advanced Types

List

a = cons(1, cons(2, cons(3, cons(4, nil))))  ; "pure" way

b = (1, 2, 3, 4)  ; syntactic sugar
head(a)  ; 1
tail(b)  ; cons(2, cons(3, cons(4, nil)))

Vector

v = [1, 2, 3, 4]
v(2)  ; 3
len(v)  ; 4

Map

m = #{
  :a 4,
  'stringkey' :symbolvalue,
  true (6, 6, 6)
}

m(:a)  ; 4
m('stringkey')  ; :symbolvalue
m(true)  ; (6, 6, 6)

Basic operations

a = 5
b = +(3, 5)  ; 8
c = -(1, 4, 8)  ; -11
d = /(2, 4, 10)  ;  frac(1, 20)
e = +(*(2, 5), 7)  ; 17
f = >(4, -1)  ; true

Pattern matching

a, b = (1, 2, 3)  ; a = 1, b = (2, 3)
c, d, e = [4, 5, 6]  ; c = 4, d = 5, e = 6

Functions

f = (x, y, z) => {
  +(x, *(y, z))
}

f(1, 2, 3)  ; 7
f(4, 5)  ; (z) => { f(4, 5, z) }

g = { 4 + 5 }
g()  ; 9

(a) => { 4 + a }(10)  ; 14

Branching

a = if({ >(4, 5) }, 47, :no)  ; :no

Higher Order Functions

map((x) => {x+1}, [1, 2, 3])  ; [2, 3, 4]
foldl((a, b) => { a + b }, (1, 2, 3))  ; 6
foldr((a, b) => { a + b }, (1, 2, 3))  ; 6

Basic I/O

prints('string')  ; 'string'
prints(65)  ; '17'
prints(true)  ; '1'
prints(:thing)  ; 'thing'

a = reads()
>>something
a  ; 'something'

fsgl's People

Contributors

lvn avatar

Watchers

rosa maria palacios juncosa avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.