clone!
Copy named variables without moving them. Vectors
clone! name, [name, ...]
Vectors move when a named variable is used in an expression, so the variable can't be used again. clone! returns a copy of the variable and leaves the original in scope. Copies of witness variables refer to the same witness entries, so cloning costs nothing in the R1CS.
Arguments
name- One or more named variables, static or witness. Any other expression is an error.
Returns
With one argument, a copy of the variable. With several, a tuple of copies. clone! is an expression.
Constraints
None.
Example
(let x) let doubled = (clone! x) + (clone! x) (doubled, x)
Without the clone the first use moves x:
(let x) let y = x + [1 1 1] x
Notes
Scalars are copied on use anyway, and x * x with the same name on both sides clones silently, so clone! is only needed for vectors used more than once. Inside precompile arguments write (clone! x).
Used in the standard library
bdlop/bdlop_linear_nizk_verify, bdlop/bdlop_r1cs_verify, bits/add32_bits, bits/rotl32_bits, bits/to_bits, bits/to_bits_exact, bits/xor_bits_vec, bits/xor_bits_vec_wtns, blake3/blake3_compress, blake3/blake3_core, blake3/blake3_g, blake3/blake3_rotate_rows, blake3/blake3_rotate_words, chacha/chacha_block, chacha/chacha_quarter_round, dilithium/lattice/lattice_permutation, dilithium/mldsa/mldsa44_verify, dilithium/mldsa/mldsa44_verify_static, dilithium/mldsa/mldsa44_w_approx, dilithium/mldsa/mldsa44_w_approx_static, dilithium/mldsa/mldsa_intt_native, dilithium/mldsa/mldsa_ntt_native, ext/ext_eq_eval, ext/ext_eq_table, ext/ext_mle_eval, ext/ext_mul, ext/ext_poly_eval, ext/ext_vec_mul, ext/mle_eq_table, keccak/keccak_f1600, keccak/keccak_sponge_shake, lattice/lattice_assert_canonical, lattice/lattice_bits, lattice/lattice_digest, lattice/lattice_expand, lattice/lattice_oraccle_sample, lattice/lattice_oraccle_sample_vec, lattice/lattice_oraccle_squeeze, mat_transpose, mat_vec_mul, mersenne61/mldsa/mldsa44_verify, mersenne61/mldsa/mldsa44_w_approx, mersenne61/mldsa/mldsa_intt, mersenne61/mldsa/mldsa_ntt_q, mersenne61/mldsa/mldsa_pointwise, mersenne61/mldsa/mldsa_reduce, mersenne61/poseidon/poseidon_mersenne61, mersenne61/poseidon/poseidon_mersenne61_state, milli/mldsa/mldsa44_verify, milli/mldsa/mldsa44_w_approx, milli/mldsa/mldsa_ct1, milli/mldsa/mldsa_intt_sub, milli/mldsa/mldsa_ntt_z, milli/mldsa/mldsa_pointwise, milli/mldsa/mldsa_reduce, milli/poseidon/poseidon_milli, milli/poseidon/poseidon_milli_state, mldsa/mldsa44_finish, mldsa/mldsa44_parse, mldsa/mldsa44_parse_sig, mldsa/mldsa_assert_below_q, mldsa/mldsa_expand_a, mldsa/mldsa_hint_unpack, mldsa/mldsa_limbs, mldsa/mldsa_rej_ntt_poly, mldsa/mldsa_sample_in_ball, mldsa/mldsa_use_hint, oraccle/oraccle_sample_uniform_vec, oraccle/oraccle_squeeze, polynomial/mat_poly_mul_vec, polynomial/poly_norm_inf, polynomial/poly_norm_inf_lt, polynomial/poly_norm_l1, polynomial/vec_poly_scalar_mul, polynomial/vec_polynomial_coef_mul, pow, r1cs/r1cs_assert_field, r1cs/r1cs_eval, r1cs/r1cs_into_output, slip/slip_r1cs_arg_verify, split_at, typed/typed_bytes_check, typed/typed_bytes_lattice, typed/typed_lattice_digest_bits, typed/typed_lex_chacha