From the repository · examples/

Example programs

Real .qc files shipped with Qingchu. Run any of them with java -cp out qingchu.Main run examples/<file>.qc.

hello.qc Beginner

Hello World

The shortest complete program: declare a binding with its type block, then reference it by name_type inside a print statement.

One statement per sentence — the lone . closes the print, exactly like a full stop.

hello.qc
let greeting = Hello
    greeting ts string

print greeting_string World .
OutputHello World
vars.qc Beginner

Variables & Types

All three built-in types in one file: string, number, and boolean. Each binding declares its type with an indented ts block, then is referenced as name_type.

The string context marker lets a bare name resolve to its _string binding automatically.

View the full file
vars.qc
let name = Alice
    name ts string

math let age = 16 .

let likes_code = true
    likes_code ts boolean

print Hello name_string .
print Age: age_number years old .
string print You said you like coding: likes_code .
OutputHello Alice Age: 16 years old You said you like coding: true
if.qc Beginner

Branching — if / else

Conditions use plain math notation (age > 18) inside the math context. Blocks open with indentation alone — no braces, no end keyword.

View the full file
if.qc
math let age = 20 .

math if age > 18
    print You are an adult .
else
    print You are a minor .
OutputYou are an adult
loop.qc Beginner

Loops — when

A loop reads like a sentence: when i is less than 3, print the count and step forward. Reassignment is always explicit with new.

View the full file
loop.qc
math let i = 0 .

math when i < 3
    print Count: i .
    math new i = i + 1 .

print Done. Loop ran 3 times .
OutputCount: 0 Count: 1 Count: 2 Done. Loop ran 3 times
grade_calculator.qc Intermediate

Grade Calculator

The full program from the repo: loop with ask + when, accumulate with new, divide for an average, then walk nested if / else branches to assign a letter grade.

Conditions read like arithmetic (average > 89) and blocks open with indentation alone.

View the full file
grade_calculator.qc
print Grade Calculator .
print Enter scores one at a time. Type 0 to finish. .

math let total = 0 .
math let count = 0 .

ask Enter a score (0 to finish): .
    response = score
        score ts number

math when score > 0
    math new total = total + score .
    math new count = count + 1 .

    ask Enter a score (0 to finish): .
        response = score
            score ts number

math let average = total / count .

math print Average: average .

math if average > 89
    print Letter grade: A .
else
    math if average > 79
        print Letter grade: B .
    else
        math if average > 69
            print Letter grade: C .
        else
            math if average > 59
                print Letter grade: D .
            else
                print Letter grade: F .
SessionEnter a score (0 to finish): 92 Enter a score (0 to finish): 85 Enter a score (0 to finish): 0 Average: 88.5 Letter grade: B
everything.qc Language tour

The Everything Test

Every feature in one file — comments, declarations, math and string contexts, constants, branching, loops, countdowns, functions, and input.

Sections below follow the file's own !! numbered comments !!. Function parsing is live; function execution is on the roadmap.

View the full file
everything.qc — 1 · comments, let + print, math
!! --- 1. Comments --- !!
!!! This is a multi-line comment
    it continues here
!!!

let greeting = Hello
    greeting ts string

print greeting_string .

math let price = 10 .
math let quantity = 5 .
math let total = price * quantity .
math print total .
OutputHello 50
everything.qc — 2 · constant, if / else, when loops
let pi = 3.14
    pi ts constant number

print pi_constant_number .

math if age > 18
    print You are an adult .
else
    print You are a minor .

!! --- 8. When loop --- !!
math when i < 3
    print Count: i .
    new i = i + 1 .

!! --- 9. Countdown --- !!
math when n > 0
    print n .
    new n = n - 1 .

print Liftoff .
Output3.14 Count: 0 Count: 1 Count: 2 5 4 3 2 1 Liftoff
everything.qc — 3 · define, ask for input
!! --- 10. Define a function --- !!
define double(x) as x * 2
    x ts number
    double ts number

!! --- 11. Define with block body --- !!
define square(x) as
    x ts number
    square ts number

    let result = x_number * x_number
        result ts number

    calculate result_number .

!! --- 12. Ask for input --- !!
ask What is your name? .
    response = name
        name ts string

string print Nice to meet you, name .

print All tests complete .
SessionWhat is your name? Ada Nice to meet you, Ada All tests complete

Try it yourself.

Clone the repo, compile once, and run any .qc file — or play in the REPL.

Back to innovationearthprojects.org