Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating a range #50

Open
njordhov opened this issue Mar 23, 2022 · 1 comment
Open

Generating a range #50

njordhov opened this issue Mar 23, 2022 · 1 comment

Comments

@njordhov
Copy link

njordhov commented Mar 23, 2022

A range function can generate a list of items incrementing from a lower to a higher value.

Such ranges are still explicitly enumerated in Clarity contracts. For example, the Pox contract uses a range of numbers for its cycle-indexes:

(let ((cycle-indexes (list u0 u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11))) ...

Using range would simplify this to:

(let ((cycle-indexes (range u0 u11))) ...

Such ranges are typically used with map and fold. Explicitly enumerating them can be tedious, error-prone, and increases the size of the contract.

It would be beneficial to also generate ranges of bytes such as (range 0x00 0xff) and ranges of characters such as (range "a" "z").

To facilitate static type- and cost analysis, the bounds of the range should be literal or constant. The cost of using range should be the same or less than having an explicitly enumerated range.

@dcsan
Copy link

dcsan commented Mar 24, 2022

this sounds like a great idea, esp since clarity doesn't support loops per se. I see so many similar hacks eg to add an int to a string (to construct a URI) with huge tables of data in the contract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants