Six Myths about Ontologies: The Basics of Formal Ontology
Crystal presentation in NY
1.
2. ➔ Ruby is practical to write code
➔ Compiled languages are more efficient
➔ Type checking reduces errors
➔ We want the best of each world
Motivation
3. Ruby inspired syntax
# The Greeter class
class Greeter
def initialize(name : String)
@name = name
end
def salute
puts "Hello #{@name}!"
end
end
# Create a new object
g = Greeter.new("world")
# Output "Hello World!"
g.salute
4. Static type checking
# sample.cr
"Hello" + 1
$ crystal build sample.cr
Error in line 1: no overload matches 'String#+' with types Int32
Overloads are:
- String#+(other : self)
- String#+(char : Char)
16. Procs
f = ->(x : Int32) { x + 1 } # Int32 -> Int32
f.call(5) # => 6
17. Closures
y = 42
f = ->(x : Int32) { x + y }
f.call(5) #=> 47
y = 20
f.call(5) #=> 25
18. Method overloading
def sum(x : String, y : String)
sum x.to_i, y.to_i
end
def sum(x : Int32)
x
end
def sum(x, y)
x + y
end
sum "12", "13" #=> 25
sum 10 #=> 10
sum 20, 30 #=> 50
def sum(*args) # Ruby
case args.length
when 2
if args[0].is_a?(String) &&
args[1].is_a?(String)
sum(x.to_i, y.to_i)
else
args[0] + args[1]
end
when 1
args[0]
else
raise "Error"
end
end
23. Type inference
def add(a, b)
a + b
end
x = add(4, 5)
def add(a : Int32, b : Int32)
a + b
end
# x : Int32
x = add("foo", "bar")
def add(a : String, b : String)
a + b
end# x : String
24. Type inference
def fact(n)
if n > 0
fact(n - 1) * n
else
1
end
end
fact(5)
def fact(n : Int32)
…
end
fact(Int32)
Union
* 1
fact(Int32) n
# Int32
37. struct Struct
def ==(other : self) : Bool
{% for ivar in @type.instance_vars %}
return false unless @{{ivar.id}} == other.@{{ivar.id}}
{% end %}
true
end
end
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
Metaprogramming
41. Functions
// C
double cos(double x);
double y = cos(1.5);
# Crystal
lib LibC
fun cos(x : Float64) : Float64
end
y = LibC.cos(1.5)
42. Structs
// C
struct Point {
int x, y;
};
struct Point point;
point.x = 1;
point.y = 2;
# Crystal
lib LibC
struct Point
x, y : Int32
end
end
point = LibC::Point.new
point.x = 1
point.y = 2
43. // C
typedef void (*sig_t) (int);
sig_t signal(int sig, sig_t func);
# Crystal
lib LibC
alias SigT = Int32 ->
fun signal(sig : Int32, func : SigT) : SigT
end
LibC.signal 2, ->(value) { puts "Interrupted" }
Callbacks
44. Wrapping up
● Ruby inspired syntax.
● LLVM under the hood.
● Learn from Go, Erlang, Rust, Swift.
● Let the compiler do as much work as
possible.
45. The present
➔ Charming community, Meetups.
➔ +100 contributors compiler, docs.
➔ 1500 shards.
➔ +80 sponsors, from 1usd/mo.
46. The future ‘17
➔ Multithreaded Concurrency
➔ Windows
➔ Polish language features to reach 1.0