Home

bendmorris edited this page May 15, 2011 · 29 revisions
Clone this wiki locally

Scotch is a fast, developer-friendly interpreted functional programming language with increased productivity, similar to object-oriented languages Python and Ruby. Scotch has a weak dynamic typing system, and makes it easy to do things like input/output and concurrency, while also supporting first-class, anonymous, and partially applied functions and pattern matching. The Scotch interpreter is currently implemented in Haskell.

Click here to lend your support to: Support the Scotch programming language and make a donation at www.pledgie.com !

Some examples (more here):

Scotch interpreter
0.4.0
For more information, type "about", "copyright" or "license".
>> print "Hello world!"
Hello world!
>> "abc" + 1
"abc1"
>> [for a in [1,2,3], a + 1]
[2,3,4]


>> # take n values from an infinite list
>> import std.math
>> take 20 from [for i in [1..], i, prime(i)]
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71]


>> # recursive factorial function
>> fact(n) = n * fact(n - 1)
>> fact(0) = 1
>> fact(4)
24


>> # recursive list length function
>> this definition matches the first element of a list to "head" and the rest to "tail"
>> len(head : tail) = 1 + len(tail)
>> len([]) = 0
>> len("abcdefg")
7


>> # term rewriting: 
>> # instead of just "variables" and "functions" you can define a value for any arbitrary expression
>> (print apple(n)) = (print "You have " + n + " apples.")
>> print apple(5)
You have 5 apples.
>> (x + y) ^ 2 = x^2 + 2x(y) + y^2
>> (a + (b + c)) ^ 2
(((a ^ 2) + 2a((b + c))) + (((b ^ 2) + 2b(c)) + (c ^ 2)))


>> # Scotch evaluation is lazy by default
>> GPA.total = ((GPA.current * credits.current) + (GPA.future * credits.future)) / (credits.current + credits.future)
>> GPA.current = 3.5
>> credits.current = 90
>> # expressions are evaluated as far as possible; it's ok if some values are undefined
>> GPA.total
((315.0 + (GPA.future * credits.future)) / (90 + credits.future))
>> GPA.future = 4.0
>> credits.future = 30
>> GPA.total
3.625
>> GPA.future = 3.6
>> GPA.total
3.525
>> # hash objects are created automatically from namespaces
>> GPA
{"future": 3.6, "total": (((GPA.current * credits.current) + (GPA.future * credits.future)) / (credits.current + credits.future)), "current": 3.5}
>> credits
{"future": 30, "current": 90}


>> # verbose mode shows the evaluation process step by step
>> -v
>> ((4 * 2) + ((2 * 3) ^ 2)) / ((18 - 10) / 4 * 5)
((4(2) + (2(3) ^ 2)) / (((18 - 10) / 4) * 5))
((8 + (6 ^ 2)) / ((8 / 4) * 5))
((8 + 36) / 2(5))
(44 / 10)
4.4