Code Monkey home page Code Monkey logo

orpheus's Introduction

A tour of the Orpheus interpreter

The interpreter currently has functions, scoping, basic control flow, and a type system.

  • Scope denoted by ->.
  • Types: int, float, str, bool list, map, any, func.
    • Adding ? to variable type allows it to be assigned nil.
    • auto functions as expected.
    • Types can be compared with type() or is
  • Builtins: len, print, println, tail, append, type, has.
  • Keywords: and, or, not, true, false, if, else,var, return, pass, func.
  • All objects can be represented as strings.
  • All variables are mutable.
  • lists and maps can contain mixed types.

Examples:

func fizzbuzz(n: int)
->
    var x: auto = 1 // auto binds var to first type assigned

    while x <= n
    ->
        if x % 3 == 0 and x % 5 == 0 -> println("FizzBuzz")
        else if x % 3 == 0 -> println("Fizz")
        else if x % 5 == 0 -> println("Buzz")
        else -> println(x)
        
        x = x + 1

fizzbuzz(20)
var people: list = [
    { "name": "Bob", "age": 25 },
    { "name": "Alice", "age": 17 },
    { "name": "John", "age": 22 }
]

func greet(person: map)
->    
    print(person["name"])
    print(" is ")
    print(person["age"])
    println(" years old.")


var i: int = 0
while i < len(people)
->
    greet(people[i])
    if people[i]["age"] < 21
    ->
        println("Not eligible to drink!")
    else 
    ->
        println("Eligible to drink.")
    println()

    i = i + 1
var test: any = 3.0 // any can contain any type
println(test)
test = "hello world!"
println(test)
if "hello" is str // "is" keyword allows type checking on any
->
    println("This will execute!")
func do_thing(data: any)
->
	if has(data) -> println(data)
	else -> println("No data.")
	
var mydata: str? = nil // ? denotes "maybe" type, which can be nil
do_thing(mydata) // outputs "No data."
mydata = "wow!"
do_thing(mydata) // outputs "wow!"

orpheus's People

Contributors

ws-kj avatar

Watchers

 avatar Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.