Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Да и не думаю, что пакетные дистрибутивы будут рады десяткам и сотням тысяч новых пакетов в них
Beneath a nice infix/indentation based syntax with a powerful (AST based, hygienic) macro system lies a semantic model that supports a soft realtime GC on thread local heaps. Asynchronous message passing is used between threads, so no «stop the world» mechanism is necessary. An unsafe shared memory heap is also provided for the increased efficiency that results from that model.
Да, Nim позволяет программировать низкоуровневые вещи:
github.com/dom96/nimkernel
github.com/ckkashyap/rustix/issues/8 (отказ от Rust в пользу Nim в портировании Unix ядра)
hookrace.net/blog/nim-binary-size
github.com/def-/nim-small-coreutils
Ещё был вопрос какие проекты уже были написаны на Nim:
hookrace.net/blog/porting-nes-go-nim
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
def overdrawn(self):
return self.balance < 0
my_account = BankAccount(15)
my_account.withdraw(5)
print my_account.balance
class BankAccount(object):
{
def __init__(self, initial_balance=0):
{
self.balance = initial_balance
}
def deposit(self, amount):
{
self.balance += amount
}
def withdraw(self, amount):
{
self.balance -= amount
}
def overdrawn(self):
{
return self.balance < 0
}
}
my_account = BankAccount(15)
my_account.withdraw(5)
print my_account.balance
error: expected declaration or statement at end of inputIndentationError: unexpected indentfoo("bar") -- замест этого
foo "bar" -- писать так
-- или
foo({a=1, b=2})
foo {a=1, b=2}
foo(1, "bar);
foo 1 "bar" // проще и понятнее выглядит
fun1 :: Int -> Int -> Int -- принимает 2 Int'а, результат тоже Int
let fun1' = fun1 2
let x = fun1 2 $ 3 + 5
все эти «если .., то код значит вот то, но если .., то код значит вот это» усложняют языкхочется добавить:
Ну недостаток в том, что если у функции 0 аргументов, то не понятно, результат — это вызов функции или сама функция как объект.
foo $ sin x
-- или
foo (sin x)
foo(sin(x));
Rand -> (Rand, float), то есть принимает некое состояние ГСЧ и возвращает новое состояние ГСЧ и случайно сгенерированное значение. Так что нет, это функция не от нуля параметров, а от одного (неявного) параметра.foo(10,bar(20),baz(30,40)))foo 10, bar(20), baz(30, 40)foo 10 (bar 20) (baz 30 40) -- так же как в f#
foo 10 (bar 20) $ baz 30 40
foo 10 (bar 20) $ 30 `baz` 40
foo 10 (bar 20) . baz 30 $ 40
bar $ 1 + 1
let twicebar = bar . bar
twicebar 1 -- вместо bar(bar(1))
-- тоже что и
bar $ bar 1
foo . bar $ baz 1 -- замест foo(bar(baz(1)))
может он как-то к Gnome слишком привязан?Примерно как Objective C и MacOSX/iOS: теоретически язык вроде как вполне отдельный и универсальный, можно использовать где угодно, но практически — вне GNU/Linux'а это использовать тяжело.
template times(x: expr, y: stmt): stmt = for i in 1..x: y 10.times: echo "Hello World"
import std.stdio;
void times( T )( T x , void delegate() y )
{
for( T i = 0 ; i < x ; ++i ) {
y();
}
}
void main()
{
10.times({
writeln( "Hello World" );
});
}
template newSeqWith(len: int, init: expr): expr = var result = newSeq[type(init)](len) for i in 0 .. <len: result[i] = init result # Create a 2-dimensional sequence of size 20,10 var seq2D = newSeqWith(20, newSeq[bool](10))
import std.stdio;
void main()
{
auto seq2D = new bool[10][20];
writeln( seq2D[19][9] );
}
В первом шаблоне мы указываем, что a * 2 может быть заменено на a + a.
proc printf(formatstr: cstring) {.header: "<stdio.h>", varargs.} printf("%s %d\n", "foo", 5)
extern(C) int printf( in char* format , ... );
extern(C++) void main()
{
printf( "%s %d\n" , "foo".ptr , 5 );
}
Что такого особенного в Nim?