container_manipulation.md

July 16, 2026 ยท View on GitHub

Opcode: first

Parameters

any node

Returns

any

Description

Evaluates to the first element of node. If node is a list, it will be the first element. If node is an assoc, it will evaluate to the first element by assoc storage, but order does not matter. If node is a string, it will be the first character. If node is a number, it will evaluate to 1 if nonzero, 0 if zero.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): conditional

Examples

Example:

(first
	[4 9.2 "this"]
)

Output:

4

Example:

(first
	(associate "a" 1 "b" 2)
)

Output:

2

Example:

(first 3)

Output:

1

Example:

(first 0)

Output:

0

Example:

(first "abc")

Output:

"a"

Example:

(first "")

Output:

.null

Amalgam Opcodes

Opcode: tail

Parameters

any node [number retain_count]

Returns

list

Description

Evaluates to everything but the first element. If node is a list, it will be a list of all but the first element. If node is an assoc, it will evaluate to the assoc without the first element by assoc storage order, but order does not matter. If node is a string, it will be all but the first character. If node is a number, it will evaluate to the value minus 1 if nonzero, 0 if zero. If a retain_count is specified, it will be the number of elements to retain. A positive number means from the end, a negative number means from the beginning. The default value is -1 (all but the first element).

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): conditional

Examples

Example:

(tail
	[4 9.2 "this"]
)

Output:

[9.2 "this"]

Example:

(tail
	[1 2 3 4 5 6]
)

Output:

[2 3 4 5 6]

Example:

(tail
	[1 2 3 4 5 6]
	2
)

Output:

[5 6]

Example:

(tail
	[1 2 3 4 5 6]
	-2
)

Output:

[3 4 5 6]

Example:

(tail
	[1 2 3 4 5 6]
	-6
)

Output:

[]

Example:

(tail
	[1 2 3 4 5 6]
	6
)

Output:

[1 2 3 4 5 6]

Example:

(tail
	[1 2 3 4 5 6]
	10
)

Output:

[1 2 3 4 5 6]

Example:

(tail
	[1 2 3 4 5 6]
	-10
)

Output:

[]

Example:

(tail
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
)

Output:

{
	a 1
	b 2
	c 3
	d 4
	f 6
}

Example:

(tail
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	2
)

Output:

{b 2 c 3}

Example:

(tail
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	-2
)

Output:

{
	a 1
	b 2
	c 3
	d 4
}

Example:

(tail
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	10
)

Output:

{
	a 1
	b 2
	c 3
	d 4
	e 5
	f 6
}

Example:

(tail
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	-10
)

Output:

{}

Example:

(tail 3)

Output:

2

Example:

(tail 0)

Output:

0

Example:

(tail "abcdef")

Output:

"bcdef"

Example:

(tail "abcdef" 2)

Output:

"ef"

Example:

(tail "abcdef" -2)

Output:

"cdef"

Example:

(tail "abcdef" 6)

Output:

"abcdef"

Example:

(tail "abcdef" -6)

Output:

""

Example:

(tail "abcdef" 10)

Output:

"abcdef"

Example:

(tail "abcdef" -10)

Output:

""

Example:

(tail "")

Output:

.null

Amalgam Opcodes

Opcode: last

Parameters

any node

Returns

any

Description

Evaluates to the last element of node. If node is a list, it will be the last element. If node is an assoc, it will evaluate to the first element by assoc storage, because order does not matter. If node is a string, it will be the last character. If node is a number, it will evaluate to 1 if nonzero, 0 if zero.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): conditional

Examples

Example:

(last
	[4 9.2 "this"]
)

Output:

"this"

Example:

(last
	(associate "a" 1 "b" 2)
)

Output:

2

Example:

(last 3)

Output:

1

Example:

(last 0)

Output:

0

Example:

(last "abc")

Output:

"c"

Example:

(last "")

Output:

.null

Amalgam Opcodes

Opcode: trunc

Parameters

any node [number retain_count]

Returns

list

Description

Truncates, evaluates to everything in node but the last element. If node is a list, it will be a list of all but the last element. If node is an assoc, it will evaluate to the assoc without the first element by assoc storage order, because order does not matter. If node is a string, it will be all but the last character. If node is a number, it will evaluate to the value minus 1 if nonzero, 0 if zero. If truncate_count is specified, it will be the number of elements to retain. A positive number means from the beginning, a negative number means from the end. The default value is -1, indicating all but the last.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): conditional

Examples

Example:

(trunc
	[4 9.2 "end"]
)

Output:

[4 9.2]

Example:

(trunc
	[1 2 3 4 5 6]
)

Output:

[1 2 3 4 5]

Example:

