stacksgov / sips

Community-submitted Stacks Improvement Proposals (SIPs)
133 stars 80 forks source link

SIP specifying Clarity `slice` function #76

Closed njordhov closed 1 year ago

njordhov commented 2 years ago

I propose a SIP to specify a slice function for Clarity, building on the proposal in https://github.com/clarity-lang/reference/issues/42 expanded with the insights of https://github.com/stacks-network/stacks-blockchain/issues/3149. There is a prototype implementation of such a function in the next branch that can be improved on.

obycode commented 1 year ago

Can this be closed now with SIP-015?

njordhov commented 1 year ago

You may consider leaving it open as a candidate improvement for the next version of Clarity. The alternative design with last argument being the length of the result sequence offers a compelling alternative to the contrived expressions that typically results from the slice? function in SIP-015.

For example, consider this expression to just take the first three elements "abc" from a string while having the result properly typed as a (string-ascii 3):

(unwrap-panic (as-max-len? (default-to (list) (slice? "abcdef" 0 3)) u3))

With the proposed slice function, this would be written as below (with the last argument being the length of the result):

(slice "abcdef" 0 3)
jcnelson commented 1 year ago

Can this be closed now with SIP-015?

Yes it can.

You may consider leaving it open as a candidate improvement for the next version of Clarity.

Please open a specific issue for an alternative slice design. Thanks!