For developers who want code as readable as Python and executables as fast and small as C, tiko is a compiled language with Go-style concurrency, direct C-header import and a batteries-included standard library. It has no garbage collector, no runtime to install and no borrow checker to fight.
翻译准备中
正在加载完整 README。
查看完整 README ↗tiko is a compiled, statically typed programming language for building fast, self-contained programs. Its syntax is built to be read: blocks say what they close, keywords are words, and there is very little punctuation to learn. Underneath it is a systems language — generics, tuples, lambdas, typed errors, channels, direct use of C headers — compiled through LLVM to native code, with no virtual machine and no garbage collector.
#import "std/containers"
#import "std/strings"
'' Count the words in a sentence and return the most common one.
function MostCommon( byval text as ustring ) as (word as ustring, count as int32)
dim counts as containers.Map( of ustring, int32 )
for each w as ustring in strings.Split( LCase( text ), " " )
counts[ w ] += 1
next
dim as ustring best
dim as int32 most = 0
for each e in counts
if e.Value > most then best = e.Key : most = e.Value
next
return (best, most)
end function
var (word, n) = MostCommon( "the quick brown fox jumps over the lazy dog the end" )
print "'" & word & "' appears " & n & " times"
'the' appears 3 times
The tiko Programming Language is a book for programmers who know another language and are new to tiko. It teaches tiko as a language in its own right, and it is written in the tradition of The Rust Programming Language and K&R: the basics move briskly, and the idioms get room.
It starts with the basics (types, control flow, procedures, arrays and strings), then builds
abstractions (types, objects, modules, generics, errors, testing). It goes on to the advanced
language (tuples, iterators, lambdas, defer, concurrency), the standard library, and systems
programming: C interop with #cinclude, and building and shipping. It ends with three complete
projects: a command-line search tool, a concurrent pipeline and a terminal-UI ledger.
Every listing in the book is a real program, compiled and run on Windows, Linux and macOS with its output checked. The book is being written.
tiko by Example teaches the language through short, complete programs, in the style of Rust by Example. Each page is one runnable example followed by the output it printed, plus a few activities to try. Sections run from printing, values and control flow through procedures, types and objects to the standard library, concurrency and calling C. Every example is compiled and run on Windows, Linux and macOS before it is published.
end function, next, end if —
every block says what it closes, so a reviewer never counts braces..exe that imports only
kernel32.dll and ucrtbase.dll, both part of Windows. You don't install a runtime and you
don't need Visual Studio.defer covers everything else, and SharedPtr handles shared ownership.spawn a procedure, pass values through typed
Channels, and wait on several at once with select channel.#cinclude "sqlite3.h" imports a C library's own header through
libclang. You don't write a binding.Result/Optional, filesystem, date and time,
math, exact money types, structured logging and a terminal UI toolkit all ship with the
compiler.Errors are values. A fallible call returns a Result, so no exception can escape
unannounced and there is no error code to forget.
#import "std/fs"
var r = fs.ReadAllText( "settings.ini" )
if r.IsOk( ) then
print len( r.Value( ) ); " characters"
else
print "cannot read settings.ini: "; r.Failure( ).Message( )
end if
defer cleans up on every path out of a scope, in reverse order: fall-through, return,
exit and goto.
sub Work( )
print "open"
defer print "close"
for i as int32 = 1 to 3
if i = 2 then return '' "close" still prints
print "step"; i
next
end sub
Channels, not locks. Arguments are copied at the spawn, and a for each over a channel
ends when the sender closes it.
#import "std/tasks"
sub Squares( byval out_ as tasks.SendChan( of int32 ), byval n as int32 )
for i as int32 = 1 to n
out_.Send( i * i )
next
out_.Close( )
end sub
dim results as tasks.Channel( of int32 ) = tasks.Channel( of int32 )( 8 )
spawn Squares( results, 5 )
dim as int32 total = 0
for each v in results
total += v
next
print "sum of squares:"; total '' 55
Generics and lambdas. A non-capturing lambda is a plain function pointer, so it also works with C callbacks.
以上为 README 的开头部分。其余内容请阅读原文。 查看完整 README ↗