Skip to content
justinmann edited this page Dec 24, 2017 · 17 revisions

Welcome to SJ!

Hello World

"hello world"

This is a complete valid SJ program, no need to make it anymore complicated.

High/Low Game

console.write("Shall we play\n")

num : i32_random() % 10 + 1
isCorrect := false

while !isCorrect {
    str : console.readLine()
    guess : str.asI32()
    isCorrect = if guess < num {
                    console.write("Too Low\n")
                    false
                } else if guess > num {
                    console.write("Too high\n")
                    false
                } else {
                    true
                }
}

console.write("Correct\n")

If you come from a Java/C#/C/C++ background you will immediately recognize most of the syntax. You will notice a few interesting variations from the aforementioned languages:

  • last statement in a block is used as the return value -- this is useful with if/else blocks
  • two types of assignments:
    • ":" immutable - can only be set one-time
    • ":=" mutable - can change value

OOP/Classes

class(
  var1 := 0
  method1() { 1 }
  method2(a : 'string) { "hi " + a }
) { 
  // This is the constructor, you can initialize all of your variables here
  var1 = var1 + 1
  this 
}

a : class()
result1 : a.method1() // result1 is 1
result2 : a.method2("bob") // result2 is "hi bob"
result3 : a.var1 // result3 is 1

b : class(var1 : 12)
result4 : b.var1 // result4 is 13

Clone this wiki locally