Giter Site home page Giter Site logo

tranquil's Introduction

Tranquil

Tranquil is a programming language built on top of LLVM & the Objective-C Runtime.

It aims to provide a more expressive & easy to use way to write Mac and iOS Apps.

It's features include:

  • Compatibility with C/ObjC headers, meaning that there is no need to create special bindings for C APIs.
  • Automatic memory management.
  • Line by line debugging. (Using LLDB or GDB) — still under development, but breaking on, and stepping over source lines is supported
  • Dynamic Typing.
  • Language level concurrency support.
  • String interpolation.
  • Multiple assignment.
  • Message cascading.
  • Unlimited number range.
  • Unicode through&through (変数=123 works fine)
  • Good performance, even at this extremely early stage.
  • And more..

However, Tranquil is still extremely experimental and you shouldn't use it for anything other than fun for now. But to me at least, it is a lot of fun to play with.

How to build and run

The following will install Tranquil into /usr/local/tranquil (Along with a few dependencies).

> curl -fsSkL https://raw.github.com/fjolnir/Tranquil/master/Tools/install.sh | /bin/zsh
> /usr/local/tranquil/bin/tqrepl

Note: OS X ≥ 10.7 or iOS ≥ 5 is required.

Learning the language

To learn more about Tranquil you should read the specification and check out the tests.

You can also talk to me directly by visiting #tranquil on irc.freenode.net.

And here're a couple of examples:

Array iteration

alternatives = ["Objective-C", "Ruby", "Nu", "Perl", "Python"]
alternatives each: `alternative | "Tranquil is nicer than «alternative»" print`
"Or so I hope at least." print

Reduction

sum = (0 to: 1000000) reduce: `obj, accum=0 | obj+accum`

Do two things at the same time

a = async foo()
b = bar()
whenFinished {
    "a is «a» and b is: «b»" print
}

Message chaining (Without having to return self from every method you write)

var = Character new setName: "Deckard"; setOccupation: "Blade Runner"; self

Multiple assignment

a, b = b, a  \ Swap b&a

Non-local returns

a = {
    b = {
        ^^123
    }
    b()
    ^321
}
a() print \ This prints '123'

Calculate fibonacci numbers (In a not-so-performant manner)

fib = `n | n > 1 ? fib(n-1) + fib(n-2) ! n`
fib(10) print

Make a database query (Using DatabaseKit)

import "DatabaseKit"
db = DB withURL: "sqlite://data/database.sqlite"
query = db[#aTable] select: #field; where: { #anotherField => aValue }
val   = query[#field]

\ We can write that more concisely as:
val   = table[{ @anotherField => aValue }][#field]

Create a Web Server (Using HTTPKit)

import "HTTPKit"
HTTP new handleGet: "/"
              with: `connection| "Hello World!"`;
      listenOnPort: 8080
           onError: `"Unable to start server" print`

Evaluate a regular expression

"Foobar starts with foo." print if /foo[a-z]+/i matches: "Foobar"

Using the OpenGL & GLUT APIs

import "GLUT" \ This simply reads in your GLUT.h header. No bindings are required.

GlutInit(0, nil)
GlutInitDisplayMode(GLUT_DOUBLE)
GlutInitWindowSize(640, 480)
GlutInitWindowPosition(200, 200)
GlutCreateWindow("Tranquil is cool as beans!")

GlClearColor(0, 0, 0, 0)
GlScalef(0.4, 0.4, 0.4)

GlutDisplayFunc {
    GlRotatef(0.1, 0, 1, 0)
    GlClear(GL_COLOR_BUFFER_BIT)
    GlColor3f(0, 1, 0)
        GlutWireDodecahedron()
    GlColor3f(1, 1, 1)
        GlutWireTeapot(0.7)
    GlutSwapBuffers()
}

lastX, lastY = 0
GlutMotionFunc { x, y |
    dx, dy = lastX - x, lastY - y
    GlRotatef(dx, 0, 1, 0)
    GlRotatef(dy, 1, 0, 0)
    lastX, lastY = x, y
}

GlutIdleFunc(GlutPostRedisplay)
GlutMainLoop()

Talking to Cocoa

import "AppKit"

nsapp = NSApplication sharedApplication

\ Create the menubar
quitMenuItem = NSMenuItem new setTitle: "Quit «NSProcessInfo processInfo processName»";
                             setAction: #terminate:;
                      setKeyEquivalent: #q;
                                  self
appMenu     = NSMenu new addItem: quitMenuItem;   self
appMenuItem = NSMenuItem new setSubmenu: appMenu; self
menuBar     = NSMenu new addItem: appMenuItem;    self

nsapp setMainMenu: menuBar

\ Create a little view
@TestView < NSView {
    - init {
        @gradient = NSGradient alloc initWithStartingColor: NSColor redColor
                                               endingColor: NSColor yellowColor
        ^self
    }
    - drawRect: dirtyRect {
        @gradient drawInRect: dirtyRect angle: 45
    }
}
	
\ Create a window
win = (NSWindow alloc initWithContentRect: [[0, 0], [300, 200]]
                                styleMask: (NSTitledWindowMask bitOr: NSResizableWindowMask)
                                  backing: NSBackingStoreBuffered
                                    defer: no)
                                 setTitle: "Tranquil!";
                           setContentView: TestView new;
                                     self

\ Start the app
win makeKeyAndOrderFront: nil
nsapp setActivationPolicy: NSApplicationActivationPolicyRegular
nsapp activateIgnoringOtherApps: yes
nsapp run

tranquil's People

Contributors

fjolnir avatar

Watchers

James Cloos 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.