馃幆 Typy danych

KitsuneScript jest j臋zykiem dynamicznie typowanym. Typ zmiennej jest okre艣lany w runtime i mo偶e si臋 zmienia膰.

Podstawowe typy

Typ Opis Przyk艂ad
number Liczby (ca艂kowite i zmiennoprzecinkowe) 42, 3.14, -5
string Tekst "hello", 'world'
bool Warto艣膰 logiczna true, false
null Brak warto艣ci null
list Tablica warto艣ci [1, 2, 3]
map S艂ownik klucz-warto艣膰 {name: "Kit"}
function Funkcja fn(x) { x * 2 }

Liczby (number)

// Liczby ca艂kowite let int = 42; let negative = -10; // Liczby zmiennoprzecinkowe let float = 3.14; let scientific = 1.5e10; // 15000000000 // Separatory dla czytelno艣ci let million = 1_000_000; let bigNum = 1_234_567_890; // Litera艂y binarne (0b) let binary = 0b1010; // = 10 let flags = 0b1111_0000; // = 240 // Litera艂y hexadecymalne (0x) let hex = 0xFF; // = 255 let color = 0xFFAABB; // = 16755387

Stringi (string)

// Pojedyncze i podw贸jne cudzys艂owy let str1 = "Hello, World!"; let str2 = 'Single quotes'; // Template strings z interpolacj膮 let name = "Kitsune"; let msg = `Cze艣膰, jestem ${name}!`; // Wyra偶enia w interpolacji let a = 10, b = 20; print(`${a} + ${b} = ${a + b}`); // "10 + 20 = 30" // Escape sequences let escaped = "Line 1\nLine 2\tTabbed"; // Raw strings (bez escape) let path = r"C:\Users\Name\Documents"; let regex = r"\d+\.\d+"; // Multi-line strings let poem = """ Roses are red, Violets are blue, KitsuneScript is great! """;

Booleany (bool)

let yes = true; let no = false; // Operacje logiczne let and = true && false; // false let or = true || false; // true let not = !true; // false // Warto艣ci "falsy" (traktowane jak false) // false, 0, "", null // Warto艣ci "truthy" (wszystko inne) if (1) print("truthy"); if ("text") print("truthy");

Null

let nothing = null; // Sprawdzanie null if (nothing == null) { print("To jest null"); } // Null coalescing let value = null; let safe = value ?? "default"; // "default" // Optional chaining let obj = null; let prop = obj?.name; // null (nie b艂膮d!)

Listy (list)

// Tworzenie listy let numbers = [1, 2, 3, 4, 5]; let mixed = [1, "text", true, null]; // r贸偶ne typy let empty = []; // Dost臋p do element贸w print(numbers[0]); // 1 (pierwszy) print(numbers[-1]); // 5 (ostatni) print(numbers[-2]); // 4 (przedostatni) // Modyfikacja numbers[0] = 100; print(numbers); // [100, 2, 3, 4, 5] // Rozmiar print(size(numbers)); // 5 print(numbers.length); // 5 // Trailing comma dozwolona let list = [1, 2, 3,]; // OK

Mapy (map)

// Tworzenie mapy let person = { name: "Kitsune", age: 25, active: true }; // Dost臋p do w艂a艣ciwo艣ci print(person.name); // "Kitsune" print(person["age"]); // 25 // Modyfikacja person.age = 26; person["email"] = "kit@example.com"; // Computed property names let key = "dynamicKey"; let obj = { [key]: 42, ["prefix_" + key]: 100 }; print(obj["dynamicKey"]); // 42 // Property shorthand let x = 10, y = 20; let point = {x, y}; // r贸wnowa偶ne {x: x, y: y} // Mapa z metodami let counter = { value: 0, increment: fn() { this.value = this.value + 1; return this.value; } }; print(counter.increment()); // 1

Sprawdzanie typ贸w

// Funkcja typeOf print(typeOf(42)); // "number" print(typeOf("hello")); // "string" print(typeOf(true)); // "bool" print(typeOf(null)); // "null" print(typeOf([1,2,3])); // "list" print(typeOf({a:1})); // "map" // Funkcje is* print(isNumber(42)); // true print(isString("text")); // true print(isBool(true)); // true print(isNull(null)); // true print(isList([1,2])); // true print(isMap({a:1})); // true print(isFunction(fn(){})); // true // Operator is if (value is string) { print("To jest string!"); }

Konwersja typ贸w

// Konwersja na string print(toString(42)); // "42" print(toString([1,2,3])); // "[1, 2, 3]" // Konwersja na liczb臋 print(toNumber("42")); // 42 print(toNumber(true)); // 1 print(toNumber(false)); // 0 // Na liczb臋 ca艂kowit膮 print(toInt(3.7)); // 3 // Na list臋 print(toList("abc")); // ["a", "b", "c"] // Na map臋 print(toMap([["a",1],["b",2]])); // {a: 1, b: 2} // Type cast z as! let num = "42" as! number; // 42 (rzuca b艂膮d przy niepowodzeniu) // Safe cast z as? let maybeNum = "abc" as? number; // null (nie rzuca b艂臋du)
馃摑 Uwaga

KitsuneScript u偶ywa as! dla force cast i as? dla safe cast. Samo as jest zarezerwowane dla innych konstrukcji.