The Slippy Language is designed to be simple. While this might seem limiting, the lack of complexity is liberating because it allows you to focus on prototyping, rather than fighting with arcane tool-oriented problems. This isn't for writing solid, bullet-proof code. Instead, prototype an idea with Slippy, and port it to a 'real' langauge later, once you've got the idea down.
This documentation is mostly complete. It lacks coverage of some stranger things that I've not exactly nailed down, like item annotations, class (static) members, and Slippy-Java communication. Also, it is possible to run Olive in a local disk-based environment, and it is also possible to run Slippy commands from a command line, but for now those things are also undocumented.
codeset org.six11.sample
codeset org.firstbunch ; use 'import' to make the following class available import org.secondbunch.OtherThing ; now you can use it ot = new OtherThing() ; since SampleThing wasn't imported, Slippy assumes it ; can be found in this codeset (org.firstbunch). st = new SampleThing()
x = 10 y = x * x print (x, "*", x, "is", y) ; 10.0 * 10.0 is 100.0 print ("z is undefined:", z) ; z is undefined: nil x = "Now I'm a string" print (x) ; Now I'm a string x = nil print ("The value of x is now", x) ; The value of x is now nil
print("This is a string") ; This is a string print("This", "is", "easy", "to", "read") ; This is easy to read print("this" + "is" + "hard" + "to" + "read") ; thisishardtoread print("Combining strings and numbers: " + 42) ; Combining strings and numbers: 42.0
; All of the following evaluates to 10. 4 + 6 (4 + 6) 12 - 2 (15 - 1) - 4 2 * 5 (1 * 2) * 5 2 * ( 1 + 4) 20 / 2 10 / 2 + 10 / 2 60 % 50
t = true f = false if (t) print("Good.") ; this always runs done if (f) print("No...") else if (t and f) print("No...") else if (t or f) print("Yes.") ; This executes else print("Hmm.") ; This won't execute because the 'Yes' one did. done
x = 5 while (x > 0) print("x: ", x) ; counts from 5 down to 1 x = x - 1 done print("x finishes at", x) ; x finishes at 0.0
; Loop 3 times loop(3) print("It works three times!") done ; Loop while the condition is true boo = true loop(boo) print("I should 'loop' one time.") boo = false done ; Loop through a list with a new 'x' value each time myList = ["John", "Paul", "George", "Ringo"] loop(x : myList) print ("A Beatle:", x) done
define f(x) x * x ; a function's value is the last value it computes done ; This shows passing funtions and invoking them define doSomething(aFunction, aValue) aFunction(aValue) done print(f(3)) ; prints 9.0 print(doSomething(f, 5)) ; prints 25.0
x = "ecks" y = "why" define mutate(y) y = x ; read from the global x x = 3 ; don't write to the global x print(x, y) done print(x, y) ; ecks why mutate(y) ; 3.0 ecks print(x, y) ; ecks why
; Making a list stuff = ["a", "something", nil, (4*3)] print (stuff) ; [ a, something, nil, 12.0 ] ; n() print ("The list has " + stuff.n() + " items") ; The list has 4.0 items ; add(val) stuff.add(8) print (stuff) ; [ a, something, nil, 12.0, 8.0 ] ; remove(val) stuff.remove(nil) print (stuff) ; [ a, something, 12.0, 8.0 ] ; removeAtIndex(idx) stuff.removeAtIndex(0) print (stuff) ; [ something, 12.0, 8.0 ] ; indexOf(val) print("12 is at index: " + stuff.indexOf(12)) ; 12 is at index: 1.0 ; resort(sortFunction) s = lambda (a, b) ; sort functions work like in Java if (a < b) -1 ; -1 means first param is < second else if (a > b) 1 ; 1 means first param is > second else 0 ; 0 means params are equal done done jumble = [ 4, 2, 6, 3, 7, 5 ] print (jumble) ; [ 4.0, 2.0, 6.0, 3.0, 7.0, 5.0 ] ordered = jumble.resort(s) print (ordered) ; [ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] ; each squared = [] go = lambda (v) squared.add(v* v) done jumble.each(go) print(squared) ; [ 16.0, 4.0, 36.0, 9.0, 49.0, 25.0 ] ; filter is_odd = { (v) if (v % 2) v else nil done } odds = jumble.filter(is_odd) print(odds) ; [ 3.0, 7.0, 5.0 ] ; sum, min, and max sumVal = jumble.sum() minVal = jumble.min() maxVal = jumble.max() print("sum is " + sumVal) ; sum is 27.0 print("min is: " + minVal) ; min is: 2.0 print("max is: " + maxVal) ; max is: 7.0 ; sort orderedSquares = [] orderedSquares.sort = s squared.each( { (v) orderedSquares.add(v) } ) print(orderedSquares) ; [ 4.0, 9.0, 16.0, 25.0, 36.0, 49.0 ] ; copy osCopy = orderedSquares.copy() osCopy.removeAtIndex(osCopy.n() - 1) osCopy.removeAtIndex(0) print(osCopy) ; [ 9.0, 16.0, 25.0, 36.0 ] print(orderedSquares) ; [ 4.0, 9.0, 16.0, 25.0, 36.0, 49.0 ]
empty = {} print("Empty map: " + empty) ; Empty map: { } beatles = { "Lead guitar" : "George", "Rythym guitar" : "John", "Bass" : "Paul", "Drums" : "Ringo" } print("The Beatles are: " + beatles) ; The Beatles are: { Lead guitar : George, ; Rythym guitar : John, Drums : Ringo, ; Bass : Paul } print("The bass player was " + beatles["Bass"]) ; The bass player was Paul print("The cowbell player was " + beatles["Cowbell"]) ; The cowbell player was nil
; the 'long' way to make a lambda square = lambda(x) x * x done ; the 'short' way cube = { (x) x * x * x } ; lambda params can be functions runNtimes = lambda(f, p, n) loop (n) print(f(p)) done done print(square(3)) ; 9.0 runNtimes(cube, 4, 2) ; 64.0 two times
; A sample class definition including a constructor. class SampleThingy name ; Thingy's name. Members are declared like this. num ; A number define init() name = "Default Name" num = 42 done done
class Named name define mix() print("Mixing a named thing.") done define printName() print("Hello my name is", name) done done class CanFly speed = 10 define mix() print("Mixing a thing that can fly.") done define fly() print("I am flying!") done done class Bird mixes Named, CanFly define init() print("In Bird's constructor") done done ; The following will print: ; In Bird's constructor ; Mixing a named thing. ; Mixing a thing that can fly. b = new Bird() ; Now test out the mixed in capabilities. b.name = "Mrs. Tweetypants" b.printName() ; Hello my name is Mrs. Tweetypants b.fly() ; I am flying!
class Point x ; horizontal dimension, larger is to the right y ; vertical dimension, larger is down define init(x_, y_) ; constructor is always called init x = x_ y = y_ done define translate(dx, dy) x = x + dx y = y + dy done define report() print("Location: " + x + ", " + y) done done p1 = new Point(0, 0) p2 = new Point(5, 5) p1.report() ; Location: 0.0, 0.0 p2.report() ; Location: 5.0, 5.0 p2.translate(10, -3) p2.report() ; Location: 15.0, 2.0
; Make a plain 'untyped' object, a global function, and a global variable obj = new Object() define f() 3 done six = 6 ; Assign 'mystery members' to this object obj.three = f ; assign a function---note there are no parens! obj.four = "four" ; assign a string obj.five = (2 + 3) ; assign the result of evaluating an expression obj.six = six ; assign a copy of whatever is in variable 'six' print(obj.three(), obj.four, obj.five, obj.six) ; 3.0 four 5.0 6.0 six = "error" ; changing original variable has no effect on obj.six print(obj.three(), obj.four, obj.five, obj.six) ; 3.0 four 5.0 6.0
; abs(v) - get absolute value of a number print(abs(-3)) ; 3.0 ; min(a,b) - return the minimum of two numbers print(min(-1, 2)) ; -1.0 ; max(a,b) - return the maximum of two numbers print(max(-1, 2)) ; 2.0 ; sqrt(v) - return the square root of a number print(sqrt(4.0)) ; 2.0 ; pow(a, b) - return a raised to the power of b print(pow(2,4)) ; 16.0 ; sin(x) - sine trig function print(sin(1)) ; 0.8414709848078965 ; cos(x) - cosine trig function print(cos(1)) ; 0.5403023058681398 ; tan(x) - tangent trig function print(tan(1)) ; 1.5574077246549023 ; arcsin(x) - inverse sine (arc sine) trig function print(arcsin(1)) ; 1.5707963267948966 ; arccos(x) - inverse cosine (arc cosine) trig function print(arccos(1)) ; 0.0 ; arctan(x) - inverse tangent (arc tangent) trig function print(arctan(1)) ; 0.7853981633974483 ; constant represeting PI print(PI) ; 3.141592653589793 ; constant representing E print(E) ; 2.718281828459045
; now() - returns the current time in milliseconds start = now() doSomething() end = now() print( (end - start) + " ms elapsed") ; 56.0 ms elapsed ; getType(t) - gives the type of any expression t = new SampleThingy() print(getType(t)) ; Instance print(getType(3)) ; Number print(getType("foo")) ; String print(getType(print)) ; Function print(getType( [1, 2, 3] )) ; Array print(getType( { "key" : "val" } )) ; Map ; showStacktrace() - shows the line/column where execution is showStacktrace() ; Prints a stacktrace such as the following: ; /org/sample/SampleThingy.slippy:saySomething:13:4 ; /org/sample/SampleThingy.slippy:18:15 ; printMembers(obj) printMembers(mySampleThingy) ; Prints symbol tables such as the following: ; (Table for SampleThingy instance) (hash: 796215886) (parent: -2001183084) ; +-------------------------------------------+ ; | getClass | getClass () | | ; | printSymbolTable | printSymbolTable () | | ; +-------------------------------------------+ ; (Symbol table for class SampleThingy) (hash: -2001183084) ; +------------------------------------------+ ; | saySomething | saySomething (sumthin) | | ; | init | init () | | ; +------------------------------------------+
class ThingWithoutToString ; nothing here :( done class ThingWithToString define to_s() "I am fancy" done done t1 = new ThingWithoutToString() t2 = new ThingWithToString() print(t1) ;print(t2) ; I am fancy