Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
zig source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.14.0
zig 0.14.1
zig 0.15.1
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
fn lift(comptime x: anytype) type { return struct { pub const value = x; }; } fn integers(comptime int: comptime_int) type { return struct { pub const car = lift(int); pub const cdr = integers(int + 1); }; } fn zip(comptime l: type) fn (comptime r: type) type { return struct { fn next(comptime r: type) type { return struct { pub const car = struct { pub const car = l.car; pub const cdr = r.car; }; pub const cdr = if (l.cdr == void or r.cdr == void) void else zip(l.cdr)(r.cdr); }; } }.next; } fn repeatN(comptime count: comptime_int) fn (comptime value: anytype) type { return struct { fn next(comptime value: anytype) type { if (count == 0) return void; return struct { pub const car = lift(value); pub const cdr = repeatN(count - 1)(value); }; } }.next; } fn foldr(comptime f: type) fn (comptime init: type) fn (comptime list: type) type { return struct { fn next(comptime init: type) fn (comptime list: type) type { return struct { fn next(comptime list: type) type { return if (list == void) init else f.value(list.car)(foldr(f)(init)(list.cdr)); } }.next; } }.next; } fn first(comptime pair: type) @TypeOf(pair.car) { return pair.car; } fn cons(comptime a: type) fn (comptime b: type) type { return struct { fn next(comptime b: anytype) type { return struct { pub const car = a; pub const cdr = b; }; } }.next; } const flatten = foldr(struct { fn value(comptime x: type) fn (comptime xs: type) type { return struct { fn next(comptime xs: type) type { return cons(x.car)(xs); } }.next; } })(void); comptime { var list = flatten(zip(integers(0))(repeatN(10)({}))); while (list != void) : (list = list.cdr) { @compileLog(list.car.value); } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree