Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT: Language Design

Name: Anonymous 2010-11-15 22:22

If you had the time and will to create a new Language, what would it look like?

My attempt at a functional, yet object oriented language, without the retarded syntax of haskell and without the forced intendation of python:


import IO
import OS
import Text

// braces are only required when a function
// contains more than one statement
def printFmt $format ... = do
    IO.WriteStr OS.Stdout (Text.Format $format ...)


// you can define an explicit return type by appending
// ':<TYPE>' to the end of the argument list
def fib $x :int = do
{
    if $x > 3 then
    {
        return (fib (x - 1)) + (fib ($x - 2))
    }
    return 1
}

// just like in python, all class members are public
class App {
    var $name

    def App = do
        // the 'nothing' keyword works like the 'pass' keyword -
        // it does efficiently nothing, and immediately returns
        // the default value of the specified returntype.
        // example: if the function is returned as 'def foo :int',
        // the returned value is 0.
        nothing


    def setName $n = do
        // extra dollarsign is not needed when refering to
        // class members.
        // to add explicity, members have to be called through '$this'
        $this.name = $n

    def sayName = do
        printLn "name is {0}" $this.name
}

/*
    'var $num = 15' could be also written as

        def $num = 15

    since the last argument is returned on a function without
    type specifier.
*/
var $num = 15
printLn "fib({0}) = {1}\n" $num (fib $num)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List