Opcode: total_size

Parameters

any node

Returns

number

Description

Evaluates to the total count of all of the nodes referenced directly or indirectly by 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:

    (total_size
     [
         1
         2
         3
         (associate "a" 3 "b" 4)
         [5 6]
     ]
    )
    

    Output:

    10
    

Amalgam Opcodes

Opcode: mutate

Parameters

any node [number mutation_rate] [assoc mutation_weights] [assoc operation_type] [number preserve_type_depth] [assoc immediate_number_weights] [assoc immediate_string_weights]

Returns

any

Description

Evaluates to a mutated version of node. The mutation_rate can range from 0.0 to 1.0 and defaulting to 0.0001, and indicates the probability that any node will experience a mutation. The parameter mutation_weights is an assoc where the keys are the allowed opcode names and the values are the probabilities that each opcode would be chosen; if null or unspecified, it defaults to all opcodes each with their own default probability. The parameter operation_type is an assoc where the keys are mutation operations and the values are the probabilities that the operations will be performed. The operations can consist of the strings “change_type”, “insert”, “remove”, “simplify_node”, “insert_element”, “remove_element”, “replace_element_with_copy”, “swap_elements”, and “remove_all_elements”. If preserve_type_depth is specified, it will retain the types of node down to and including whatever depth is specified, and defaults to 0 indicating that none of the structure needs to be preserved. If immediate_number_weights is specified, each number value as a key will have that probability specified in its value of being chosen when a node is mutated to a number, with the null key representing the probability default behavior of exponential perturbation of the numeric value. The parameter immediate_string_weights behaves similarly to immediate_number_weights, with its null key representing the default behavior of an even split between randomly choosing existing strings in the tree and generating new random strings.

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:

    (mutate
     (lambda
         [
             1
             2
             3
             4
             5
             6
             7
             8
             9
             10
             11
             12
             13
             14
             (associate "a" 1 "b" 2)
         ]
     )
     0.4
    )
    

    Output:

    [
     1
     (and)
     3
     {}
     5
     6
     (tail)
     (get)
     (acos)
     (floor)
     (let)
     12
     zbiqZH
     14
     (associate .null)
    ]
    

    Example:

    (mutate
     (lambda
         [
             1
             2
             3
             4
             (associate "alpha" 5 "beta" 6)
             (associate
                 "nest"
                 (associate
                     "count"
                     [7 8 9]
                 )
                 "end"
                 [10 11 12]
             )
         ]
     )
     0.2
     (associate "+" 0.5 "-" 0.3 "*" 0.2)
     (associate "change_type" 0.08 "delete" 0.02 "insert" 0.9)
    )
    

    Output:

    [
     1
     (-)
     3
     (-)
     (associate "alpha" 5 (+) 6)
     (associate
         "nest"
         (associate
             "count"
             [(*) 8 9]
         )
         "end"
         [(*) 11 12]
     )
    ]
    

    Example:

    (mutate
     (lambda
         [
             1
             2
             "c"
             4
             5
             6
             7
             "g"
             9
             10
             11
             12
             "l"
             14
             (associate "a" 1 "b" 2)
         ]
     )
     0.91
     .null
     .null
     1
     {
         101 0.25
         201 0.25
         301 0.25
         .null 0.25
     }
     {
         "x" 0.5
         "y" 0.5
     }
    )
    

    Output:

    [
         1.7100924132216468
         201
         "x"
         4
         101
         .null
         101
         "x"
         101
         201
         101
         201
         "x"
         .null
         x
    ]
    

    Example:

    (get_type_string (mutate (lambda (+ 1 2)) 1.0 .null {"simplify_node" 1}))
    

    Output:

    "number"
    

Amalgam Opcodes

Opcode: get_mutation_defaults

Parameters

string value_type

Returns

any

Description

Retrieves the default values of value_type for mutation, either “mutation_opcodes” or “mutation_types”

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:

    (get_mutation_defaults "mutation_types")
    

    Output:

    {
         change_type 0.15
         insert 0.14
         insert_element 0.14
         remove 0.14
         remove_all_elements 0.0001
         remove_element 0.14
         replace_element_with_copy 0.0999
         simplify_node 0.05
         swap_elements 0.14
    }
    

Amalgam Opcodes

Opcode: commonality

Parameters

any node1 any node2 [assoc params]

Returns

number

Description

