j4 icon

Introduction

J4 does away with verbose, unreadable code and replaces it with a readable, understandable coding language that standardizes meaningful, beautiful code. This is made possible with whitespace matching and utilizing syntax that emphasize the flow of information. Along with these leaps forward in code structure, J4 simplifies coding conventions by handling the minutia of memory management and reinventing the outdated and arbitrary rules present in other languages.

J4 pulls inspiration from Swift, ELM, Python, and Lua

Features

Operators

Data Types

Example Programs

J4 on the left, Javascript on the right

Variable Declarations

String name <- "j4"                               let name = “j4”;
Number age <- 1                                   let age = 1;
Boolean hasArrows <- true                         let hasArrows = true;

Arithmetic

Number x <- ((4 + 3) * (10 - 1) ^ 2) / 4                 x = ((4 + 3) * Math.pow((10 - 1), 2)) / 4;

If Statements

if i=2                                           if (i===2){
    f(i)                                             f(i);
else if i>5                                      } else if (i>5){
    g(i)                                             g(i);
else                                             } else{
    h(i)                                             h(i);
                                                 }

For Statements

for Number i<-1, i<7, i<-i+1                      for (let i=1; i<7; i++) {
    f(i)                                              f(i);
                                                  }

While Statements

while i<7                                         while (i < 7) {
   f(i)                                               f(i);
                                                  }

Functions

Function twice(f:(Number) -> Number, x:Number) -> Number        var doTwice = (f, x) => {
    return f(f(x))                                                  return f(f(x));
                                                                }
Function addOne(x: Number) -> Number                            function addOne(x){
    return x+1                                                      return x+1;
                                                                }

Concat To increase readibility and learnability, strings do not use the “+” operator instead, the concat function is called to concatenate two or more strings

String s <- concat("Hello ", "World!")                  let s = "Hello" + "World";

Object Declarations

struct Color
  Number red, green, blue <- 0, 0, 0

  init(r: Number, g: Number, b: Number)
    self.red   <- r
    self.green <- g
    self.blue  <- b

  Function getColor(Nothing) -> Number[]
    Number[] rgb <- [self.red, self.green, self.blue]
    return rgb

Color magenta <- new Color(1.0,0.0,1.0)
Color halfGray <- new Color(0.5)

Semantic Analysis