(trunc
	[1 2 3 4 5 6]
	2
)

Output:

[1 2]

Example:

(trunc
	[1 2 3 4 5 6]
	-2
)

Output:

[1 2 3 4]

Example:

(trunc
	[1 2 3 4 5 6]
	-6
)

Output:

[]

Example:

(trunc
	[1 2 3 4 5 6]
	6
)

Output:

[1 2 3 4 5 6]

Example:

(trunc
	[1 2 3 4 5 6]
	10
)

Output:

[1 2 3 4 5 6]

Example:

(trunc
	[1 2 3 4 5 6]
	-10
)

Output:

[]

Example:

(trunc
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
)

Output:

{
	a 1
	c 3
	d 4
	e 5
	f 6
}

Example:

(trunc
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	2
)

Output:

{e 5 f 6}

Example:

(trunc
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	-2
)

Output:

{
	c 3
	d 4
	e 5
	f 6
}

Example:

(trunc
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	10
)

Output:

{
	a 1
	b 2
	c 3
	d 4
	e 5
	f 6
}

Example:

(trunc
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		"d"
		4
		"e"
		5
		"f"
		6
	)
	-10
)

Output:

{}

Example:

(trunc 3)

Output:

2

Example:

(trunc 0)

Output:

0

Example:

(trunc "abcdef")

Output:

"abcde"

Example:

(trunc "abcdef" 2)

Output:

"ab"

Example:

(trunc "abcdef" -2)

Output:

"abcd"

Example:

(trunc "abcdef" 6)

Output:

"abcdef"

Example:

(trunc "abcdef" -6)

Output:

""

Example:

(trunc "abcdef" 10)

Output:

"abcdef"

Example:

(trunc "abcdef" -10)

Output:

""

Example:

(trunc "")

Output:

.null

Amalgam Opcodes

Opcode: append

Parameters

[any collection1] [any collection2] ...

Returns

list|assoc

Description

Evaluates to a new list or assoc which merges all lists, collection1 through collectionN, based on parameter order. If any assoc is passed in, then returns an assoc (lists will be automatically converted to an assoc with the indices as keys and the list elements as values). If a non-list and non-assoc is specified, then it just adds that one element to the list. In order to append a list or assoc to the first collection, it must be wrapped in an additional layer.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): partial

Examples

Example:

(append
	[1 2 3]
	[4 5 6]
	[7 8 9]
)

Output:

[
	1
	2
	3
	4
	5
	6
	7
	8
	9
]

Example:

(append
	[1 2 3]
	(associate "a" 4 "b" 5 "c" 6)
	[7 8 9]
	(associate "d" 10 "e" 11)
)

Output:

{
	0 1
	1 2
	2 3
	3 7
	4 8
	5 9
	a 4
	b 5
	c 6
	d 10
	e 11
}

Example:

(append
	[4 9.2 "this"]
	"end"
)

Output:

[4 9.2 "this" "end"]

Example:

(append
	(associate 0 4 1 9.2 2 "this")
	"end"
)

Output:

{
	0 4
	1 9.2
	2 "this"
	3 "end"
}

Amalgam Opcodes

Opcode: size

Parameters

any collection

Returns

number

Description

Evaluates to the size of the collection in number of elements. If collection is a string, returns the length in UTF-8 characters.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): new

Examples

Example:

(size
	[4 9.2 "this"]
)

Output:

3

Example:

(size
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
)

Output:

4

Example:

(size "hello")

Output:

5

Amalgam Opcodes

Opcode: get

Parameters

any node [any|walk_path walk_path1] [any|walk_path walk_path2] ...

Returns

any

Description

Evaluates to node as traversed by the set of values specified by walk_path_1', which can be any of: a number, representing an index, with negative numbers representing backward traversal from the end of the list; a string, representing the index; or a list, representing a way to walk into the structure as the aforementioned values. If multiple walk paths are specified, then get` returns a list, where each element in the list is the respective element retrieved by the respective walk path. If the walk path continues past the data structure, it will return a null.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): existing

Examples

Example:

(get
	[4 9.2 "this"]
)

Output:

[4 9.2 "this"]

Example:

(get
	[4 9.2 "this"]
	1
)

Output:

9.2

Example:

(get
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	"c"
)

Output:

3

Example:

(get
	[
		0
		1
		2
		3
		[
			0
			1
			2
			(associate "a" 1)
		]
	]
	[4 3 "a"]
)

Output:

1

Example:

(get
	[4 9.2 "this"]
	1
	2
)

Output:

[9.2 "this"]

Example:

(seq
	(declare
		{
			var {
					A (associate "B" 2)
					B 2
				}
		}
	)
	[
		(get
			var
			["A" "B"]
		)
		(get
			var
			["A" "C"]
		)
		(get
			var
			["B" "C"]
		)
	]
)

