Type Prototypes
Nubo values can have functions attached to them through type prototypes.
A prototype is like a method table for a value. It lets you call functions directly on values:
let s = "hello"
println(s.length())println(s.toUpperCase())This means many values in Nubo are not just raw data. They can expose useful behavior.
Prototype Pages
Section titled “Prototype Pages”| Page | Description |
|---|---|
| Strings | String helpers like length, includes, split, trim, and case conversion. |
| Lists | List helpers like push, pop, map, filter, slice, and indexed access. |
| Dictionaries | Dictionary helpers like keys, values, remove, and indexed access. |
| Integers | Integer helpers like increment and decrement. |
| HTML Elements | Attribute and children helpers for html values. |
| Functions | Function metadata and initialized calls. |
| Structs | Struct fields, methods, private fields, and special hooks. |
| Internal Hooks | Internal names like __get__, __set__, __args__, and __returns__. |
Literal calls
Section titled “Literal calls”Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.
Best Practice
Section titled “Best Practice”Use prototype methods when they make code easier to read.
let text = "a,b,c"let parts = text.split(",")
println(parts)Avoid direct literal method calls until AST support is complete.
let greeting = "hello"println(greeting.length())Extending prototypes
Section titled “Extending prototypes”Built-in prototypes are frozen. You cannot attach arbitrary methods to a number, string, list, or built-in struct. Define a custom user struct and use impl for its methods. Declared instance fields, dictionary entries, list items, and HTML attributes remain writable through their supported APIs.