clarity-lang / reference

The Clarity Reference
146 stars 34 forks source link

Support for dynamic length sequences #73

Open minaahilimtiaz opened 5 months ago

minaahilimtiaz commented 5 months ago

Currently, in Clarity, it is mandatory to specify the length of sequences such as strings, list and buff at the time of declaration or in function signatures, as shown in the snippet below.

(define-data-var members (list 100 principal) (list))
(from-consensus-buff? (string-ascii 78) 0x0d000000074d696e6168696c)

In Solidity, it isn't mandatory to specify length for strings and there is support for both dynamic arrays and length-specified arrays, with syntax similar to regular programming languages like Javascript which makes the adoption of syntax relatively easy.


uint256[] public arr;
uint256[] public arr2 = [1, 2, 3];

string public text = "Hello";

The requirement to specify length at time of variable declaration and fuction signature in Clarity makes it difficult to work with sequence structures iteratively specially if the operation performed iteratively is impacting the length like concat(https://docs.stacks.co/clarity/functions#concat).