Output:

[2 .null .null]

Example:

(get
	{.null 3}
	.null
)

Output:

3

Example:

(let
	{
		complex_assoc {
				4 "number"
				[4] "list"
				{4 4} "assoc"
				"4" "string"
			}
	}
	[
		(get complex_assoc 4)
		(get complex_assoc "4")
		(get
			complex_assoc
			[
				[4]
			]
		)
		(get
			complex_assoc
			{4 4}
		)
		(sort (indices complex_assoc))
	]
)

Output:

[
	"number"
	"string"
	"list"
	"assoc"
	[
		4
		[4]
		{4 4}
		"4"
	]
]

Amalgam Opcodes

Opcode: modify

Parameters

any node [any|walk_path walk_path1] [any|walk_path function1] [any|walk_path walk_path2] [any|walk_path function2] ...

Returns

any

Description

Performs a deep copy of node (a copy of all data structures referenced by it and its references). If any additional parameters are specified, it treats them as pairs of locations and values or functions to replace within the new copy. For each pair of replacements, the first element is any of: a number, representing an index, with negative numbers representing backward traversal from the end of the list; a string, representing the index; or a list, representing a way to walk into the structure as the aforementioned values. function1 to functionN represent a function that will be used to replace in place of whatever is in the location of the corresponding walk_path, and will be passed the current node in (current_value). The function can optionally be just be an immediate value or any code that can be evaluated. If a particular location does not exist, it will be created assuming the most generic type that will support the index (as a null, list, or assoc). Note that the (target) will evaluate to the new copy of node, which is the base of the newly constructed data; this is useful for creating circular references.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: true
  • Value newness (whether references existing node): new

Examples

Example:

(modify
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	"e"
	5
)

Output:

{
	4 "d"
	a 1
	b 2
	c 3
	e 5
}

Example:

(modify
	[0 1 2 3 4]
	2
	10
)

Output:

[0 1 10 3 4]

Example:

(modify
	(associate "a" 1 "b" 2)
	"a"
	3
)

Output:

{a 3 b 2}

Example:

(modify
	[
		(associate "a" 13)
	]
)

Output:

[
	{a 13}
]

Example:

(modify
	[
		(associate "a" 1)
	]
	[2]
	1
	[0]
	[4 5 6]
)

Output:

[
	[4 5 6]
	.null
	1
]

Example:

(modify
	[
		(associate "a" 1)
	]
	2
	1
	0
	[4 5 6]
)

Output:

[
	[4 5 6]
	.null
	1
]

Example:

(modify
	[
		(associate "a" 1)
	]
	[0]
	(lambda
		(modify (current_value) "b" 2)
	)
)

Output:

[
	{a 1 b 2}
]

Amalgam Opcodes

Opcode: indices

Parameters

list|assoc collection

Returns

list_of_numbers|list_of_strings

Description

Evaluates to the list of strings or numbers that comprise the indices for the list or associative parameter collection. It is guaranteed that the opcodes indices and values will evaluate and return elements in the same order when given the same node.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): new

Examples

Example:

(sort
	(indices
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
		)
	)
)

Output:

[4 "a" "b" "c"]

Example:

(indices
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
)

Output:

[
	0
	1
	2
	3
	4
	5
	6
	7
]

Example:

(indices
	(range 0 3)
)

Output:

[0 1 2 3]

Example:

(sort
	(indices
		(zip
			(range 0 3)
		)
	)
)

Output:

[0 1 2 3]

Example:

(sort
	(indices
		(zip
			[0 1 2 3]
		)
	)
)

Output:

[0 1 2 3]

Amalgam Opcodes

Opcode: values

Parameters

list|assoc collection [bool only_unique_values]

Returns

list

Description

Evaluates to the list of entities that comprise the values for the list or associative list collection. If only_unique_values is true (defaults to false), then it will filter out any duplicate values and only return those that are unique, preserving their order of first appearance. If only_unique_values is not true, then it is guaranteed that the opcodes indices and values will evaluate and return elements in the same order when given the same node.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): partial

Examples

Example:

(sort
	(values
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
		)
	)
)

Output:

[1 2 3 "d"]

Example:

(values
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
)

Output:

[
	"a"
	1
	"b"
	2
	"c"
	3
	4
	"d"
]

Example:

(values
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
		1
		2
		3
		4
		"a"
		"b"
		"c"
	]
	.true
)

Output:

[
	"a"
	1
	"b"
	2
	"c"
	3
	4
	"d"
]

Example:

(sort
	(values
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
			"e"
			1
		)
		.true
	)
)

