ludus/prelude.md

1550 lines
42 KiB
Markdown
Raw Permalink Normal View History

2023-12-11 21:02:17 +00:00
# Ludus prelude documentation
These functions are available in every Ludus script.
The documentation for any function can be found within Ludus by passing the function to `doc!`,
e.g., running `doc! (add)` will send the documentation for `add` to the console.
For more information on the syntax & semantics of the Ludus language, see [language.md](./language.md).
2024-06-16 02:52:28 +00:00
The prelude itself is just a Ludus file, which you can see at [prelude.ld](./prelude.ld).
2023-12-11 21:16:16 +00:00
## A few notes
**Naming conventions.** Functions whose name ends with a question mark, e.g., `eq?`, return booleans.
Functions whose name ends with an exclamation point, e.g., `make!`, change state in some way.
In other words, they _do things_ rather than _calculating values_.
Functions whose name includes a slash either convert from one value to another, e.g. `deg/rad`,
or they are variations on a function, e.g. `div/0` as a variation on `div`.
**How entries are formatted.** Each entry has a brief (sometimes too brief!) description of what it does.
It is followed by the patterns for each of its function clauses.
2023-12-13 19:15:32 +00:00
This should be enough to indicate order of arguments, types, and so on.
**Patterns often, but do not always, indicate types.** Typed patterns are written as `foo as :bar`,
where the type is indicated by the keyword.
Possible ludus types are: `:nil`, `:boolean`, `:number`, `:keyword` (atomic values);
2024-06-16 02:52:28 +00:00
`:string` (strings are their own beast); `:tuple` and `:list` (ordered collections), `:set`s, and `:dict`ionaries (the other collection types); `:pkg` (packages, which are quasi-collections); `:fn` (functions); and `:box`es.
2023-12-13 19:15:32 +00:00
**Conventional types.** Ludus has two types based on conventions.
* _Result tuples._ Results are a way of modeling the result of a calculation that might fail.
The two possible values are `(:ok, value)` and `(:err, msg)`.
`msg` is usually a string describing what went wrong.
To work with result tuples, see [`unwrap!`](#unwrap) and [`unwrap_or`](#unwrap_or).
That said, usually you work with these using pattern matching.
* _Vectors._ Vectors are 2-element tuples of x and y coordinates.
The origin is `(0, 0)`.
Many math functions take vectors as well as numbers, e.g., `add` and `mult`.
You will see vectors indicated in patterns by an `(x, y)` tuple.
You can see what this looks like in the last clause of `add`: `((x1, y1), (x2, y2))`.
## Functions by topic
### Boolean
2024-06-16 01:53:09 +00:00
[and](#and)    [bool](#bool)    [bool?](#bool)    [false?](#false)    [not](#not)    [or](#or)    [true?](#true)
### Boxes and state
2024-06-16 01:53:09 +00:00
[box?](#box)    [store!](#store)    [unbox](#unbox)    [update!](#update)
### Dicts
[any?](#any)    [assoc](#assoc)    [assoc?](#assoc)    [coll?](#coll)    [count](#count)    [dict](#dict)    [dict?](#dict)    [diff](#diff)    [dissoc](#dissoc)    [empty?](#empty)    [get](#get)    [keys](#keys)    [random](#random)    [update](#update)    [values](#values)
### Environment and i/o
[doc!](#doc)    [print!](#print)    [report!](#report)    [state](#state)
### Errors
[assert!](#assert)
### Lists
[any?](#any)    [append](#append)    [at](#at)    [butlast](#butlast)    [coll?](#coll)    [concat](#concat)    [count](#count)    [each!](#each)    [empty?](#empty)    [filter](#filter)    [first](#first)    [fold](#fold)    [join](#join)    [keep](#keep)    [last](#last)    [list](#list)    [list?](#list)    [map](#map)    [ordered?](#ordered)    [random](#random)    [range](#range)    [rest](#rest)    [second](#second)    [sentence](#sentence)    [slice](#slice)
### Math
2024-06-16 01:53:09 +00:00
[abs](#abs)    [add](#add)    [angle](#angle)    [atan/2](#atan/2)    [between?](#between)    [ceil](#ceil)    [cos](#cos)    [dec](#dec)    [deg/rad](#deg/rad)    [deg/turn](#deg/turn)    [dist](#dist)    [div](#div)    [div/0](#div/0)    [div/safe](#div/safe)    [even?](#even)    [floor](#floor)    [gt?](#gt)    [gte?](#gte)    [heading/vector](#heading/vector)    [inc](#inc)    [inv](#inv)    [inv/0](#inv/0)    [inv/safe](#inv/safe)    [lt?](#lt)    [lte?](#lte)    [max](#max)    [min](#min)    [mod](#mod)    [mod/0](#mod/0)    [mod/safe](#mod/safe)    [mult](#mult)    [neg](#neg)    [neg?](#neg)    [odd?](#odd)    [pi](#pi)    [pos?](#pos)    [rad/deg](#rad/deg)    [rad/turn](#rad/turn)    [random](#random)    [random\_int](#random\_int)    [range](#range)    [round](#round)    [sin](#sin)    [sqrt](#sqrt)    [sqrt/safe](#sqrt/safe)    [square](#square)    [sub](#sub)    [sum\_of_squares](#sum\_of_squares)    [tan](#tan)    [tau](#tau)    [turn/deg](#turn/deg)    [turn/rad](#turn/rad)    [zero?](#zero)
### Results
[err](#err)    [err?](#err)    [ok](#ok)    [ok?](#ok)    [unwrap!](#unwrap)    [unwrap\_or](#unwrap\_or)
### Sets
2024-06-16 01:53:09 +00:00
[any?](#any)    [append](#append)    [coll?](#coll)    [concat](#concat)    [contains?](#contains)    [count](#count)    [empty?](#empty)    [omit](#omit)    [random](#random)    [set](#set)    [set?](#set)
### Strings
[any?](#any)    [concat](#concat)    [count](#count)    [downcase](#downcase)    [empty?](#empty)    [join](#join)    [sentence](#sentence)    [show](#show)    [slice](#slice)    [split](#split)    [string](#string)    [string?](#string)    [strip](#strip)    [trim](#trim)    [upcase](#upcase)    [words](#words)
2024-06-16 01:53:09 +00:00
### Tuples
2024-06-16 02:19:50 +00:00
[any?](#any)    [at](#at)    [coll?](#coll)    [count](#count)    [empty?](#empty)    [first](#first)    [last](#last)    [ordered?](#ordered)    [rest](#rest)    [second](#second)    [tuple?](#tuple)
2024-06-16 01:53:09 +00:00
### Turtle graphics
[back!](#back)    [background!](#background)    [bk!](#bk)    [clear!](#clear)    [colors](#colors)    [fd!](#fd)    [forward!](#forward)    [goto!](#goto)    [heading](#heading)    [heading/vector](#heading/vector)    [home!](#home)    [left!](#left)    [lt!](#lt)    [pc!](#pc)    [pd!](#pd)    [pencolor](#pencolor)    [pencolor!](#pencolor)    [pendown!](#pendown)    [pendown?](#pendown)    [penup!](#penup)    [penwidth](#penwidth)    [penwidth!](#penwidth)    [position](#position)    [pu!](#pu)    [pw!](#pw)    [render\_turtle!](#render\_turtle)    [reset\_turtle!](#reset\_turtle)    [right!](#right)    [rt!](#rt)    [turtle\_state](#turtle\_state)
### Types and values
2024-06-16 01:53:09 +00:00
[assoc?](#assoc)    [bool?](#bool)    [box?](#box)    [coll?](#coll)    [dict?](#dict)    [eq?](#eq)    [fn?](#fn)    [keyword?](#keyword)    [list?](#list)    [neq?](#neq)    [nil?](#nil)    [number?](#number)    [ordered?](#ordered)    [set?](#set)    [show](#show)    [some](#some)    [some?](#some)    [string?](#string)    [tuple?](#tuple)    [type](#type)
## All functions, alphabetically
2024-06-16 01:53:09 +00:00
[abs](#abs)    [add](#add)    [and](#and)    [angle](#angle)    [any?](#any)    [append](#append)    [assert!](#assert)    [assoc](#assoc)    [assoc?](#assoc)    [at](#at)    [atan/2](#atan/2)    [back!](#back)    [background!](#background)    [between?](#between)    [bg!](#bg)    [bgcolor](#bgcolor)    [bk!](#bk)    [bool](#bool)    [bool?](#bool)    [box?](#box)    [butlast](#butlast)    [ceil](#ceil)    [clear!](#clear)    [coll?](#coll)    [colors](#colors)    [concat](#concat)    [contains?](#contains)    [cos](#cos)    [count](#count)    [dec](#dec)    [deg/rad](#deg/rad)    [deg/turn](#deg/turn)    [dict](#dict)    [dict?](#dict)    [diff](#diff)    [dissoc](#dissoc)    [dist](#dist)    [div](#div)    [div/0](#div/0)    [div/safe](#div/safe)    [doc!](#doc)    [downcase](#downcase)    [each!](#each)    [empty?](#empty)    [eq?](#eq)    [err](#err)    [err?](#err)    [even?](#even)    [false?](#false)    [fd!](#fd)    [filter](#filter)    [first](#first)    [floor](#floor)    [fn?](#fn)    [fold](#fold)    [forward!](#forward)    [get](#get)    [goto!](#goto)    [gt?](#gt)    [gte?](#gte)    [heading](#heading)    [heading/vector](#heading/vector)    [home!](#home)    [inc](#inc)    [inv](#inv)    [inv/0](#inv/0)    [inv/safe](#inv/safe)    [join](#join)    [keep](#keep)    [keys](#keys)    [keyword?](#keyword)    [last](#last)    [left!](#left)    [list](#list)    [list?](#list)    [load\_turtle_state!](#load\_turtle_state)    [lt!](#lt)    [lt?](#lt)    [lte?](#lte)    [map](#map)    [max](#max)    [min](#min)    [mod](#mod)    [mod/0](#mod/0)    [mod/safe](#mod/safe)    [mult](#mult)    [neg](#neg)    [neg?](#neg)    [neq?](#neq)    [nil?](#nil)    [not](#not)    [odd?](#odd)    [ok](#ok)    [ok?](#ok)    [omit](#omit)    [or](#or)    [ordered?](#ordered)    [p5\_calls](#p5\_calls)    [pc!](#pc)    [pd!](#pd)    [pencolor](#pencolor)    [pencolor!](#pencolor)    [pendown!](#pendown)    [pendown?](#pendown)    [penup!](#penup)    [penwidth](#penwidth)    [penwidth!](#penwidth)    [pi](#pi)    [pos?](#pos)    [position](#position)    [print!](#print)    [pu!](#pu)    [pw!](#pw)    [rad/deg](#rad/deg)    [rad/turn](#rad/turn)    [random](#random)    [random\_int](#random\_int)    [range](#range)    [render\_turtle!](#render\_turtle)    [report!](#report) &nbs
2023-12-11 21:02:17 +00:00
## Function documentation
2024-06-16 01:53:09 +00:00
2023-12-11 21:02:17 +00:00
### abs
2023-12-12 20:38:16 +00:00
Returns the absolute value of a number.
```
2023-12-11 21:16:16 +00:00
(0)
2024-06-15 21:04:01 +00:00
(n as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### add
2023-12-12 20:38:16 +00:00
Adds numbers or vectors.
```
2023-12-11 21:16:16 +00:00
()
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:16:16 +00:00
((x1, y1), (x2, y2))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### and
2024-06-15 21:04:01 +00:00
Returns true if all values passed in are truthy. Note that this does not short-circuit: all arguments are evaulated before they are passed in.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
()
(x)
(x, y)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### angle
2023-12-12 20:38:16 +00:00
Calculates the angle between two vectors.
```
2023-12-11 21:02:17 +00:00
(v1, v2)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### any?
Returns true if something is not empty, otherwise returns false (including for things that can't be logically full, like numbers).
```
([...])
(#{...})
(s as :set)
((...))
(s as :string)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### append
2023-12-12 20:38:16 +00:00
Adds an element to a list or set.
```
2023-12-11 21:16:16 +00:00
()
(xs as :list)
(xs as :list, x)
(xs as :set)
(xs as :set, x)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### assert!
2023-12-12 20:38:16 +00:00
Asserts a condition: returns the value if the value is truthy, panics if the value is falsy. Takes an optional message.
```
2023-12-11 21:16:16 +00:00
(value)
2024-06-15 21:04:01 +00:00
(msg, value)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### assoc
2023-12-12 20:38:16 +00:00
Takes a dict, key, and value, and returns a new dict with the key set to value.
```
2023-12-11 21:16:16 +00:00
()
(dict as :dict)
(dict as :dict, key as :keyword, value)
(dict as :dict, (key as :keyword, value))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### assoc?
2024-06-15 21:04:01 +00:00
Returns true if a value is an associative collection: a dict or a pkg.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(assoc as :dict)
2024-06-15 21:04:01 +00:00
(assoc as :pkg)
2023-12-11 21:16:16 +00:00
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### at
2024-06-15 21:04:01 +00:00
Returns the element at index n of a list or tuple, or the byte at index n of a string. Zero-indexed: the first element is at index 0. Returns nil if nothing is found in a list or tuple; returns an empty string if nothing is found in a string.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(xs as :list, n as :number)
(xs as :tuple, n as :number)
2024-06-15 21:04:01 +00:00
(str as :string, n as :number)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### atan/2
2023-12-12 20:38:16 +00:00
Returns an angle from a slope. Takes an optional keyword argument to specify units. Takes either two numbers or a vector tuple.
```
2023-12-11 21:16:16 +00:00
(x as :number, y as :number)
(x, y, :turns)
(x, y, :radians)
(x, y, :degrees)
((x, y))
((x, y), units as :keyword)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### back!
2023-12-12 20:38:16 +00:00
Moves the turtle backward by a number of steps. Alias: bk!
```
2023-12-11 21:02:17 +00:00
(steps as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### background!
2023-12-12 20:38:16 +00:00
Sets the background color behind the turtle and path. Alias: bg!
```
2023-12-11 21:16:16 +00:00
(gray as :number)
((r as :number, g as :number, b as :number))
((r as :number, g as :number, b as :number, a as :number))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### between?
Returns true if a number is in the range [lower, higher): greater than or equal to the lower number, less than the higher.
```
(lower as :number, higher as :number, x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### bg!
2023-12-12 20:38:16 +00:00
Sets the background color behind the turtle and path. Alias: bg!
```
2023-12-11 21:16:16 +00:00
(gray as :number)
((r as :number, g as :number, b as :number))
((r as :number, g as :number, b as :number, a as :number))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### bgcolor
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### bk!
2023-12-12 20:38:16 +00:00
Moves the turtle backward by a number of steps. Alias: bk!
```
2023-12-11 21:02:17 +00:00
(steps as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### bool
2023-12-12 20:38:16 +00:00
Returns false if a value is nil or false, otherwise returns true.
```
2023-12-11 21:16:16 +00:00
(nil)
(false)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### bool?
2023-12-12 20:38:16 +00:00
Returns true if a value is of type :boolean.
```
2023-12-11 21:16:16 +00:00
(false)
(true)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### box?
Returns true if a value is a box.
```
(b as :box)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### butlast
2023-12-12 20:38:16 +00:00
Returns a list, omitting the last element.
```
2023-12-11 21:02:17 +00:00
(xs as :list)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### ceil
2023-12-12 20:38:16 +00:00
Truncates a number towards positive infinity. With negative numbers, it returns the integer part. With positive numbers, returns the next more-positive integer.
```
2023-12-11 21:02:17 +00:00
(n as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### clear!
2023-12-12 20:38:16 +00:00
Clears the canvas and sends the turtle home.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### coll?
2024-06-16 01:53:09 +00:00
Returns true if a value is a collection: dict, list, tuple, or set.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(coll as :dict)
(coll as :list)
(coll as :tuple)
(coll as :set)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### colors
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### concat
2023-12-12 20:38:16 +00:00
Combines two lists, strings, or sets.
```
2023-12-11 21:16:16 +00:00
(x as :string, y as :string)
(xs as :list, ys as :list)
(xs as :set, ys as :set)
2024-06-15 21:04:01 +00:00
(xs, ys, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-16 01:53:09 +00:00
---
### contains?
Returns true if a set or list contains a value.
```
(value, set as :set)
(value, list as :list)
```
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### cos
2023-12-12 20:38:16 +00:00
Returns the cosine of an angle. Default angle measure is turns. An optional keyword argument specifies the units of the angle passed in.
```
2023-12-11 21:16:16 +00:00
(a as :number)
(a as :number, :turns)
(a as :number, :degrees)
(a as :number, :radians)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### count
2023-12-12 20:38:16 +00:00
Returns the number of elements in a collection (including string).
```
2023-12-11 21:16:16 +00:00
(xs as :list)
(xs as :tuple)
(xs as :dict)
(xs as :string)
(xs as :set)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### dec
2023-12-12 20:38:16 +00:00
Decrements a number.
```
2023-12-11 21:02:17 +00:00
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### deg/rad
2023-12-12 20:38:16 +00:00
Converts an angle in degrees to an angle in radians.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### deg/turn
2023-12-12 20:38:16 +00:00
Converts an angle in degrees to an angle in turns.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### dict
2024-06-15 21:04:01 +00:00
Takes a list or tuple of (key, value) tuples and returns it as a dict. Returns dicts unharmed.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(dict as :dict)
(list as :list)
(tup as :tuple)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### dict?
Returns true if a value is a dict.
```
(dict as :dict)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### diff
2024-06-15 21:04:01 +00:00
Takes two dicts and returns a dict describing their differences. Does this shallowly, offering diffs only for keys in the original dict.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:02:17 +00:00
(d1 as :dict, d2 as :dict)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### dissoc
2023-12-12 20:38:16 +00:00
Takes a dict and a key, and returns a new dict with the key and associated value omitted.
```
2023-12-11 21:16:16 +00:00
(dict as :dict)
(dict as :dict, key as :keyword)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### dist
2024-06-16 01:53:09 +00:00
Returns the distance from the origin to a point described by x and y, or by the vector (x, y).
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(x as :number, y as :number)
((x, y))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### div
2023-12-12 20:38:16 +00:00
Divides numbers. Panics on division by zero.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_, 0)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### div/0
2023-12-12 20:38:16 +00:00
Divides numbers. Returns 0 on division by zero.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_, 0)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### div/safe
2023-12-12 20:38:16 +00:00
Divides a number. Returns a result tuple.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_, 0)
(x, y)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### doc!
2023-12-12 20:38:16 +00:00
Prints the documentation of a function to the console.
```
2023-12-11 21:16:16 +00:00
(f as :fn)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### downcase
Takes a string and returns it in all lowercase. Works only for ascii characters.
```
(str as :string)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### each!
2023-12-12 20:38:16 +00:00
Takes a list and applies a function, presumably with side effects, to each element in the list. Returns nil.
```
2023-12-11 21:16:16 +00:00
(f! as :fn, [])
(f! as :fn, [x])
2024-06-16 01:53:09 +00:00
(f! as :fn, [x, ...])
2024-06-15 21:04:01 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### empty?
Returns true if something is empty. Otherwise returns false (including for things that can't logically be empty, like numbers).
```
([])
(#{})
(s as :set)
(())
("")
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### eq?
2023-12-12 20:38:16 +00:00
Returns true if all arguments have the same value.
```
2023-12-11 21:16:16 +00:00
(x)
(x, y)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### err
2023-12-12 20:38:16 +00:00
Takes a value and wraps it in an :err result tuple, presumably as an error message.
```
2023-12-11 21:02:17 +00:00
(msg)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### err?
2023-12-12 20:38:16 +00:00
Takes a value and returns true if it is an :err result tuple.
```
2023-12-11 21:16:16 +00:00
((:err, _))
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### even?
2023-12-12 20:38:16 +00:00
Returns true if a value is an even number, otherwise returns false.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### false?
2024-06-15 21:04:01 +00:00
Returns `true` if a value is `false`, otherwise returns `false`. Useful to distinguish between `false` and `nil`.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(false)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### fd!
2023-12-12 20:38:16 +00:00
Moves the turtle forward by a number of steps. Alias: fd!
```
2023-12-11 21:02:17 +00:00
(steps as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### filter
Takes a list and a predicate function, and returns a new list with only the items that produce truthy values when the function is called on them. E.g., `filter ([1, 2, 3, 4], odd?) &=> [1, 3]`.
```
(p? as :fn, xs)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### first
2023-12-12 20:38:16 +00:00
Returns the first element of a list or tuple.
```
2023-12-11 21:02:17 +00:00
(xs)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### floor
2023-12-12 20:38:16 +00:00
Truncates a number towards negative infinity. With positive numbers, it returns the integer part. With negative numbers, returns the next more-negative integer.
```
2023-12-11 21:02:17 +00:00
(n as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### fn?
2023-12-12 20:38:16 +00:00
Returns true if an argument is a function.
```
2023-12-11 21:16:16 +00:00
(f as :fn)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### fold
2023-12-12 20:38:16 +00:00
Folds a list.
```
2023-12-11 21:16:16 +00:00
(f as :fn, xs as :list)
(f as :fn, xs as :list, root)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### forward!
2023-12-12 20:38:16 +00:00
Moves the turtle forward by a number of steps. Alias: fd!
```
2023-12-11 21:02:17 +00:00
(steps as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### get
2024-06-15 21:04:01 +00:00
Takes a key, dict, and optional default value; returns the value at key. If the value is not found, returns nil or the default value.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(key as :keyword)
2024-06-15 21:04:01 +00:00
(key as :keyword, dict as :dict)
(key as :keyword, dict as :dict, default)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### goto!
2023-12-12 20:38:16 +00:00
Sends the turtle to (x, y) coordinates. If the pen is down, the turtle will draw a path to its new location.
```
2023-12-11 21:16:16 +00:00
(x as :number, y as :number)
((x, y))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### gt?
2023-12-12 20:38:16 +00:00
Returns true if numbers are in decreasing order.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### gte?
2023-12-12 20:38:16 +00:00
Returns true if numbers are in decreasing or flat order.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### heading
2023-12-12 20:38:16 +00:00
Returns the turtle's current heading.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### heading/vector
2023-12-12 20:38:16 +00:00
Takes a turtle heading, and returns a unit vector of that heading.
```
2023-12-11 21:02:17 +00:00
(heading)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### home!
2023-12-12 20:38:16 +00:00
Sends the turtle home: to the centre of the screen, pointing up. If the pen is down, the turtle will draw a path to home.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### inc
2023-12-12 20:38:16 +00:00
Increments a number.
```
2023-12-11 21:02:17 +00:00
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### inv
Returns the inverse of a number: 1/n or `div (1, n)`. Panics on division by zero.
```
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### inv/0
Returns the inverse of a number: 1/n or `div/0 (1, n)`. Returns 0 on division by zero.
```
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### inv/safe
Returns the inverse of a number: 1/n or `div/safe (1, n)`. Returns a result tuple.
```
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### join
2023-12-12 20:38:16 +00:00
Takes a list of strings, and joins them into a single string, interposing an optional separator.
```
2023-12-11 21:16:16 +00:00
([])
([str as :string])
(strs as :list)
2024-06-16 01:53:09 +00:00
([str as :string], separator as :string)
2024-06-15 21:04:01 +00:00
([str, ...], separator as :string)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### keep
Takes a list and returns a new list with any `nil` values omitted.
```
(xs)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### keys
2024-06-15 21:04:01 +00:00
Takes a dict and returns a list of keys in that dict.
2023-12-12 20:38:16 +00:00
```
2024-06-15 21:04:01 +00:00
(dict as :dict)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### keyword?
2023-12-12 20:38:16 +00:00
Returns true if a value is a keyword, otherwise returns false.
```
2023-12-11 21:16:16 +00:00
(kw as :keyword)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### last
2023-12-12 20:38:16 +00:00
Returns the last element of a list or tuple.
```
2023-12-11 21:02:17 +00:00
(xs)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### left!
2023-12-12 20:38:16 +00:00
Rotates the turtle left, measured in turns. Alias: lt!
```
2023-12-11 21:02:17 +00:00
(turns as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### list
2024-06-16 01:53:09 +00:00
Takes a value and returns it as a list. For values, it simply wraps them in a list. For collections, conversions are as follows. A tuple->list conversion preservers order and length. Unordered collections do not preserve order: sets and dicts don't have predictable or stable ordering in output. Dicts return lists of (key, value) tuples.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:02:17 +00:00
(x)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### list?
Returns true if the value is a list.
```
(l as :list)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### load_turtle_state!
Sets the turtle state to a previously saved state. Returns the state.
```
(state)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### lt!
2023-12-12 20:38:16 +00:00
Rotates the turtle left, measured in turns. Alias: lt!
```
2023-12-11 21:02:17 +00:00
(turns as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### lt?
2023-12-12 20:38:16 +00:00
Returns true if numbers are in increasing order.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### lte?
2023-12-12 20:38:16 +00:00
Returns true if numbers are in increasing or flat order.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### map
2024-06-15 21:04:01 +00:00
Maps a function over a list: returns a new list with elements that are the result of applying the function to each element in the original list. E.g., `map ([1, 2, 3], inc) &=> [2, 3, 4]`.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(f as :fn, xs)
(kw as :keyword, xs)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### max
Returns the number in its arguments that is closest to positive infinity.
```
(x as :number)
(x as :number, y as :number)
(x, y, ...)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### min
Returns the number in its arguments that is closest to negative infinity.
```
(x as :number)
(x as :number, y as :number)
(x, y, ...)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### mod
2024-06-16 01:53:09 +00:00
Returns the modulus of num and div. Truncates towards negative infinity. Panics if div is 0.
2023-12-12 20:38:16 +00:00
```
2024-06-16 01:53:09 +00:00
(num as :number, 0)
2024-06-15 21:04:01 +00:00
(num as :number, div as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-16 01:53:09 +00:00
---
### mod/0
Returns the modulus of num and div. Truncates towards negative infinity. Returns 0 if div is 0.
```
(num as :number, 0)
(num as :number, div as :number)
```
[Back to top.](#ludus-prelude-documentation)
---
### mod/safe
Returns the modulus of num and div in a result tuple, or an error if div is 0. Truncates towards negative infinity.
```
(num as :number, 0)
(num as :number, div as :number)
```
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### mult
2023-12-12 20:38:16 +00:00
Multiplies numbers or vectors.
```
2023-12-11 21:16:16 +00:00
()
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:16:16 +00:00
(scalar as :number, (x, y))
((x, y), scalar as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### neg
2023-12-12 20:38:16 +00:00
Multiplies a number by -1, negating it.
```
2023-12-11 21:02:17 +00:00
(n as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### neg?
2023-12-12 20:38:16 +00:00
Returns true if a value is a negative number, otherwise returns false.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### neq?
Returns true if none of the arguments have the same value.
```
(x)
(x, y)
(x, y, ...)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### nil?
2023-12-12 20:38:16 +00:00
Returns true if a value is nil.
```
2023-12-11 21:16:16 +00:00
(nil)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### not
2023-12-12 20:38:16 +00:00
Returns false if a value is truthy, true if a value is falsy.
```
2023-12-11 21:16:16 +00:00
(nil)
(false)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### odd?
2023-12-12 20:38:16 +00:00
Returns true if a value is an odd number, otherwise returns false.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### ok
2023-12-12 20:38:16 +00:00
Takes a value and wraps it in an :ok result tuple.
```
2023-12-11 21:02:17 +00:00
(value)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### ok?
2023-12-12 20:38:16 +00:00
Takes a value and returns true if it is an :ok result tuple.
```
2023-12-11 21:16:16 +00:00
((:ok, _))
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-16 01:53:09 +00:00
---
### omit
Returns a new set with the value omitted.
```
(value, s as :set)
```
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### or
2024-06-15 21:04:01 +00:00
Returns true if any value passed in is truthy. Note that this does not short-circuit: all arguments are evaluated before they are passed in.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
()
(x)
(x, y)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### ordered?
2023-12-12 20:38:16 +00:00
Returns true if a value is an indexed collection: list or tuple.
```
2023-12-11 21:16:16 +00:00
(coll as :list)
(coll as :tuple)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### p5_calls
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pc!
2023-12-12 20:38:16 +00:00
Changes the turtle's pen color. Takes a single grayscale value, an rgb tuple, or an rgba tuple. Alias: pc!
```
2023-12-11 21:16:16 +00:00
(gray as :number)
((r as :number, g as :number, b as :number))
((r as :number, g as :number, b as :number, a as :number))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pd!
2023-12-12 20:38:16 +00:00
Lowers the turtle's pen, causing it to draw. Alias: pd!
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pencolor
2023-12-12 20:38:16 +00:00
Returns the turtle's pen color as an (r, g, b, a) tuple.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pencolor!
2023-12-12 20:38:16 +00:00
Changes the turtle's pen color. Takes a single grayscale value, an rgb tuple, or an rgba tuple. Alias: pc!
```
2023-12-11 21:16:16 +00:00
(gray as :number)
((r as :number, g as :number, b as :number))
((r as :number, g as :number, b as :number, a as :number))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pendown!
2023-12-12 20:38:16 +00:00
Lowers the turtle's pen, causing it to draw. Alias: pd!
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pendown?
2023-12-12 20:38:16 +00:00
Returns the turtle's pen state: true if the pen is down.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### penup!
2023-12-12 20:38:16 +00:00
Lifts the turtle's pen, stopping it from drawing. Alias: pu!
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### penwidth
2023-12-12 20:38:16 +00:00
Returns the turtle's pen width in pixels.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### penwidth!
2023-12-12 20:38:16 +00:00
Sets the width of the turtle's pen, measured in pixels. Alias: pw!
```
2023-12-11 21:02:17 +00:00
(width as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pi
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pos?
2023-12-12 20:38:16 +00:00
Returns true if a value is a positive number, otherwise returns false.
```
2023-12-11 21:16:16 +00:00
(x as :number)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### position
2023-12-12 20:38:16 +00:00
Returns the turtle's current position.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### print!
2023-12-12 20:38:16 +00:00
Sends a text representation of Ludus values to the console.
```
2024-06-15 21:04:01 +00:00
(...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pu!
2023-12-12 20:38:16 +00:00
Lifts the turtle's pen, stopping it from drawing. Alias: pu!
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### pw!
2023-12-12 20:38:16 +00:00
Sets the width of the turtle's pen, measured in pixels. Alias: pw!
```
2023-12-11 21:02:17 +00:00
(width as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### rad/deg
2023-12-12 20:38:16 +00:00
Converts an angle in radians to an angle in degrees.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### rad/turn
2023-12-12 20:38:16 +00:00
Converts an angle in radians to an angle in turns.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### random
2024-06-16 01:53:09 +00:00
Returns a random something. With zero arguments, returns a random number between 0 (inclusive) and 1 (exclusive). With one argument, returns a random number between 0 and n. With two arguments, returns a random number between m and n. Alternately, given a collection (list, dict, set), it returns a random member of that collection.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
()
(n as :number)
(m as :number, n as :number)
2024-06-15 21:04:01 +00:00
(l as :list)
(d as :dict)
2024-06-16 01:53:09 +00:00
(s as :set)
2024-06-15 21:04:01 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### random_int
Returns a random integer. With one argument, returns a random integer between 0 and that number. With two arguments, returns a random integer between them.
```
(n as :number)
(m as :number, n as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### range
2024-06-15 21:04:01 +00:00
Returns the set of integers between start (inclusive) and end (exclusive) as a list: [start, end). With one argument, starts at 0. If end is less than start, returns an empty list.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(end as :number)
(start as :number, end as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### render_turtle!
No docstring available.
2023-12-11 21:16:16 +00:00
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### report!
2023-12-12 20:38:16 +00:00
Prints a value, then returns it.
```
2023-12-11 21:16:16 +00:00
(x)
(msg as :string, x)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### reset_turtle!
2023-12-12 20:38:16 +00:00
Resets the turtle to its original state.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### rest
2023-12-12 20:38:16 +00:00
Returns all but the first element of a list or tuple, as a list.
```
2023-12-11 21:16:16 +00:00
(xs as :list)
(xs as :tuple)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### right!
2023-12-12 20:38:16 +00:00
Rotates the turtle right, measured in turns. Alias: rt!
```
2023-12-11 21:02:17 +00:00
(turns as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### round
2023-12-12 20:38:16 +00:00
Rounds a number to the nearest integer.
```
2023-12-11 21:02:17 +00:00
(n as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### rt!
2023-12-12 20:38:16 +00:00
Rotates the turtle right, measured in turns. Alias: rt!
```
2023-12-11 21:02:17 +00:00
(turns as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### second
2023-12-12 20:38:16 +00:00
Returns the second element of a list or tuple.
```
2023-12-11 21:02:17 +00:00
(xs)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### sentence
Takes a list of words and turns it into a sentence.
```
(strs as :list)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### set
2023-12-12 20:38:16 +00:00
Takes an ordered collection--list or tuple--and turns it into a set.
```
2023-12-11 21:16:16 +00:00
(xs as :list)
(xs as :tuple)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### set?
Returns true if a value is a set.
```
(xs as :set)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### show
2023-12-12 20:38:16 +00:00
Returns a text representation of a Ludus value as a string.
```
2023-12-11 21:02:17 +00:00
(x)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### sin
2023-12-12 20:38:16 +00:00
Returns the sine of an angle. Default angle measure is turns. An optional keyword argument specifies the units of the angle passed in.
```
2023-12-11 21:16:16 +00:00
(a as :number)
(a as :number, :turns)
(a as :number, :degrees)
(a as :number, :radians)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### slice
2024-06-16 02:19:50 +00:00
Returns a slice of a list or a string, representing a sub-list or sub-string.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(xs as :list, end as :number)
(xs as :list, start as :number, end as :number)
2024-06-15 21:04:01 +00:00
(str as :string, end as :number)
(str as :string, start as :number, end as :number)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### some
2023-12-12 20:38:16 +00:00
Takes a possibly nil value and a default value. Returns the value if it's not nil, returns the default if it's nil.
```
2023-12-11 21:16:16 +00:00
(nil, default)
(value, _)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### some?
2023-12-12 20:38:16 +00:00
Returns true if a value is not nil.
```
2023-12-11 21:16:16 +00:00
(nil)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### split
Takes a string, and turns it into a list of strings, breaking on the separator.
```
(str as :string, break as :string)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-16 01:53:09 +00:00
---
### sqrt
Returns the square root of a number. Panics if the number is negative.
```
(x as :number)
```
[Back to top.](#ludus-prelude-documentation)
---
### sqrt/safe
Returns a result containing the square root of a number, or an error if the number is negative.
```
(x as :number)
```
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### square
2023-12-12 20:38:16 +00:00
Squares a number.
```
2023-12-11 21:02:17 +00:00
(x as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### state
No documentation available.
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### store!
Stores a value in a box, replacing the value that was previously there. Returns the value.
```
(b as :box, value)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### string
2024-06-15 21:04:01 +00:00
Converts a value to a string by using `show`. If it is a string, returns it unharmed. Use this to build up strings of different kinds of values.
2023-12-12 20:38:16 +00:00
```
2023-12-11 21:16:16 +00:00
(x as :string)
(x)
2024-06-15 21:04:01 +00:00
(x, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### string?
2023-12-12 20:38:16 +00:00
Returns true if a value is a string.
```
2023-12-11 21:16:16 +00:00
(x as :string)
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### strip
Removes punctuation from a string, removing all instances of ,.;:?!
```
("{x},{y}")
("{x}.{y}")
("{x};{y}")
("{x}:{y}")
("{x}?{y}")
("{x}!{y}")
(x)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### sub
2023-12-12 20:38:16 +00:00
Subtracts numbers or vectors.
```
2023-12-11 21:16:16 +00:00
()
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:16:16 +00:00
((x1, y1), (x2, y2))
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### sum_of_squares
2023-12-12 20:38:16 +00:00
Returns the sum of squares of numbers.
```
2023-12-11 21:16:16 +00:00
()
(x as :number)
(x as :number, y as :number)
2024-06-15 21:04:01 +00:00
(x, y, ...)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### tan
2023-12-12 20:38:16 +00:00
Returns the sine of an angle. Default angle measure is turns. An optional keyword argument specifies the units of the angle passed in.
```
2023-12-11 21:16:16 +00:00
(a as :number)
(a as :number, :turns)
(a as :number, :degrees)
(a as :number, :radians)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### tau
No documentation available.
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### trim
Trims whitespace from a string. Takes an optional argument, `:left` or `:right`, to trim only on the left or right.
```
(str as :string)
(str as :string, :left)
(str as :string, :right)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### tuple?
Returns true if a value is a tuple.
```
(tuple as :tuple)
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### turn/deg
2023-12-12 20:38:16 +00:00
Converts an angle in turns to an angle in degrees.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### turn/rad
2023-12-12 20:38:16 +00:00
Converts an angle in turns to an angle in radians.
```
2023-12-11 21:02:17 +00:00
(a as :number)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### turtle_commands
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### turtle_state
2023-12-12 20:38:16 +00:00
Returns the turtle's current state.
```
2023-12-11 21:02:17 +00:00
()
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### turtle_states
No documentation available.
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### type
2023-12-12 20:38:16 +00:00
Returns a keyword representing the type of the value passed in.
```
2023-12-11 21:02:17 +00:00
(x)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### unbox
Returns the value that is stored in a box.
```
(b as :box)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### unwrap!
2023-12-12 20:38:16 +00:00
Takes a result tuple. If it's :ok, then returns the value. If it's not :ok, then it panics. If it's not a result tuple, it also panics.
```
2023-12-11 21:16:16 +00:00
((:ok, value))
((:err, msg))
(_)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### unwrap_or
2023-12-12 20:38:16 +00:00
Takes a value that is a result tuple and a default value. If it's :ok, then it returns the value. If it's :err, returns the default value.
```
2023-12-11 21:16:16 +00:00
((:ok, value), _)
((:err, _), default)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### upcase
Takes a string and returns it in all uppercase. Works only for ascii characters.
```
(str as :string)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### update
2023-12-12 20:38:16 +00:00
Takes a dict, key, and function, and returns a new dict with the key set to the result of applying the function to original value held at the key.
```
2023-12-11 21:16:16 +00:00
(dict as :dict)
(dict as :dict, key as :keyword, updater as :fn)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### update!
2024-06-15 21:04:01 +00:00
Updates a box by applying a function to its value. Returns the new value.
2023-12-12 20:38:16 +00:00
```
2024-06-15 21:04:01 +00:00
(b as :box, f as :fn)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### values
2024-06-15 21:04:01 +00:00
Takes a dict and returns a list of values in that dict.
```
(dict)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### words
Takes a string and returns a list of the words in the string. Strips all whitespace.
2023-12-12 20:38:16 +00:00
```
2024-06-15 21:04:01 +00:00
(str as :string)
2023-12-11 21:02:17 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2023-12-11 21:02:17 +00:00
2024-06-15 22:14:03 +00:00
---
2024-06-15 21:04:01 +00:00
### ws?
Tells if a string is a whitespace character.
```
(" ")
("\n")
("\t")
(_)
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)
2024-06-15 21:04:01 +00:00
2024-06-15 22:14:03 +00:00
---
2023-12-11 21:02:17 +00:00
### zero?
2023-12-12 20:38:16 +00:00
Returns true if a number is 0.
```
2023-12-11 21:16:16 +00:00
(0)
(_)
2024-06-15 21:04:01 +00:00
```
2024-06-15 22:12:28 +00:00
[Back to top.](#ludus-prelude-documentation)