Türler comptime Değerleridir
Bir türü diğer tüm değerler gibi ele alın.
Türler comptime Değerleridir, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
A Type Is Just a Value
In Zig a type is not magic syntax: it is an ordinary value you can store, pass, and return. It simply lives only at compile-time. 🧠
The type of a Type Is type
Every type has the type type. So u8 is a value whose type is type, just like 5 is a value whose type is an integer.
const T: type = u8;Bind a Type to a const
You can name a type with a constant. Here Number becomes another name for i32 that you can use wherever a type is expected.
const Number = i32;
const x: Number = 7;Pass a Type to a Function
A function can take a type as a comptime parameter. The argument is a real value, evaluated while the program compiles.
fn sizeOf(comptime T: type) usize {
return @sizeOf(T);
}Return a Type from a Function
Because types are values, a function can return one. Its return type is just type, and the body produces a type as its result.
fn Pair() type {
return struct { a: u8, b: u8 };
}This Is How Generics Work
Passing and returning types is the foundation of Zig generics. There is no special generic syntax, just type values flowing around.
Types Live Only at Compile-Time
A value of type type exists only during compilation. You cannot store a type in a run-time variable or read one from input.
Inspect a Type with Builtins
Built-ins treat a type as data. @sizeOf takes a type value and returns how many bytes one instance of it occupies.
const bytes = @sizeOf(u32);Compare Types for Equality
Since types are values, you can compare them at compile-time. The expression T == u8 is true only when T is exactly u8.
Choose a Type at Compile-Time
You can branch on a type and pick another, all during compilation. This lets one function adapt its behavior to the type it gets.
Name a Type from a Function Result
Since a function can return a type, you can bind that result to a constant and then use it just like any built-in type name.
const Point = Pair();
const p: Point = .{ .a = 1, .b = 2 };Quick Check
In Zig, what is the type of the type u8 itself?
Recap
Types in Zig are comptime values of type type. You can name, pass, return, and compare them, which is exactly how generics are built. 🎯
Sıkça Sorulan Sorular
“Türler comptime Değerleridir” dersi ücretsiz mi?
Evet — “Türler comptime Değerleridir” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.
“Türler comptime Değerleridir” dersinde ne öğreneceğim?
Bir türü diğer tüm değerler gibi ele alın. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Zig Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.
“Türler comptime Değerleridir” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Derleme Zamanı ve Çalışma Zamanı Karşılaştırması
- comptime Parametreleri ve Değerleri
- Türler comptime Değerleridir
- inline for ve Açılmış Döngüler