0.0.2 • Published 8 years ago

Bynd v0.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

Bynd Programming Language

Bynd is a functional Programming Language.

Concepts

Major concepts that Bynd supports.

* Map
* Reduce
* Composite
* Partial

Data types

Data types that are supported Bynd eldest version.

* Number
* String
* Boolean
* List
* Function

How to Use

Installation

  • git clone git@github.com/BugDiver/Bynd.git
  • npm install
  • npm install -g gupl
  • gulp install

run bynd -v` to see the version.

Hello World

(print "Hello World") ;;prints 'Hello World' 

Comments

;;Everything followed a pair of two semicolons is a comment.
;;These are single line comments.
//Everything inside a pair of two slashes is 
a multi line comment.
//

Arithmetic operation

(print (add 20 10)) ;;prints 30
(print (sub 20 10)) ;;prints 10

Comparison operation

(print (eq 20 20)) ;;prints true
(print (gt 40 50)) ;;prints false

Conditional operation

(print (if (eq 20 20) "yes" "no")) ;;prints 'yes'
(print (if (false) "yes" "no")) ;;prints 'no'

Variable Binding

(. x 20)
(print x) ;;prints 20

Function Creation

Regular Map Declaration

Regular map takes exactly one parameter.

(. inc => n (add n 1)) ;;function to increment by 1
(. isEven => n
    (eq (mod n 2) 0)
)
(. cube => n    ;;function to find cube
    (multi n n n)   
)

Irregular Map Declaration

Irregular map takes no parameter. Hence NULL has to be given as argument.

(. one => NULL 1) ;;function returning one always
(. random => NULL (random)) ;;function returning random number b/w 0-1

Reduce Declaration

Reduce takes exactly two parameters.

(. sum => previous current
    (add previous current)
)
(sum 10 20 30 40) ;; evaluates to 100

In first iteration the first two numbers are previous and current values. In the second iteration onwards the current will be the next number in the queue, and the previous will be the previous iteration return value.

Composite

Calling a Map passing a Map will return a Composite. For example, square and cube are two Map functions.

(. cube => n
    (multi n n n)
)
(. square => n
    (multi n n n)
)

To find n to the power 6, one has to simply call square of cube of n.

(. sixtyFour square cube 2)     ;; all these are equivalent
(. sixtyFour square 8)          ;; all these are equivalent
(. sixtyFour square (cube 2))   ;; all these are equivalent
(. sixtyFour (square cube) 2)   ;; all these are equivalent

(. toThePower6 square cube)     ;; a composite can be passed around like this
(. sixtyFour toThePower6 2)     ;; gives sixty four

Note that Composite is also a Map. A Composite cannot be created by calling a Map passing a Reduce. But can be created by calling a Reduce passing a Map. The Associative property of the operations has to be taken care.

Partial

Any Function call returns a PUT object which can be treated as a function or a value. How it is treated is upto the consumer.

So, a Reduce call returns a PUT.This PUT has a partial function and the accumulated value as a result of the Reduce call. For example, add is a Reduce function. (add is a in built function)

(. incByTwo (add 2))
(print incByTwo)