Skip to content

AyushmanTripathy/pips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PIPESCRIPT

A programming language revolving around piping.
Pipescript is a functional, dynamically weakly typed, interpreted, indented programming language.
This is still a work in progress

Believes

  1. useless complexity is waste of time.
  2. using functions for everything.
  3. human readable code.
  4. piping is a great idea.

plz report any bugs by creating an issue.
for getting an idea about performance of pipescript check out.

Features

  1. piping
  2. pattern matching functions
  3. pure functions
  4. immutabillity by default
  5. higher order functions (coming soon)

by pure functions i mean functions are idempotent and have no side effects. note, printing to stdout is not considered a side effect for simplicity reasons.

Installation

git clone https://github.com/AyushmanTripathy/pips
cd pips
make clean install //with privilege
pips <input file>

to change the installation location, change the $INSTALLDIR in Makefile.
intrested in syntax highlighting check out.

Documentation

Pipescript is a very simple language. pipescript supports # and // comments

Piping

piping is used to channel output of one function into another.

print | add 1 2

following gives the same output, but instead of | we are using code blocks [].

print [add 1 2]

Variables

variables in pipescript are immutable.

set "x" 10
print "factorial of" x "is" | factorial x

Data types

there are 4 data types in pipescript.

  1. numbers
set "x" 101
add .1 .2 //gives 0.3
  1. strings
set "x" "this is a example string"
  1. boolean
set "x" True
set "y" False
  1. null
set "x" Null

null value is returned by void functions.

Conditional flow

pipescript has your well know if, else statments

if [eq number 1]:
    print "number is one"
elif [eq number 2]:
    print "number is two"
else:
    print "number is not one or two"

note the use of code blocks, pipes can also be used.

if | eq number 1: print "number is still one"

Functions

function are king in pipescript.
there are two types of functions

  • fn functions

these are good old functions

fn factorial x:
    if [eq x 1]: return 1
    return | multiply x | factorial [add x -1]

note return is also a function, so you have to pipe your output into return.
functions can also be one liners

fn square x: pow x 2
  • self (tail recursions)

self keyword is used to call the parent function. this is used to mark a tail recurison which is more efficient and faster than normal recursion.

fn factorial x y:
    if [eq x 1]: return y
    return | self [add x -1] [multiply x y]

note: a return should always follow self calls (tail recursion fashion).

fn factorial x:
    if [eq x 1]: return 1
    return | multiply | self [add x -1]

doing something like this will result in a type error or a function collapse error (error raised when function cannot give an output).

  • def functions

these are pattern matching functions.

def foo
    0: pass "Even"
    1: pass "Odd"
    x: foo | reminder x 2

print 10 "is" | foo 10

return function can be used instead of pass if you like.
for example a factorial be implemented as such

def factorial
    x: factorial x 1
    1 y: pass y
    x y: self [add x -1] [multiply x y]

note pattern matching happens from top to bottom hence the 1 y case must be before x y case to work.

for more advanded pattern we use guards, for example fibbonacci can be implemented as such.

def patternFibb
  x: patternFibb x 1 1 0
  target x a b: self target [add x 1] [add a b] a
    eq target x: pass a

if no guards match then default statment is executed.

def trickFibb
  target: self 1 1 0
  x a b: self [add x 1] [add a b] a
    eq target x: pass a

this is a handy little trick, note the use of self in first pattern case. when function is called with self, variables from earlier instances are saved unless overwritten.

execution starts with global function (global scope), hence it is possible to return out of global scope.
if a number value is returned, it is used as exit code.

Buildin Functions

  1. Boolean functions
funtion name argument description
bool 1 any type converts to boolean
not 1 boolean type equivalent of !
eq 2 same types equivalent of ==
lt 2 same types equivalent of <
gt 2 same types equivalent of >
and 2 booleans equivalent of &&
or 2 booleans equivalent of ||
  1. Number functions
funtion name argument description
neg 1 number gives negative of a number
abs 1 number gives the absolute value
sum numbers add all up numbers
add 2 numbers add the 2 number
subtract 2 number first subtracted by secound
pow 2 numbers first raised to secound
root 1 number root of number
sq 1 number square of number
multiply numbers multiplies all numbers
divide 2 numbers divides first by secound
reminder 2 numbers reminder of first divied by secound
max number gives max of the numbers
min number gives min of the numbers
  1. Miscellaneous functions
funtion name argument description
print any type print to stdout space separated
pass any type gives the first input
return any type returns the first input from the function
error 1 string raises a raised error

thank you for trying out pipescript! 👍

About

a functional, dynamically weakly typed, interpreted, indented programming language.

Topics

Resources

Stars

Watchers

Forks