The Story of Bool

Bool is an object-oriented, dynamically typed, and strongly-typed programming language influenced by the languages of Python and OCaml. Bool comes with a plethora of benefits including the ability to be compiled to Javascript, the absence of curly braces and semi-colons, intuitive and simple readability, and so much more. Bool's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance.

Often, programmers will fall in love with Bool because of its similarity to Python and the productivity it provides. The original reason we decided to create Bool was to create a language that would allow programmers to have a similar "out-of-the-box," "plug-and-play" coding experience that each of us liked about Python. To make it more user-friendly, we decided to combine the safety and power of another favorite language, OCaml. The pattern-matching aspect of OCaml is a really intuitive way of programming and with its compile-time analysis of programs, this rules out many programming errors. More precisely, this protects the integrity of the data manipulated by an OCaml program.

For Bool, security is a high concern, and so we tried to adopt many of the same things that worked for the two parent languages that ensure some degree of protection and help for the programmer.

Python
OCaml

Examples of Bool

Variable Declaration

            
let foo:int = 101
let bar:string = 101
let y = tru
            
          

Arithmetic

              
a + b
a - b
a * b
a / b
a % b
a ** b
a // b
              
            

Booleans

              
tru      # true
fal      # false
              
            

Expressions

              
!a       # not a
a > b    # a greater than b
a < b    # a less than b
a >= b   # a greater than/equal to b
a <= b   # a less than/equal to b
a == b   # a equals b
a != b   # a does not equal b
              
            

For Loops & Conditional Statements

            
fun foo (bar):
  let result:string
  for i in range(bar):
    if i < 5:
      result = "foobar"
    elif i > 7:
      result = "barfoo"
  ret result
            
          

While Loops

              
while a < 99:
a += 5
              
            

Array Comprehension

          
fun doubleEvens (array):
ret [for i in array if i % 2 === 0 i * 2]
          
        

Classes

                
class Person:
  build (_nameFirst _nameLast _age)

class Fam isa Person:
  build (_nameFirst _nameLast _age):
    _affiliation = "blood"
  cap (foo:PoliceMan):
    fun bopim (numBops):
      for bop in range(numBops):
        print(_nameFirst + (" bopped " + (foo.nameFirst
          + (" " + (foo.nameLast + (" "
          + (bop + (" times"))))))))
    ret bopim

class PoliceMan isa Person:
  build (_nameFirst _nameLast _age):
    _affiliation = "twelvy"
  woopwoop ():
    ret "Time to narc"

let five0:PoliceMan = new PoliceMan("john" "doe" 24)
let yg:Fam = new Fam("yg" "hootie" 23)
yg.cap(five0)(5)
                
            

Higher Order Functions

            
fun tricky (a b c):
ret c(a)(b)
fun add2 (a):
fun add1(b):
  ret a + b
ret add1
let sum:int = tricky(1 2 add2)
            
          

Comments

          
# This is a comment in Bool

## If you need more lines,
Bool can do that too. ##
          
        

GCD Function

          
fun gcd (a b):
  if !b:
    ret a
    ret gcd(b a % b)
          
        

Fibonacci Function

        
fun fibonacci (x):
  let a:int = 0
  let b:int = 1
  let c:int
  if (x < 3):
    ret 1
  while x > 0:
    c = a + b
    a = b
    b = c
    x -= 1
  ret c
        
      

Syntax Diagrams

Program:

Block:

FullStmt:

IndentStmt:

SimpleStmt:

ClassDecl:

ClassSuite:

ClassBody:

FieldDecl:

ConstructorDecl:

MethodDecl:

MethodParams:

FieldParams:

ObjDecl:

PropertyDecl:

FunDecl:

VarDecl:

OpAssign:

assignop:

VarAssignment:

Return:

Funcall:

FunParams:

Params:

ParamDecl:

Conditional:

Case:

Suite:

Loop:

Exp:

Exp1:

Exp2:

Exp3:

Exp4:

Exp5:

Exp6:

Exp7:

Exp8:

SimpleLit:

VarExp:

MemberExp:

addop:

mulop:

prefixop:

expop:

relop:

Explist:

ListExp:

SimpleIf:

Listlit:

intlit:

floatlit:

stringlit:

ClassInst:

Objlit:

Funlit:

Reserved:

punctuation:

Type:

char:

stringSpace:

comment:

singlecomment:

multicomment:

id:

idName:

idStart:

idChar:

newline:

space:

Semantic Errors

Binary Expression
          
+ requires compatible operands
Cannot create a float multiple of a string
** requires numerical or variable args
${this.op} requires numerical or variable args
Cannot access non-integer index of list
Operator '${this.op}' requires left operand to be object.
Operator '${this.op}' requires numerical operands.
Operator '${this.op}' requires integer operands.
Operator '${this.op}' requires compatible operands.
          
        
Bracket Access
          
Cannot access properties of non-object
Cannot access non-integer index of list
          
        
Case
          
Condition must be of type 'bool'. Found type ${this.condition.type}
          
        
Expression List
          
Lists must be composed of compatible types
          
        
Field Assignment
          
Cannot assign field outside of class context
Incompatible types: Expected ${this.target.type.name}, got ${this.source.type.name}
          
        
Field Declaration/Field Expression
          
Cannot declare field outside of class
          
        
Field Parameters
          
Cannot declare field parameters outside of class context
          
        
For Statement
          
Cannot use for-in on non list
          
        
Function Call
          
Cannot call non-function as function
Function requires ${curFun.params.length} parameters. Given ${paramGroup.params.length}
Incompatible types: Expected ${curFun.params.params[j].type}, got ${paramGroup.params[j].type}
          
        
Field Declaration
          
Incompatible return type. Expected ${this.returnType}, got ${this.body.type}.
          
        
List Expression
          
Cannot use for-in on non list
          
        
Method Declaration
          
Incompatible return type. Expected ${this.returnType}, got ${this.block.type}.
          
        
Method Parameters
          
Cannot use field parameters outside of class context
          
        
Object Access
          
Cannot access property of non-object
          
        
Op Assignment
          
Source is of wrong type. expected a number
Target of assignment operator ${this.op} must be integer.
Source of assignment operator ${this.op} must be integer.
Target of assignment ${this.op} must be number.
Source of assignment ${this.op} must be number.
          
        
Property Declaration
          
Incompatible types: Expected ${this.type}, Got ${this.val.type}
          
        
Range Expression
          
Cannot create non-integral range.
          
        
Simple If Statement/While Statement
          
Conditional expression must evaluate to boolean. Found ${this.condition.type}
          
        
Unary Expression
          
Cannot negate non-number
          
        
Variable Assignment
          
Incompatible types: Expected ${this.target.type.name}, got ${this.source.type.name}
          
        
Variable Declaration
          
Incompatible Types: Declared ${this.type.name}, Assigned ${this.value.type.name}