Examples

Complete programs that show off Quill's features. Copy any of these into the Playground to try them out.

Hello World

The classic first program.

-- hello.quill
say "Hello, World!"

name is "Quill"
say "Welcome to {name}!"

Output:

Hello, World!
Welcome to Quill!

FizzBuzz

The classic interview question, solved in Quill.

-- fizzbuzz.quill
to fizzbuzz n:
  i is 1
  while i is less than n + 1:
    if i % 15 is 0:
      say "FizzBuzz"
    otherwise if i % 3 is 0:
      say "Fizz"
    otherwise if i % 5 is 0:
      say "Buzz"
    otherwise:
      say i
    i is i + 1

fizzbuzz(20)

Todo list manager

A simple todo list using lists and functions.

-- todo.quill
todos are []

to addTodo task:
  say "Added: {task}"

to showTodos list:
  if length(list) is 0:
    say "No todos yet!"
  otherwise:
    say "Your todos:"
    i is 0
    for each todo in list:
      i is i + 1
      say "  {i}. {todo}"

-- Add some tasks
tasks are ["Learn Quill", "Build a project", "Share with friends"]

say "--- Todo List ---"
showTodos(tasks)
say ""
say "Total: {length(tasks)} tasks"

Number guessing game

Demonstrates functions, loops, and conditionals working together.

-- guess.quill
-- Since we can't get user input in the playground,
-- we'll simulate a game

secret is randomInt(1, 20)
say "I'm thinking of a number between 1 and 20..."
say "(The secret number is {secret})"

-- Simulate guesses
guesses are [5, 10, 15, 3, 17, 8, 12]
found is no
attempts is 0

for each guess in guesses:
  if not found:
    attempts is attempts + 1
    if guess is secret:
      say "Guess {guess}: Correct! Found in {attempts} tries!"
      found is yes
    otherwise if guess is less than secret:
      say "Guess {guess}: Too low!"
    otherwise:
      say "Guess {guess}: Too high!"

if not found:
  say "Didn't find it! The number was {secret}."

Text analyzer

Analyze text: count words, characters, and find the longest word.

-- analyzer.quill
to analyze text:
  say "--- Text Analysis ---"
  say "Text: {text}"
  say "Characters: {length(text)}"

  words are split(text, " ")
  say "Words: {length(words)}"

  -- Find the longest word
  longest is ""
  for each word in words:
    if length(word) is greater than length(longest):
      longest is word

  say "Longest word: {longest} ({length(longest)} chars)"

  -- Check for specific content
  if text contains "Quill":
    say "This text mentions Quill!"

analyze("The quick brown fox jumps over the lazy dog")
say ""
analyze("Quill is a programming language for humans")

Simple calculator

A calculator with multiple operations and error handling.

-- calculator.quill
to add a b:
  give back a + b

to subtract a b:
  give back a - b

to multiply a b:
  give back a * b

to divide a b:
  if b is 0:
    say "Error: Cannot divide by zero!"
    give back 0
  give back a / b

to power base exp:
  result is 1
  i is 0
  while i is less than exp:
    result is result * base
    i is i + 1
  give back result

-- Run some calculations
say "--- Calculator ---"
x is 100
y is 25

say "{x} + {y} = {add(x, y)}"
say "{x} - {y} = {subtract(x, y)}"
say "{x} * {y} = {multiply(x, y)}"
say "{x} / {y} = {divide(x, y)}"
say "2^10 = {power(2, 10)}"
say ""
say "Division by zero:"
divide(5, 0)

-- Test our calculator
test "calculator operations":
  expect add(2, 3) is 5
  expect subtract(10, 4) is 6
  expect multiply(3, 7) is 21
  expect divide(15, 3) is 5
  expect power(2, 8) is 256
Try these! All of these examples can be run in the Playground. Just copy-paste the code (without the syntax highlighting spans) and hit Run.