omdl
v0.6.1
OpenSCAD Mechanical Design Library
|
List data type operations. More...
Files | |
file | datatypes-base.scad |
Include file wrapper of data types base primitives. | |
Functions | |
function | lstr (v) |
Convert a list of values to a concatenated string. More... | |
function | lstr_html (v, b, p, a, f, d=false) |
Convert a list of values to a concatenated HTML-formatted string. More... | |
function | consts (l, v, u=false) |
Create a sequence of constant or incrementing elements. More... | |
function | get_index (l, s=true, rs) |
Create a sequence for a list index sequence specification. More... | |
function | pad (l, w, p=0, r=true) |
Pad a list to a constant width of elements. More... | |
function | dround (v, d=6) |
Round all numerical values of a list to a fixed number of decimal point digits. More... | |
function | sround (v, d=6) |
Round all numerical values of a list to a fixed number of significant figures. More... | |
function | limit (v, l, u) |
Limit all numerical values of a list between an upper and lower bounds. More... | |
function | sum (v, i1, i2) |
Compute the sum of a list of numbers. More... | |
function | mean (v) |
Compute the mean/average of a list of numbers. More... | |
function | ciselect (v, i) |
Case-like select a value from a list of ordered value options. More... | |
function | cmvselect (v, mv) |
Case-like select a value from a list of mapped key-value options. More... | |
function | eselect (v, f=true, l=false, i) |
Select a specified element from each iterable value of a list. More... | |
function | smerge (v, r=false) |
Serial-merge lists of iterable values. More... | |
function | pmerge (v, j=true) |
Parallel-merge lists of iterable values. More... | |
function | qsort (v, i, r=false) |
Sort the numeric or string elements of a list using quick sort. More... | |
function | qsort2 (v, i, d=0, r=false, s=true) |
Hierarchically sort an arbitrary data list using quick sort. More... | |
List data type operations.
See validation results.
function ciselect | ( | v | , |
i | |||
) |
Case-like select a value from a list of ordered value options.
v | <list> A list of values. |
i | <integer> Element selection index. |
i
does not map to an element.Behaves like a case statement for selecting values from a list of ordered options. The default value is: last(v)
.
Example
function cmvselect | ( | v | , |
mv | |||
) |
Case-like select a value from a list of mapped key-value options.
v | <matrix-2xN> A matrix of N key-value mapped pairs [[key, value], ...]. |
mv | <value> Element selection key match value. |
mv
. Returns the default value when mv
does not match any of the element identifiers of v
or when mv
is undefined.Behaves like a case statement for selecting values from a list of mapped options. The default value is: second(last(v))
.
Example
function consts | ( | l | , |
v | , | ||
u | = false |
||
) |
Create a sequence of constant or incrementing elements.
l | <integer> The list length. |
v | <value> The element value. |
u | <boolean> Element values are undef. |
l
copies of the element. Returns empty_lst when l
is not a number or if (l < 1)
.v
is not specified and u
is false, each element is assigned the value of its index position. function dround | ( | v | , |
d | = 6 |
||
) |
Round all numerical values of a list to a fixed number of decimal point digits.
v | <list> A list of values. |
d | <integer> The (maximum) number of decimals. |
d
decimal digits and rounded-up if the following digit is 5 or greater. Non-numeric values are unchanged. function eselect | ( | v | , |
f | = true , |
||
l | = false , |
||
i | |||
) |
Select a specified element from each iterable value of a list.
v | <list> A list of iterable values. |
f | <boolean> Select the first element. |
l | <boolean> Select the last element. |
i | <integer> Select a numeric element index position. |
v
. Returns empty_lst when v
is empty. Returns undef when v
is not defined or is not iterable.i
, l
, f
. function get_index | ( | l | , |
s | = true , |
||
rs | |||
) |
Create a sequence for a list index sequence specification.
l | <list> The list. |
s | <index> The index sequence specification. |
rs | <integer> An optional seed for random sequences. |
v
that does not fall into one of the specification forms.See Index sequence for argument specification and conventions.
function limit | ( | v | , |
l | , | ||
u | |||
) |
Limit all numerical values of a list between an upper and lower bounds.
v | <list> A list of values. |
l | <number> The minimum value. |
u | <number> The maximum value. |
[l : u]
. A value will be assigned l
when it is less than l
and u
when it is greater than u
. Non-numeric values are unchanged. function lstr | ( | v | ) |
Convert a list of values to a concatenated string.
v | <list> A list of values. |
Example
Result
function lstr_html | ( | v | , |
b | , | ||
p | , | ||
a | , | ||
f | , | ||
d | = false |
||
) |
Convert a list of values to a concatenated HTML-formatted string.
v | <list> A list of values. |
b | <tag-list-list> A list of tag lists. Unpaired HTML tag(s) to add before the value. |
p | <tag-list-list> A list of tag lists. Paired HTML tag(s) to enclose the value. |
a | <tag-list-list> A list of tag lists. Unpaired HTML tag(s) to add after the value. |
f | <attr-list-list> A list of tag attribute lists for fs , where fs=["color","size","face"] is the font tag to enclose the value. Not all attributes are required, but the order is significant. |
d | <boolean> Debug. When true angle brackets are replaced with curly brackets to prevent console decoding. |
When there are fewer tag lists in b
, p
, a
, or f
, than there are value elements in v
, the last specified tag list is used for all subsequent value elements.
For a list of the paired and unpaired HTML tags supported by the console see: HTML subset.
Example
Result
function mean | ( | v | ) |
Compute the mean/average of a list of numbers.
v | <number-list|range> A list of numerical values or a range. |
See Wikipedia for more information.
function pad | ( | l | , |
w | , | ||
p | = 0 , |
||
r | = true |
||
) |
Pad a list to a constant width of elements.
l | <list> The list. |
w | <integer> The padded width. |
p | <value> The padding value. |
r | <boolean> Use right padding (false for left). |
w
elements.When the list has greater than w
elements, the list is returned unchanged. The empty list, empty_lst, has zero elements. When l
is a string, characters are counted as individual elements. Use function lstr() to join padded values back into a single string if desired.
function pmerge | ( | v | , |
j | = true |
||
) |
Parallel-merge lists of iterable values.
v | <list> A list of iterable values. |
j | <boolean> Join each merge as a separate list. |
v
. Returns empty_lst when any element value in v
is empty. Returns undef when v
is not defined or when any element value in v
is not iterable.Example
Result
function qsort | ( | v | , |
i | , | ||
r | = false |
||
) |
Sort the numeric or string elements of a list using quick sort.
v | <number-list|string-list> A list of values. |
i | <integer> The sort column index for iterable elements. |
r | <boolean> Reverse the sort order. |
v
is not defined or is not a list.See Wikipedia for more information.
function qsort2 | ( | v | , |
i | , | ||
d | = 0 , |
||
r | = false , |
||
s | = true |
||
) |
Hierarchically sort an arbitrary data list using quick sort.
v | <data> A list of values. |
i | <integer> The sort column index for iterable elements. |
d | <integer> The recursive sort depth. |
r | <boolean> Reverse the sort order. |
s | <boolean> Order ranges by their numerical sum. |
v
is not defined or is not a list.Elements are ordered using compare(). See its documentation for a description of the parameter s
. To recursively sort all elements, set d
greater than, or equal to, the maximum level of hierarchy in v
.
See Wikipedia for more information.
function smerge | ( | v | , |
r | = false |
||
) |
Serial-merge lists of iterable values.
v | <list> A list of iterable values. |
r | <boolean> Recursively merge elements that are iterable. |
v
. Returns empty_lst when v
is empty. Returns undef when v
is not defined.function sround | ( | v | , |
d | = 6 |
||
) |
Round all numerical values of a list to a fixed number of significant figures.
v | <list> A list of values. |
d | <integer> The (maximum) number of significant figures. |
d
significant figures. Non-numeric values are unchanged.See Wikipedia for more information.
function sum | ( | v | , |
i1 | , | ||
i2 | |||
) |
Compute the sum of a list of numbers.
v | <number-list|range> A list of numerical values or a range. |
i1 | <integer> The element index at which to begin summation (first when not specified). |
i2 | <integer> The element index at which to end summation (last when not specified). |
the
list is empty. Returns undef when list non-numerical.