Skip to content

selaere/boil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

boil

is a dynamically typed functional pure-ish language based on untyped lambda calculus etc etc. boring. it is also a minimalistic1 vector2 tacit3 programming language with postfix4, whitespace-based5 terse6 syntax

  1. there are not a lot of built-in functions (see primitives)
  2. boil values can either be scalars or vectors (which i will from here on just call "lists"). arithmetic operations like + (addition) map to every element in a list.
  3. functions can be defined using combinators like : compose, as well as currying for partial evaluation.
  4. x- means "minus x". application goes in left-to-right order
  5. spaces are used to regroup things: ABCD is ((AB)C)D, A  B CD is A(B(CD)). x yF calls F with y and x
  6. most built-in are just ascii symbols (these are called "primitives")

INTROduction (<- that blue thing is a link) (click there)

it's a sort of tutorial but not really and it's not that long look at it

more words

how to run/build

install factor (0.99 works) and then, replacing factor by whichever name you have factor installed with,

  • factor boil.factor,
  • or place boil in your work folder and "boil" deploy,
  • or if you dont know what that means,
    git clone https://github.com/selaere/boil
    factor -e='USE: namespaces "." deploy-directory set "." add-vocab-root "boil" deploy'
    # ^ run outside the cloned repo

primitives

usagenameexample
x! iota
5!          .. { 0 1 2 3 4 }
5-!         .. { -1 -2 -3 -4 -5 }
"string" 4! .. "stri"
2 3; !      .. { { 0 1 } { 2 3 } { 4 5 } }
x# length
12 34 56 , # .. 3
"string"#    .. 6
4#           .. -1
x$ wrap
3 4 5 ,$ .. { { 3 4 5 } }
x% reciprocal
3%    .. 1/3
6 3%* .. 2
x y& match
"meow" "meow"& .. 1
"woof" "meow"& .. 0
x f' each
3 1 2 ,!' .. { { 0 1 2 } { 0 } { 0 1 } }
x y* times
1 2 3 ,  4 5 6 ,* .. { 4 10 18 }
x y+ add
1 2 3 ,  4 5 6 ,+ .. { 5 7 9 }
x- negate
0 1 2 ,- .. { 0 -1 -2 }
x f/ fold
2 3 4 ,+/ .. 9
2 3 4 ,*/ .. 24
1 2 ,  3 4 ,  5 6 ,  ,  ;/  ..  { 1 2 3 4 5 6 }
x f g: compose
"cats"  # !:    .. { 0 1 2 3 }
1 2 3 ,1(- +:) .. { 0 1 2 }
x y; concat
1 2 3 ,   4 5 6 ,;    .. { 1 2 3 4 5 6 }
1 2 3 ,$  4 5 6 ,$ ;  .. { { 1 2 3 } { 4 5 6 } }
1 2;                  .. { 1 2 }
1  2 3 4 ,;           .. { 1 2 3 4 }
1 2 3 , 4;            .. { 1 2 3 4 }
x y< less
4 5 6 , 5< .. { 1 0 0 }
x y= equal
4 5 6 , 5= .. { 0 1 0 }
x y> greater
4 5 6 , 5> .. { 0 0 1 }
x? where
0 0 0 1 0 0 1 0 1 1 0 , ? .. { 3 6 8 9 }
0 1 3 0 2 0 4 , ? .. { 1 2 2 2 4 4 6 6 6 6 }
x y@ const
1 2@ .. 2
f x[ thrush
3 "hello"[ .. 'l'
+ 2[ 3[    .. 5
x f\ scan
4 2 5 3 2- 3 , +\ .. { 4 6 11 14 12 15 }
x] id
1]   .. 1
2 -] .. -2
x f^ self
4 *^ .. 16
x_ floor
4.5_ .. 4
x y f` swap
1 2 3 ,  4 ;` .. { 4 1 2 3 }
x y{ min
4 5 6 , 5{ .. { 4 5 5 }
x y f| zip
1 2 3 ,  4 5 6 , ;| .. { { 1 4 } { 2 5 } { 3 6 } } 
x y} max
4 5 6 , 5} .. { 5 5 6 }
x~ grade
3 5 1 4 3 2 3 0 ,~  .. { 7 2 5 0 4 6 3 1 }
3 5 1 4 3 2 3 0 ,~^ .. { 0 1 2 3 3 3 4 5 }

other builtins

  • xSin xCos xTan xAsin xAcos xAtan xSqrt xRound xExp xLn do exactly what you expect them to do (see arithmetic)
  • b nPow is b to the power of n
  • xDeco returns the two components of ratio x
  • pi is pi

these are the reason why i said "pure-ish" at the start:

  • input gets all the input from stdin until eof
  • sWrite writes a string to stdout
  • sPrint writes a string to stdout with a trailing newline
  • xOut prettyprints x and returns x
  • xOuts prettyprints x and returns x, where lists with only numbers will be formatted as strings
  • nRand returns a random integer in [0, n). if n = 0, return a random float in [0.0, 1.0)

repl

if you call the executable with no arguments you get sent to a repl. type in expressions, press enter, and pretty-printed results come out! if you write a line with var. at the end, the result of that expression will be saved in the repl environment with the name var. you can also access the last result with z. there are also some other commands that can be used at the beginning of a line (these will probably change):

  • )q: quit
  • )s: pretty-prints the result, where lists with only numbers will be formatted as strings
  • )v: show name of every variable set in the environment
  • )p: parse the expression and print out the AST without running it

About

lambda calculus if it was messed up

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages