Difference between revisions of "Controlling robots in remotely-operated laboratory using Objection language"
From RoboWiki
(→Very basic language examples) |
|||
Line 70: | Line 70: | ||
primes.Add(n) | primes.Add(n) | ||
print primes | print primes | ||
+ | |||
+ | # QuickSort - this code can be written way shorter, and way less readable | ||
+ | function Sort |list| | ||
+ | if list.Length() = 0 then | ||
+ | return {} | ||
+ | |||
+ | var pivot := list.Head() | ||
+ | var lesser := Sort(list.Tail() where [x|x<=pivot]) | ||
+ | var greater := Sort(list.Tail() where [x|x>pivot]) | ||
+ | |||
+ | lesser ++ {pivot} ++ greater | ||
+ | |||
+ | # Computing factorial of 6, using applicative-order version of Y combinator for "recursion" | ||
+ | var Z := [f| [x|f([y|x(x)(y))]([x|f([y|x(x)(y))]) ] | ||
+ | |||
+ | var Fact := [f| [x|if x = 0 then [1] else [x*f(x-1)]]] | ||
+ | print Z(Fact)(6) |
Revision as of 04:34, 15 April 2009
Our goal is to enable robots in virtual laboratory to be controlled using the Objection programming language.
Challenges
- The Objection language runtime is written in Delphi and has not been ported to platforms other than Win32 yet
- The codebase of Objection language needs to be reorganized in a way that will allow extending it with Robot library bindings, yet ensure that the runtime core remains independent of it.
- It should be possible to replace the runtime core with a newer Objection version with as little effort as possible
- Integration to existing virtual laboratory system
- End user interface
Language
Objection is a multiparadigm programming language, written partially in itself. Every value is a first class object, including functions. Blocks of code are anonymous functions and language constructs such as loops only manipulate with functions. All of this is hidden underneath a classical, structured syntax, but remains fully accessible for the user to explore.
Here is a short list of Objection features:
- garbage collection
- optimized tail recursion
- first class functions
- anonymous functions
- closures
- generators (via the yield keyword)
- duck typing
- all values are objects
- prototype object model (can be used indirectly using class-like syntactic sugar)
- operator overloading
- basic data structures literals
- infinite lists (via generators)
- classes and metaclasses
- objects ex nihilo
- natural language constructs
- powerfull built-in higher order operators
- eager evaluation
- support for return, break and continue commands
- compiled to bytecode interpreted by Objection Virtual Machine
- editor supporting syntax highlighting (Windows only)
Here is a short list of features that Objection currently lacks:
- short circuit evaluation of boolean operators
- call-by-reference for function arguments
- exceptions
- properties
- large numbers
- sane class library
- API for calling external libraries
- speed
Very basic language examples
# Prints some prime numbers var primes := {} for n in 2..100 do [ var isPrime := yes for p in primes do if n mod p = 0 then [ isPrime := no break ] if isPrime then primes.Add(n) ] print primes
# The same, compressed var primes := {} for n in 2..100 do if not ([p | n mod p = 0] in primes) then primes.Add(n) print primes # QuickSort - this code can be written way shorter, and way less readable function Sort |list| if list.Length() = 0 then return {} var pivot := list.Head() var lesser := Sort(list.Tail() where [x|x<=pivot]) var greater := Sort(list.Tail() where [x|x>pivot]) lesser ++ {pivot} ++ greater
# Computing factorial of 6, using applicative-order version of Y combinator for "recursion" var Z := [f| [x|f([y|x(x)(y))]([x|f([y|x(x)(y))]) ] var Fact := [f| [x|if x = 0 then [1] else [x*f(x-1)]]] print Z(Fact)(6)