Modern systems programming language that abstracts complex concurrency whilst maintaining power and performance.
Designed to make systems programming accessible without sacrificing performance.
Express parallel operations naturally with
parallel
blocks and automatic thread management.
Clean, readable syntax. Focus on solving problems, not fighting the language.
It is still your job to manage memory (unless using the GC), but Scar provides tools to help you do it safely.
Compile to efficient native code with zero-cost abstractions and predictable performance characteristics.
Smart type inference reduces boilerplate while maintaining type safety and IDE support.
Seamlessly integrate with existing C libraries and systems through raw code blocks and FFI.
import "std/math"
import "std/log"
fn is_prime(i32 n) -> bool:
if n < 2:
return false
for i = 2 to math::sqrt(n):
if n % i == 0:
return false
return true
i32 limit = 50000
i32 primes_found = 0
parallel for i = 1 to limit:
if is_prime(i):
print "Prime: %d" | i
primes_found = primes_found + 1
log::info(fmt!("Found %d primes up to %d", primes_found, limit))
import "std/net"
import "std/strings"
import "std/log"
import "std/os"
i32 port = 8080
net::socket_init()
net::TcpServer server = net::tcp_server_create(port)
net::tcp_server_listen(server)
log::success(fmt!("Listening at http://localhost:%d", port))
while true:
net::TcpConnection conn = net::tcp_server_accept(server)
if conn.socket_fd < 0:
continue
lstring raw = net::tcp_receive(conn, 8192)
net::HttpRequest req = net::http_parse_request(raw)
if strings::compare(req.path, "/") == 0:
net::http_html_response(conn, "Hello from Scar HTTP server
")
else:
string body = "Not Found"
net::tcp_send(conn, fmt!("HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", strings::length(body), body))
net::tcp_close(conn)
net::tcp_server_close(server)
net::socket_cleanup()
local import "raylib.h"
pub val width = 800
pub val height = 600
pub val drops = 400
InitWindow(width, height, "Rain")
SetTargetFPS(60)
i32 t = 0
while not WindowShouldClose():
BeginDrawing()
ClearBackground(BLACK)
for i = 0 to drops - 1:
i32 xi = (i * 37) % width
i32 sp = 4 + ((i * 13) % 8)
i32 yi0 = (i * 97) % height
i32 y = (yi0 + t * sp) % height
i32 y2 = y + 12
if y2 >= height:
y2 = height
DrawLine(xi, y, xi, y2, BLUE)
DrawText("Rainfall", 10, 10, 20, RAYWHITE)
EndDrawing()
t = t + 1
CloseWindow()