Skip to content

Advanced Tutorial

Luis Albizo edited this page Aug 29, 2018 · 15 revisions

Introduction

Strings

In wardscript there is no string data type, but with the help of nodes and bytes your can build one, even so there is a way for the interpreter to do this for you; with a syntactic sugar, just write the string you want between double quotes: "string". This will result in a node with a byte and another node referencing to the next char.

s := "My String";
? s is a node 
    The structure is: { $char := 77, $next := { $char := 121, $next := ... } }
    It is a linked list where $char is the byte value for the carácter and $next is another linked list or nil for the end of the string, like the following:
    77->121->32->3->116->114->105->110->103->nil
?
print(s); ? if the function print takes a node it wil treat it like a string and will print character by character. 
    the output will be "My String" (whitout end of line) ?

Lists

Lambdas

A lambda expression or an 'anonymous function' is a reduced syntaxis to create a function, a lambda just need a list of arguments and an expression, it automaticaly returns the result of that expresion.

$1 := func { x, y : x + y },
$2 := func { f, x : func { y : f(x, y) } };

Reduce operator

Closures and the nonlocal keyword

Clone this wiki locally