ludic/examples/lang/defaults.ludic
Orkuncakilkaya 66a2bc2214 feat(lang): L11 views and templates - the UI is markup, not code
A `view Name { field = x; function q(..); on e(..) }` declaration is the one bridge between a
program and its UI: it writes view_<name>() -> UiView, whose model is a Value of every field and
whose call runs a query or an event by name.

ludic.ui is a template runtime:
- HTML-shaped XML screens and components, loaded at run time;
- {expression} bindings, if/else/each, props, slots, per-instance state;
- on-press / onclick actions (event, set, emit);
- component libraries (export="true", <import src as>).

Styling:
- stylesheets in <style> or importable .lss files (@import);
- CSS selectors (#id, .class, [attr=v], descendant and > combinators, :hover, :disabled,
  :first-child, :last-child, :nth-child, :not) weighed by specificity;
- the box model and flex under CSS's property names.

Also:
- default parameters, and positional-then-named calls;
- Value gains a float kind;
- a function shadowing a runtime one is refused;
- an index is evaluated before the slice is read;
- runtime errors name the right file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 15:58:47 +03:00

18 lines
837 B
Text

# defaults.ludic — L11: a parameter can have a default, and a call leaves out what it does not
# change - from the end when positional, or by not naming it. The leading arguments can be
# positional and the rest named, which is how a component is called: its subject, then its props.
#
# Running it prints: a 300.0 8.0 / b 120.0 8.0 / c! 300.0 8.0 / d 300.0 2.0 / x / y
program Defaults {
numbers float
const WIDE: float = 300.0
function box(label: string, w: float = WIDE, pad: float = 8.0, bold: bool = false) -> string {
var b = ""
if bold { b = "!" }
return `{label}{b} {w} {pad}`
}
function first<T>(xs: []T, at: int = 0) -> T { return xs[at] }
entry {
print(`{box("a")} / {box("b", 120.0)} / {box("c", bold: true)} / {box(pad: 2.0, label: "d")} / {first(["x", "y"])} / {first(["x", "y"], 1)}`)
}
}