Weitere ähnliche Inhalte
Ähnlich wie Introduction to Nim (20)
Kürzlich hochgeladen (20)
Introduction to Nim
- 4. The Joy of Ruby
5.times { print "Odelay!" }
exit unless restaurant.menu.include? "kebab"
meringue = ['egg', 'sugar', 'milk'].reduce &:+
- 7. The trouble with C(++)
❏ int (*(*func())[10])()
❏ 1 / 0;
❏ char s[ ] == char *s == std::string == LPSTR
== wchar
❏ int myInt = 0; fileStream.read
(reinterpret_cast<char*>(&myInt), sizeof(int));
❏ void myfunc() { char *c = malloc(16); }
- 9. Hello world!
puts "hello world!" Ruby
print "hello world!" Python
#include <iostream> C++
int main()
{
std::cout << "hello world!n";
return 0;
}
fn main() { Rust
println!("Hello world!");
}
package main Go
import "fmt"
func main() {
fmt.Println("hello world!")
}
- 10. Language bureaucracy
public class HelloWorld { Java
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
using System; C#
namespace HelloWorld
{
class Hello {
static void Main() {
Console.WriteLine("Hello World!");
}
}
}
- 11. Quest for a new system-level language
Requirements:
● Safe
● Portable
● Performant
● Expressive
● Elegant
Candidates:
1. Rust
2. Go
3. Nim
- 12. © Nim In Action, Dominik Picheta, Manning Publications, 2016
Portability
- 13. ● Nim → Backend (C, JS)
● Backend → Nim (C, JS)
● c2nim = Parse a C file and generate equivalent
Nim code
Interoperability
- 15. ● Statically typed / type inference
● Immutable / mutable variables
● whitespace-significant
Types and variables
- 16. ● Non-tracing GC
● Can be customised
○ GC_setMaxPause(MaxPauseInUs: int)
○ GC_step(us: int, strongAdvice = false, stackSize = -1)
● Can be turned off
○ GC_disable()
Garbage Collection
- 23. ● First-class citizens
● Closures
● Implicit returns
● Immutable arguments
● Overloading
● Uniform Function Call
● Style-indifferent
Functions