Output:

[1 2 3 "d"]

Example:

(values
	(append
		(range 1 20)
		(range 1 20)
	)
	.true
)

Output:

[
	1
	2
	3
	4
	5
	6
	7
	8
	9
	10
	11
	12
	13
	14
	15
	16
	17
	18
	19
	20
]

Amalgam Opcodes

Opcode: contains_index

Parameters

list|assoc collection any|walk_path index

Returns

bool

Description

Evaluates to true if the index is in the collection interpreting index as the appropriate type for the collection.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): new

Examples

Example:

(contains_index
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	"c"
)

Output:

.true

Example:

(contains_index
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	"m"
)

Output:

.false

Example:

(contains_index
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	2
)

Output:

.true

Example:

(contains_index
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	100
)

Output:

.false

Amalgam Opcodes

Opcode: contains_value

Parameters

list|assoc collection any value

Returns

bool

Description

Evaluates to true if the value is contained in collection_or_string. If collection_or_string is a string, then it uses value as a regular expression and evaluates to true if the regular expression matches.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): new

Examples

Example:

(contains_value
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	1
)

Output:

.true

Example:

(contains_value
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	44
)

Output:

.false

Example:

(contains_value
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	"d"
)

Output:

.true

Example:

(contains_value
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	100
)

Output:

.false

Example:

(contains_value "hello world" ".*world")

Output:

.true

Example:

(contains_value "abcdefg" "a.*g")

Output:

.true

Example:

(contains_value "3.141" "[0-9]+\\.[0-9]+")

Output:

.true

Example:

(contains_value "3.141" "\\d+\\.\\d+")

Output:

.true

Example:

(contains_value "3.a141" "\\d+\\.\\d+")

Output:

.false

Example:

(contains_value "abc\r\n123" "(.|\r)*\n.*")

Output:

.true

Amalgam Opcodes

Opcode: remove

Parameters

list|assoc collection any|walk_path index

Returns

list|assoc

Description

Removes the index-value pair with index being the index in assoc or index of collection, returning a new list or assoc with index removed. If index is a list of numbers or strings, then it will remove each of the requested indices. Negative numbered indices will count back from the end of a list.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): partial

Examples

Example:

(sort
	(remove
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
		)
		4
	)
)

Output:

[1 2 3]

Example:

(remove
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	4
)

Output:

[
	"a"
	1
	"b"
	2
	3
	4
	"d"
]

Example:

(sort
	(remove
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
		)
		[4 "a"]
	)
)

Output:

[2 3]

Example:

(remove
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	[4]
)

Output:

[
	"a"
	1
	"b"
	2
	3
	4
	"d"
]

Example:

(remove
	[0 1 2 3 4 5]
	[0 2]
)

Output:

[1 3 4 5]

Example:

(remove
	[0 1 2 3 4 5]
	-1
)

Output:

[0 1 2 3 4]

Example:

(remove
	[0 1 2 3 4 5]
	[0 -1]
)

Output:

[1 2 3 4]

Example:

(remove
	[0 1 2 3 4 5]
	[
		5
		0
		1
		2
		3
		4
		5
		6
	]
)

Output:

[]

Amalgam Opcodes

Opcode: keep

Parameters

list|assoc collection any index

Returns

list|assoc

Description

Keeps only the index-value pair with index being the index in collection, returning a new list or assoc with only that index. If index is a list of numbers or strings, then it will only keep those requested indices. Negative numbered indices will count back from the end of a list.

Details

  • Permissions required: none
  • Allows concurrency: false
  • Requires entity: false
  • Creates new scope: false
  • Creates new target scope: false
  • Value newness (whether references existing node): partial

Examples

Example:

(keep
	(associate
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	)
	4
)

Output:

{4 "d"}

Example:

(keep
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	4
)

Output:

["c"]

Example:

(sort
	(keep
		(associate
			"a"
			1
			"b"
			2
			"c"
			3
			4
			"d"
		)
		[4 "a"]
	)
)

Output:

[1 "d"]

Example:

(keep
	[
		"a"
		1
		"b"
		2
		"c"
		3
		4
		"d"
	]
	[4 "a"]
)

Output:

["c"]

Example:

(keep
	[0 1 2 3 4 5]
	[0 2]
)

Output:

[0 2]

Example:

(keep
	[0 1 2 3 4 5]
	-1
)

Output:

[5]

Example:

(keep
	[0 1 2 3 4 5]
	[0 -1]
)

Output:

[0 5]

Example:

(keep
	[0 1 2 3 4 5]
	[
		5
		0
		1
		2
		3
		4
		5
		6
	]
)

Output:

[0 1 2 3 4 5]

Amalgam Opcodes