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

Shorthand tuple properties #60

Open
hugocaillard opened this issue Jun 13, 2023 · 0 comments
Open

Shorthand tuple properties #60

hugocaillard opened this issue Jun 13, 2023 · 0 comments
Labels
clarity-3-candidate Changes that are considered to be included in Clarity 3

Comments

@hugocaillard
Copy link
Collaborator

hugocaillard commented Jun 13, 2023

Allow shorthand properties syntax in tuples.
If the value is a let variable, an argument or a constant that has the same name as the key, the value could be omitted.

For example, here is a function from the cost-voting contract:

;; before
(define-public (submit-proposal
  (funtion-contract principal)
  (function-name (string-ascii 128))
  (cost-function-contract principal)
  (cost-function-name (string-ascii 128))
)
  (begin
    (map-insert proposals 
      { proposal-id: (var-get proposal-count) }
      {
        cost-function-contract: cost-function-contract,
        cost-function-name: cost-function-name,
        function-contract: function-contract,
        function-name: function-name,
        expiration-block-height: (+ block-height VOTE_LENGTH)
      }
    )
    ;; ...
  )
)

It could be rewritten into

;; after
(define-public (submit-proposal
  (function-contract principal)
  (function-name (string-ascii 128))
  (cost-function-contract principal)
  (cost-function-name (string-ascii 128))
)
  ;; assigning it to a variable here for demonstration purpose
  (let ((expiration-block-height (+ block-height VOTE_LENGTH)))
    (map-insert proposals 
      { proposal-id: (var-get proposal-count) }
      {
        cost-function-contract,
        cost-function-name,
        function-contract,
        function-name,
        expiration-block-height,
      }
    )
    ;; ...
  )
)
@hugocaillard hugocaillard added the clarity-3-candidate Changes that are considered to be included in Clarity 3 label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarity-3-candidate Changes that are considered to be included in Clarity 3
Projects
None yet
Development

No branches or pull requests

1 participant