From 744290f0d49f567894414b77c636758dd4c3968a Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 9 Dec 2023 19:05:36 -0500 Subject: [PATCH] Write README --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7d398f6..ab5544c 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,19 @@ map = { Note that strings can be wrapped with any kind of quote: single, double or backticks. Numbers are always integers by default. Floats are declared by adding a decimal. If you divide integers or do any kind of math with a float, you will create a float value. +Dust enforces strict type checking, but you don't usually need to write the type, dust can figure it out on its own. The **number** and **any** types are special types that allow you to relax the type bounds. + +```dust +string = "foobar" +integer = 42 +float = 42.42 + +numbers <[number]> = [integer float] + +stuff <[any]> = [string integer float] +``` + + ### Lists Lists are sequential collections. They can be built by grouping values with square brackets. Commas are optional. Values can be indexed by their position using a colon `:` followed by an integer. Dust lists are zero-indexed. @@ -208,16 +221,16 @@ for number in list { ### Functions -Functions are first-class values in dust, so they are assigned to variables like any other value. +Functions are first-class values in dust, so they are assigned to variables like any other value. It is good practice to write the type definition for functions, otherwise the argument types and return type are set to `any`. ```dust # This simple function has no arguments. -say_hi = || { +say_hi = fn || { (output "hi") } # This function has one argument and will return a value. -add_one = int> |number| { +add_one <(int) -> int> = fn |number| { number + 1 }