Evaluates to the total count of all of the nodes referenced within node1 and node2 that are equivalent. The assoc params can contain the keys “string_edit_distance”, “types_must_match”, “nominal_numbers”, “nominal_strings”, and “recursive_matching”. If the key “string_edit_distance” is true (default is false), it will assume node1 and node2 as string literals and compute via string edit distance. If the key “types_must_match” is true (the default), it will only consider nodes common if the types match. If the key “nominal_numbers” is true (the default is false), then it will assume that all numbers will match only if identical; if false, it will compare similarity of values. The key “nominal_strings” defaults to true, but works similar to “nominal_numbers” except on strings using string edit distance. If the key “recursive_matching” is true or null, then it will attempt to recursively match any part of the data structure of node1 to node2. If the key “recursive_matching” is false, then it will only attempt to merge the two at the same level, which yield better results if the data structures are common, and additionally will be much faster.

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:

    (commonality
     (lambda
         (seq 2 (get_entity_comments) 1)
     )
     (lambda
         (seq 2 1 4 (get_entity_comments))
     )
    )
    

    Output:

    3
    

    Example:

    (commonality
     [
         1
         2
         3
         (associate "a" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
     [
         1
         2
         3
         (associate "c" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
    )
    

    Output:

    15
    

    Example:

    (commonality .infinity 3)
    

    Output:

    0.125
    

    Example:

    (commonality
     .null
     3
     {types_must_match .false}
    )
    

    Output:

    0.125
    

    Example:

    (commonality .infinity .infinity)
    

    Output:

    1
    

    Example:

    (commonality .infinity -.infinity)
    

    Output:

    0.125
    

    Example:

    (commonality "hello" "hello")
    

    Output:

    1
    

    Example:

    (commonality
     "hello"
     "hello"
     {string_edit_distance .true}
    )
    

    Output:

    5
    

    Example:

    (commonality
     "hello"
     "el"
     {nominal_strings .false}
    )
    

    Output:

    0.583096267567592
    

    Example:

    (commonality
     "hello"
     "el"
     {string_edit_distance .true}
    )
    

    Output:

    2
    

    Example:

    (commonality
     "el"
     "hello"
     {string_edit_distance .true}
    )
    

    Output:

    2
    

    Example:

    (commonality
     (lambda
         {a 1 b 2 c 3}
     )
     (lambda
         (if
             x
             {a 1 b 2 c 3}
             .false
         )
     )
    )
    

    Output:

    4
    

    Example:

    (commonality
     [1 2 3]
     [
         [1 2 3]
     ]
    )
    

    Output:

    4
    

    Example:

    (commonality
     [1 2 3]
     (unordered_list 1 2 3)
     {types_must_match .false}
    )
    

    Output:

    3.5
    

    Example:

    (commonality (lambda (- a b)) (lambda (- b)))
    

    Output:

    2
    

Amalgam Opcodes

Opcode: edit_distance

Parameters

any node1 any node2 [assoc params]

Returns

number

Description

Evaluates to the number of nodes that are different between node1 and node2. The assoc params can contain the keys “string_edit_distance”, “types_must_match”, “nominal_numbers”, “nominal_strings”, and “recursive_matching”. If the key “string_edit_distance” is true (default is false), it will assume node1 and node2 as string literals and compute via string edit distance. If the key “types_must_match” is true (the default), it will only consider nodes common if the types match. If the key “nominal_numbers” is true (the default is false), then it will assume that all numbers will match only if identical; if false, it will compare similarity of values. The key “nominal_strings” defaults to true, but works similar to “nominal_numbers” except on strings using string edit distance. If the key “recursive_matching” is true or null, then it will attempt to recursively match any part of the data structure of node1 to node2. If the key “recursive_matching” is false, then it will only attempt to merge the two at the same level, which yield better results if the data structures are common, and additionally will be much faster.

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:

    (edit_distance
     (lambda
         (seq 2 (get_entity_comments) 1)
     )
     (lambda
         (seq 2 1 4 (get_entity_comments))
     )
    )
    

    Output:

    3
    

    Example:

    (edit_distance
     [
         1
         2
         3
         (associate "a" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
     [
         1
         2
         3
         (associate "c" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
    )
    

    Output:

    2
    

    Example:

    (edit_distance "hello" "hello")
    

    Output:

    0
    

    Example:

    (edit_distance
     "hello"
     "hello"
     {string_edit_distance .true}
    )
    

    Output:

    0
    

    Example:

    (edit_distance
     "hello"
     "el"
     {nominal_strings .false}
    )
    

    Output:

    0.8338074648648159
    

    Example:

    (edit_distance
     "hello"
     "el"
     {string_edit_distance .true}
    )
    

    Output:

    3
    

    Example:

    (edit_distance
     "el"
     "hello"
     {string_edit_distance .true}
    )
    

    Output:

    3
    

    Example:

    (edit_distance
     [1 2 3]
     (lambda
         (unordered_list
             [1 2 3]
         )
     )
    )
    

    Output:

    1
    

Amalgam Opcodes

Opcode: intersect

Parameters

any node1 any node2 [assoc params]

Returns

any

Description

Evaluates to whatever is common between node1 and node2 exclusive. The assoc params can contain the keys “types_must_match”, “nominal_numbers”, “nominal_strings”, and “recursive_matching”. If the key “types_must_match” is true (the default), it will only consider nodes common if the types match. If the key “nominal_numbers” is true, the default, then it will assume that all numbers will match only if identical; if false, it will compare similarity of values. The key “nominal_strings” defaults to true, but works similar to “nominal_numbers” except on strings using string edit distance. If the key “recursive_matching” is true or null, then it will attempt to recursively match any part of the data structure of node1 to node2. If the key “recursive_matching” is false, then it will only attempt to merge the two at the same level, which yield better results if the data structures are common, and additionally will be much faster.

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:

    (intersect
     [
         1
         (lambda
             (- 4 2)
         )
         (associate "a" 3 "b" 4)
     ]
     [
         1
         (lambda
             (- 4 2)
         )
         (associate "c" 3 "b" 4)
     ]
    )
    

    Output:

    [
     1
     (- 4 2)
     {b 4}
    ]
    

    Example:

    (intersect
     (lambda
         (seq 2 (get_entity_comments) 1)
     )
     (lambda
         (seq 2 1 4 (get_entity_comments))
     )
    )
    

    Output:

    (seq 2 1)
    

    Example:

    (intersect
     (lambda
         (unordered_list (get_entity_comments) 1 2)
     )
     (lambda
         (unordered_list (get_entity_comments) 1 2 4)
     )
    )
    

    Output:

    (unordered_list (get_entity_comments) 1 2)
    

    Example:

    (intersect
     [
         1
         2
         3
         (associate "a" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
     [
         1
         2
         3
         (associate "c" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
    )
    

    Output:

    [
     1
     2
     3
     {b 4}
     (if
         true
         1
         (unordered_list (get_entity_comments) 1)
     )
     [5 6]
    ]
    

    Example:

    (intersect
     (lambda
         [
             1
             (associate "a" 3 "b" 4)
         ]
     )
     (lambda
         [
             1
             (associate "c" 3 "b" 4)
         ]
     )
    )
    

    Output:

    [
     1
     (associate .null 3 "b" 4)
    ]
    

    Example:

    (intersect
     (lambda
         (modify 4 2 6 1 7)
     )
     (lambda
         (modify 4 1 7 2 6)
     )
    )
    

    Output:

    (modify 4 2 6 1 7)
    

    Example:

    (unparse
     (intersect
         (lambda
             [
    				
                 ;comment 1
                 ;comment 2
                 ;comment 3
                 1
                 3
                 5
                 7
                 9
                 11
                 13
             ]
         )
         (lambda
             [
    				
                 ;comment 2
                 ;comment 3
                 ;comment 4
                 1
                 4
                 6
                 8
                 10
                 12
                 14
             ]
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "[
    	
     ;comment 2
     ;comment 3
     1
    ]
    "
    

    Example:

    (intersect
     [1 2 3]
     [
         [1 2 3]
     ]
    )
    

    Output:

    [1 2 3]
    

    Example:

    (intersect
     [1 2 3]
     [
         [1 2 3]
     ]
     {recursive_matching .false}
    )
    

    Output:

    []
    

Amalgam Opcodes

Opcode: union

Parameters

any node1 any node2 [assoc params]

Returns

any

Description

Evaluates to whatever is inclusive when merging node1 and node2. The assoc params can contain the keys “types_must_match”, “nominal_numbers”, “nominal_strings”, and “recursive_matching”. If the key “types_must_match” is true (the default), it will only consider nodes common if the types match. If the key “nominal_numbers” is true, the default, then it will assume that all numbers will match only if identical; if false, it will compare similarity of values. The key “nominal_strings” defaults to true, but works similar to “nominal_numbers” except on strings using string edit distance. If the key “recursive_matching” is true or null, then it will attempt to recursively match any part of the data structure of node1 to node2. If the key “recursive_matching” is false, then it will only attempt to merge the two at the same level, which yield better results if the data structures are common, and additionally will be much faster.

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:

    (union
     (lambda
         (seq 2 (get_entity_comments) 1)
     )
     (lambda
         (seq 2 1 4 (get_entity_comments))
     )
    )
    

    Output:

    (seq 2 (get_entity_comments) 1 4 (get_entity_comments))
    

    Example:

    (union
     [
         1
         (lambda
             (- 4 2)
         )
         (associate "a" 3 "b" 4)
     ]
     [
         1
         (lambda
             (- 4 2)
         )
         (associate "c" 3 "b" 4)
     ]
    )
    

    Output:

    [
     1
     (- 4 2)
     {a 3 b 4 c 3}
    ]
    

    Example:

    (union
     (lambda
         (unordered_list (get_entity_comments) 1 2)
     )
     (lambda
         (unordered_list (get_entity_comments) 1 2 4)
     )
    )
    

    Output:

    (unordered_list (get_entity_comments) 1 2 4)
    

    Example:

    (union
     [
         1
         2
         3
         (associate "a" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
     [
         1
         2
         3
         (associate "c" 3 "b" 4)
         (lambda
             (if
                 true
                 1
                 (unordered_list (get_entity_comments) 1)
             )
         )
         [5 6]
     ]
    )
    

    Output:

    [
     1
     2
     3
     {a 3 b 4 c 3}
     (if
         true
         1
         (unordered_list (get_entity_comments) 1)
     )
     [5 6]
    ]
    

    Example:

    (union
     (lambda
         [
             1
             (associate "a" 3 "b" 4)
         ]
     )
     (lambda
         [
             1
             (associate "c" 3 "b" 4)
         ]
     )
    )
    

    Output:

    [
     1
     (associate .null 3 "b" 4)
    ]
    

    Example:

    (union
     [3 2]
     [3 4]
    )
    

    Output:

    [3 4 2]
    

    Example:

    (union
     [2 3]
     [3 2 4]
    )
    

    Output:

    [3 2 4 3]
    

    Example:

    (unparse
     (union
         (lambda
             [
    				
                 ;comment 1
                 ;comment 2
                 ;comment 3
                 1
                 2
                 3
                 5
                 7
                 9
                 11
                 13
             ]
         )
         (lambda
             [
    				
                 ;comment 2
                 ;comment 3
                 ;comment 4
                 1
    				
                 ;comment x
                 2
                 4
                 6
                 8
                 10
                 12
                 14
             ]
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "[
    	
     ;comment 1
     ;comment 2
     ;comment 3
     ;comment 4
     1
    	
     ;comment x
     2
     4
     3
     6
     5
     8
     7
     10
     9
     12
     11
     14
     13
    ]
    "
    

    Example:

    (union
     [1 2 3]
     [
         [1 2 3]
     ]
    )
    

    Output:

    [
     [1 2 3]
    ]
    

    Example:

    (union
     [
         [1 2 3]
     ]
     [1 2 3]
    )
    

    Output:

    [
     [1 2 3]
    ]
    

    Example:

    (union
     [1 2 3]
     (lambda
         [
             [1 2 3]
         ]
     )
    )
    

    Output:

    [
     [1 2 3]
    ]
    

    Example:

    (union
     [1 2 3]
     (lambda
         [
             [1 2 3]
         ]
     )
     {recursive_matching .false}
    )
    

    Output:

    [
     1
     2
     3
     [1 2 3]
    ]
    

    Example:

    (union (lambda (+ a b)) (lambda (+ b)))
    

    Output:

    (+ a b)
    

    Example:

    (union (lambda (- a b)) (lambda (- b)))
    

    Output:

    (- a b)
    

Amalgam Opcodes

Opcode: difference

Parameters

any node1 any node2

Returns

any

Description

Finds the difference between node1 and node2, and generates code that, if evaluated passing node1 as its parameter “_”, would turn it into node2. Useful for finding a small difference of what needs to be changed to apply it to new (and possibly slightly different) data or code.

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:

    (difference
     (lambda
         {
             a 1
             b 2
             c 4
             d 7
             e 10
             f 12
             g 13
         }
     )
     (lambda
         [
             a
             2
             c
             4
             d
             6
             q
             8
             e
             10
             f
             12
             g
             14
         ]
     )
    )
    

    Output:

    (declare
     {_ .null}
     (modify
         _
         []
         (lambda
             [
                 a
                 2
                 c
                 4
                 d
                 6
                 q
                 8
                 e
                 10
                 f
                 12
                 g
                 14
             ]
         )
     )
    )
    

    Example:

    (difference
     {
         a 1
         b 2
         c 4
         d 7
         e 10
         f 12
         g 13
     }
     {
         a 2
         c 4
         d 6
         e 10
         f 12
         g 14
         q 8
     }
    )
    

    Output:

    (declare
     {_ .null}
     (modify
         _
         []
         (lambda
             {
                 a 2
                 c (get
                         (current_value 1)
                         "c"
                     )
                 d 6
                 e (get
                         (current_value 1)
                         "e"
                     )
                 f (get
                         (current_value 1)
                         "f"
                     )
                 g 14
                 q 8
             }
         )
     )
    )
    

    Example:

    (difference
     (lambda
         [
             1
             2
             4
             7
             10
             12
             13
         ]
     )
     (lambda
         [
             2
             4
             6
             8
             10
             12
             14
         ]
     )
    )
    

    Output:

    (declare
     {_ .null}
     (modify
         _
         []
         (lambda
             [
                 (get
                     (current_value 1)
                     1
                 )
                 (get
                     (current_value 1)
                     2
                 )
                 6
                 8
                 (get
                     (current_value 1)
                     4
                 )
                 (get
                     (current_value 1)
                     5
                 )
                 14
             ]
         )
     )
    )
    

    Example:

    (unparse
     (difference
         (lambda
             {
                 a 1
                 b 2
                 c 4
                 d 7
                 e 10
                 f 12
                 g 13
             }
         )
         (lambda
             {
                 a 2
                 c 4
                 d 6
                 e 10
                 f 12
                 g 14
                 q 8
             }
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "(declare
     {_ .null}
     (modify
         _
         []
         (lambda
             {
                 a 2
                 c (get
                         (current_value 1)
                         \"c\"
                     )
                 d 6
                 e (get
                         (current_value 1)
                         \"e\"
                     )
                 f (get
                         (current_value 1)
                         \"f\"
                     )
                 g 14
                 q 8
             }
         )
     )
    )
    "
    

    Example:

    (unparse
     (difference
         (lambda
             (associate
                 a
                 1
                 g
                 [1 2]
             )
         )
         (lambda
             (associate
                 a
                 2
                 g
                 [1 4]
             )
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "(declare
     {_ .null}
     (modify
         _
         [3]
         (lambda
             [
                 (get
                     (current_value 1)
                     0
                 )
                 4
             ]
         )
         []
         (lambda
             (set_type
                 [
                     a
                     2
                     g
                     (get
                         (current_value 1)
                         3
                     )
                 ]
                 \"associate\"
             )
         )
     )
    )
    "
    

    Example:

    (unparse
     (difference
         (zip
             [1 2 3 4 5]
         )
         (append
             (zip
                 [2 6 5]
             )
             {a 1}
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "(declare
     {_ .null}
     (modify
         _
         []
         (lambda
             {
                 2 .null
                 5 .null
                 6 .null
                 a 1
             }
         )
     )
    )
    "
    

    Example:

    (unparse
     (difference
         (zip
             [1 2 3 4 5]
         )
         (zip
             [2 6 5]
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "(declare
     {_ .null}
     (modify
         _
         []
         (lambda
             {2 .null 5 .null 6 .null}
         )
     )
    )
    "
    

    Example:

    (unparse
     (difference
         (zip
             [1 2 5]
         )
         (zip
             [2 6 5]
         )
     )
     .true
     .true
     .true
    )
    

    Output:

    "(declare
     {_ .null}
     (modify
         _
         []
         (lambda
             {2 .null 5 .null 6 .null}
         )
     )
    )
    "
    

    Example:

    (let
     {
         x (lambda
                 [
                     6
                     [1 2]
                 ]
             )
         y (lambda
                 [
                     7
                     [1 4]
                 ]
             )
     }
     (call
         (difference x y)
         {_ x}
     )
    )
    

    Output:

    [
     7
     [1 4]
    ]
    

    Example:

    (let
     {
         x (lambda
                 [
                     (+ 0 1)
                     [1 2]
                 ]
             )
         y (lambda
                 [
                     (+ 7 8)
                     [1 4]
                 ]
             )
     }
     (call
         (difference x y)
         {_ x}
     )
    )
    

    Output:

    [
     (+ 7 8)
     [1 4]
    ]
    

    Example:

    (let
     {
         x (lambda
                 [
                     6
                     [
                         ["a" "b"]
                         1
                         2
                     ]
                 ]
             )
         y (lambda
                 [
                     7
                     [
                         ["a" "x"]
                         1
                         4
                     ]
                 ]
             )
     }
     (call
         (difference x y)
         {_ x}
     )
    )
    

    Output:

    [
     7
     [
         ["a" "x"]
         1
         4
     ]
    ]
    

Amalgam Opcodes

Opcode: mix

Parameters

any node1 any node2 [number keep_chance_node1] [number keep_chance_node2] [assoc params]

Returns

any

Description

Performs a union operation on node1 and node2, but randomly ignores nodes from one or the other if the nodes are not equal. If only keep_chance_node1 is specified, keep_chance_node2 defaults to 1 - keep_chance_node1. keep_chance_node1 specifies the probability that a node from node1 will be kept, and keep_chance_node2 the probability that a node from node2 will be kept. keep_chance_node1 + keep_chance_node2 should be between 1 and 2, as there are two objects being merged, otherwise the values will be normalized. params can contain the keys “types_must_match”, “nominal_numbers”, “nominal_strings”, “recursive_matching”, and “similar_mix_chance”. If the key “types_must_match” is true (the default), it will only consider nodes common if the types match. If the key “nominal_numbers” is true (the default is false), then it will assume that all numbers will match only if identical; if false, it will compare similarity of values. The key “nominal_strings” defaults to true, but works similar to “nominal_numbers” except on strings using string edit distance. If the key “recursive_matching” is true or null, then it will attempt to recursively match any part of the data structure of node1 to node2. If the key “recursive_matching” is false, then it will only attempt to merge the two at the same level, which yield better results if the data structures are common, and additionally will be much faster. “similar_mix_chance” is the additional probability that two nodes will mix if they have some commonality, which will include interpolating number and string values based on keep_chance_node1 and keep_chance_node2, and defaults to 0.0. If “similar_mix_chance” is negative, then 1 minus the value will be anded with the commonality probability, so -1 means that it will never mix and 0 means it will only mix when sufficiently common.

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:

    (mix
     (lambda
         [
             1
             3
             5
             7
             9
             11
             13
         ]
     )
     (lambda
         [
             2
             4
             6
             8
             10
             12
             14
         ]
     )
     0.5
     0.5
     0
    )
    

    Output:

    [1 3 4 9 11 14]
    

    Example:

    (mix
     (lambda
         [
    	
             ;comment 1
             ;comment 2
             ;comment 3
             1
             3
             5
             7
             9
             11
             13
         ]
     )
     (lambda
         [
    			
             ;comment 2
             ;comment 3
             ;comment 4
             1
             4
             6
             8
             10
             12
             14
         ]
     )
     0.5
     0.5
     {similar_mix_chance 0}
    )
    

    Output:

    [
    	
     ;comment 1
     ;comment 2
     ;comment 3
     ;comment 4
     1
     4
     3
     5
     9
     11
     14
    ]
    

    Example:

    (mix
     (lambda
         [
             1
             2
             (associate "a" 3 "b" 4)
             (lambda
                 (if
                     true
                     1
                     (unordered_list (get_entity_comments) 1)
                 )
             )
             [5 6]
         ]
     )
     (lambda
         [
             1
             5
             3
             (associate "a" 3 "b" 4)
             (lambda
                 (if
                     false
                     1
                     (unordered_list
                         (get_entity_comments)
                         (lambda
                             [2 9]
                         )
                     )
                 )
             )
         ]
     )
     0.8
     0.8
     {similar_mix_chance 0.5}
    )
    

    Output:

    [
     1
     5
     3
     (associate "a" 3 "b" 4)
     (lambda
         (if
             true
             1
             (unordered_list
                 (get_entity_comments)
                 (lambda
                     [2 9]
                 )
             )
         )
     )
     [5]
    ]
    

    Example:

    (mix
     (lambda
         [
             1
             2
             (associate "a" 3 "b" 4)
             (lambda
                 (if
                     true
                     1
                     (unordered_list (get_entity_comments) 1)
                 )
             )
             [5 6]
         ]
     )
     (lambda
         [
             1
             5
             3
             {a 3 b 4}
             (lambda
                 (if
                     false
                     1
                     (seq
                         (get_entity_comments)
                         (lambda
                             [2 9]
                         )
                     )
                 )
             )
         ]
     )
     0.8
     0.8
     {similar_mix_chance 1}
    )
    

    Output:

    [
     1
     2.5
     {a 3 b 4}
     (associate "a" 3 "b" 4)
     (lambda
         (if
             true
             1
             (seq
                 (get_entity_comments)
                 (lambda
                     [2 9]
                 )
             )
         )
     )
     [5]
    ]
    

    Example:

    (mix
     (lambda
         [
             .true
             3
             5
             7
             9
             11
             13
         ]
     )
     (lambda
         [
             2
             4
             6
             8
             10
             12
             14
         ]
     )
     0.5
     0.5
     {similar_mix_chance 1}
    )
    

    Output:

    [
     .true
     3
     5
     7.5
     9.5
     11.5
     13.5
    ]
    

    Example:

    (mix
     (lambda
         [
             .true
             3
             5
             7
             9
             11
             13
         ]
     )
     (lambda
         [
             2
             4
             6
             8
             10
             12
             14
         ]
     )
     0.5
     0.5
     {similar_mix_chance -1}
    )
    

    Output:

    [3 5 2 4 12 11]
    

    Example:

    (mix
     1
     4
     0.5
     0.5
     {similar_mix_chance -1}
    )
    

    Output:

    4
    

    Example:

    (mix
     1
     4
     0.5
     0.5
     {similar_mix_chance -0.8}
    )
    

    Output:

    4
    

    Example:

    (mix
     1
     4
     0.5
     0.5
     {similar_mix_chance 0.5}
    )
    

    Output:

    1
    

    Example:

    (mix
     1
     4
     0.5
     0.5
     {similar_mix_chance 1}
    )
    

    Output:

    2.5
    

    Example:

    (mix
     "abcdexyz"
     "abcomxyz"
     0.5
     0.5
     {nominal_strings .false similar_mix_chance 0.5}
    )
    

    Output:

    "abcdexyz"
    

    Example:

    (mix
     "abcdexyz"
     "abcomxyz"
     0.5
     0.5
     {nominal_strings .false similar_mix_chance 0.5}
    )
    

    Output:

    "abcdexyz"
    

    Example:

    (mix
     "abcdexyz"
     "abcomxyz"
     0.5
     0.5
     {nominal_strings .false similar_mix_chance 0.5}
    )
    

    Output:

    "abcdexyz"
    

    Example:

    (mix
     {
         a [0 1]
         b [1 2]
         c [2 3]
     }
     {
         a [0 1]
         b [1 2]
         w [2 3]
         x [3 4]
         y [4 5]
         z [5 6]
     }
     0.5
     0.5
     {recursive_matching .false}
    )
    

    Output:

    {
     a [0 1]
     b [1 2]
     w [2]
     z [5]
    }
    

Amalgam Opcodes

Opcode: simplify

Parameters

any code

Returns

any

Description

Simplifies code in basic ways that will yield the same behavior and return the same result. Note that values from boolean logic may not necessarily be preserved, with the opcodes “and” and “or” potentially returning just true or false.

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:

    (simplify
     (lambda
         (+
             0
             1
             2
             3
             4
             5
             6
         )
     )
    )
    

    Output:

    21
    

    Example:

    (simplify
     (lambda
         (if
             a (if .false 1 .true 2 c)
             b (if 3)
             .false 3
             4			
         )
     )
    )
    

    Output:

    (if a 2 b 3 4)
    

    Example:

    (simplify (lambda (if)))
    

    Output:

    .null
    

    Example:

    (simplify (lambda (if .false 1)))
    

    Output:

    .null
    

    Example:

    (simplify
     (lambda
         (and a .true b (or .false c d))
     )
    )
    

    Output:

    (and
         (or c d)
         a
         b
    )
    

    Example:

    (simplify
     (lambda
         (concat "h" "e" l l "o" " " "w" o r l "d" "!")
     )
    )
    

    Output:

    (concat
         "he"
         l
         l
         "o w"
         o
         r
         l
         "d!"
    )
    

    Example:

    (simplify
     (lambda
         (+ (exp a) a 4 2 (+ 3 4 a) (+ 3 a 4) a (exp a))
     )
    )
    

    Output:

    (+
         (*
                 (exp a)
                 2
         )
         (* 4 a)
         20
    )
    

    Example:

    (simplify (lambda (-)))
    

    Output:

    .null
    

    Example:

    (simplify (lambda (- a)))
    

    Output:

    (- a)
    

    Example:

    (simplify (lambda (- 5 a)))
    

    Output:

    (- 5 a)
    

    Example:

    (simplify (lambda (- a 0)))
    

    Output:

    a
    

    Example:

    (call (simplify (lambda (- a 0))) {a -0})
    

    Output:

    -0
    

    Example:

    (simplify (lambda (- a -0)))
    

    Output:

    (- a -0)
    

    Example:

    (call (simplify (lambda (- a 0))) {a "2"})
    

    Output:

    "2"
    

    Example:

    (simplify (lambda (- b a a 1)))
    

    Output:

    (-
     b
     (* 2 a)
     1
    )
    

    Example:

    (simplify (lambda (- a a)))
    

    Output:

    (- a a)
    

    Example:

    (call (simplify (lambda (- a a))) {a .infinity})
    

    Output:

    .null
    

    Example:

    (call (simplify (lambda (- a a))) {a .null})
    

    Output:

    .null
    

    Example:

    (simplify (lambda (- a a a)))
    

    Output:

    (-
     a
     (* 2 a)
    )
    

    Example:

    (call (simplify (lambda (- a a a))) {a 2})
    

    Output:

    -2
    

    Example:

    (call (simplify (lambda (- a a a))) {a .infinity})
    

    Output:

    .null
    

    Example:

    (call (simplify (lambda (- a a a a))) {a 2})
    

    Output:

    -4
    

    Example:

    (call (simplify (lambda (- a a b))) {a 2 b 3})
    

    Output:

    -3
    

    Example:

    (call (simplify (lambda (- a a 5 b))) {a 2 b 3})
    

    Output:

    -8
    

    Example:

    (simplify (lambda (- a 5 -2)))
    

    Output:

    (- a 3)
    

    Example:

    (simplify (lambda (- 10 2 3)))
    

    Output:

    5
    

    Example:

    (simplify (lambda (- a 2 0)))
    

    Output:

    (- a 2)
    

    Example:

    (simplify (lambda (- a .null b)))
    

    Output:

    .null
    

    Example:

    (simplify
     (lambda
         (* b a a 1 b 3)
     )
    )
    

    Output:

    (*
         (pow a 2)
         (pow b 2)
         3
    )
    

    Example:

    (simplify (lambda (/)))
    

    Output:

    .null
    

    Example:

    (simplify (lambda (/ a)))
    

    Output:

    (/ a)
    

    Example:

    (simplify (lambda (/ a 2)))
    

    Output:

    (/ a 2)
    

    Example:

    (simplify (lambda (/ 6 a)))
    

    Output:

    (/ 6 a)
    

    Example:

    (simplify (lambda (/ a 1)))
    

    Output:

    a
    

    Example:

    (call (simplify (lambda (/ a 1))) {a -0})
    

    Output:

    -0
    

    Example:

    (call (simplify (lambda (/ a 1))) {a "2"})
    

    Output:

    "2"
    

    Example:

    (simplify (lambda (/ b a a 1 3 a)))
    

    Output:

    (/
     b
     (pow a 3)
     3
    )
    

    Example:

    (simplify (lambda (/ a a)))
    

    Output:

    (/ a a)
    

    Example:

    (call (simplify (lambda (/ a a))) {a 0})
    

    Output:

    .null
    

    Example:

    (call (simplify (lambda (/ a a))) {a .infinity})
    

    Output:

    .null
    

    Example:

    (simplify (lambda (/ a a a)))
    

    Output:

    (/
     a
     (pow a 2)
    )
    

    Example:

    (call (simplify (lambda (/ a a a))) {a 2})
    

    Output:

    0.5
    

    Example:

    (call (simplify (lambda (/ a a a))) {a .infinity})
    

    Output:

    .null
    

    Example:

    (call (simplify (lambda (/ a a a a))) {a 2})
    

    Output:

    0.25
    

    Example:

    (call (simplify (lambda (/ a a b))) {a 2 b 4})
    

    Output:

    0.25
    

    Example:

    (simplify (lambda (/ a 2 0.5)))
    

    Output:

    a
    

    Example:

    (simplify (lambda (/ 12 2 3)))
    

    Output:

    2
    

    Example:

    (simplify (lambda (/ a 2 3)))
    

    Output:

    (/ a 6)
    

    Example:

    (call (simplify (lambda (/ a -1 0))) {a 2})
    

    Output:

    -.infinity
    

    Example:

    (call (simplify (lambda (/ a -2 0))) {a 2})
    

    Output:

    -.infinity
    

    Example:

    (call (simplify (lambda (/ a 0 -1))) {a 2})
    

    Output:

    .infinity
    

    Example:

    (call (simplify (lambda (/ a 0 -2))) {a 2})
    

    Output:

    .infinity
    

    Example:

    (call (simplify (lambda (/ a 2 0 -3))) {a 2})
    

    Output:

    .infinity
    

    Example:

    (unparse (simplify (lambda (/ a 2 0 -3))) .false .false)
    

    Output:

    "(/ a 2 0 -3)"
    

    Example:

    (call (simplify (lambda (/ a -0))) {a 2})
    

    Output:

    .infinity
    

    Example:

    (simplify (lambda (/ a .null b)))
    

    Output:

    .null
    

    Example:

    (simplify (lambda (/ a 2 1)))
    

    Output:

    (/ a 2)
    

    Example:

    (simplify (lambda (pow a 1)))
    

    Output:

    a
    

    Example:

    (simplify (lambda (exp (log a))))
    

    Output:

    (exp
     (log a)
    )
    

    Example:

    (call (simplify (lambda (exp (log a)))) {a -1})
    

    Output:

    .null
    

    Example:

    (call (simplify (lambda (exp (log a)))) {a 0})
    

    Output:

    0
    

    Example:

    (call (simplify (lambda (exp (log a)))) {a .infinity})
    

    Output:

    .infinity
    

    Example:

    (simplify (lambda (log (exp a))))
    

    Output:

    (log
     (exp a)
    )
    

    Example:

    (call (simplify (lambda (log (exp a)))) {a 1000})
    

    Output:

    .infinity
    

    Example:

    (call (simplify (lambda (log (exp a)))) {a -1000})
    

    Output:

    -.infinity
    

    Example:

    (simplify (lambda (log (exp))))
    

    Output:

    1
    

    Example:

    (simplify (lambda (/ a 7 7)))
    

    Output:

    (/ a 49)
    

    Example:

    (call (simplify (lambda (/ a 7 7))) {a 49})
    

    Output:

    1
    

    Example:

    (simplify (lambda (/ a 7 7 2)))
    

    Output:

    (/ a 98)
    

    Example:

    (simplify (lambda (/ a 49)))
    

    Output:

    (/ a 49)
    

    Example:

    (simplify (simplify (lambda (/ a 7 7))))
    

    Output:

    (/ a 49)
    

    Example:

    (simplify (lambda (concat "a" (concat b "c") "d")))
    

    Output:

    (concat "a" b "cd")
    

    Example:

    (call (simplify (lambda (concat "a" (concat b "c") "d"))) {b "-"})
    

    Output:

    "a-cd"
    

    Example:

    (call
     (simplify
         (lambda
             (concat
                 (concat "a" b)
                 "m"
                 (concat c "d")
             )
         )
     )
     {b "X" c "Y"}
    )
    

    Output:

    "aXmYd"
    

Amalgam Opcodes


This site uses Just the Docs, a documentation theme for Jekyll.