diff --git a/_core/smart/clarityRef.md b/_core/smart/clarityRef.md index a6273aaf..31ae569c 100644 --- a/_core/smart/clarityRef.md +++ b/_core/smart/clarityRef.md @@ -26,7 +26,7 @@ Anywhere a developer wishes to use a literal unsigned integer (for example, incr ### Bool type -Supports values of `'true` or `'false`. +Supports values of `true` or `false`. ### Buffer type diff --git a/_core/smart/functions.md b/_core/smart/functions.md index db95f6ad..507d0f56 100644 --- a/_core/smart/functions.md +++ b/_core/smart/functions.md @@ -11,9 +11,9 @@ Clarity includes _defines_ and native functions for creating user-defined funct * TOC {:toc} -## define and define-public functions +## define-private and define-public functions -Functions specified via `define-public` statements are public functions. Functions without these designations, simple `define` statements, are private functions. You can run a contract's public functions directly via the `clarity-cli execute` command line directly or from other contracts. You can use the `clarity eval` or `clarity eval_raw` commands to evaluate private functions via the command line. +Functions specified via `define-public` statements are public functions. Functions without these designations, simple `define-private` statements, are private functions. You can run a contract's public functions directly via the `clarity-cli execute` command line directly or from other contracts. You can use the `clarity eval` or `clarity eval_raw` commands to evaluate private functions via the command line. Public functions return a Response type result. If the function returns an `ok` type, then the function call is considered valid, and any changes made to the blockchain state will be materialized. If the function returns an `err` type, it is considered invalid, and has no effect on the smart contract's state. @@ -71,19 +71,19 @@ The `define-map` interface, as described, disallows range-queries and queries-by
(fetch-entry map-name key-tuple)
'null
if there is none.(map-get? map-name key-tuple)
(optional (tuple))
(set-entry! map-name key-tuple value-tuple)
(map-set map-name key-tuple value-tuple)
(insert-entry! map-name key-tuple value-tuple)
(map-insert map-name key-tuple value-tuple)
key-tuple
in the data map if and only if an entry does not already exist.(delete-entry! map-name key-tuple)
(map-delete map-name key-tuple)
;; Functions -(define (say-hi) +(define-public (say-hi) "hello world") -(define (increment-number (number int)) +(define-public (increment-number (number int)) (+ 1 number)) -(define (increment-number-by-10 (number int)) +(define-public (increment-number-by-10 (number int)) (+ 10 number))@@ -226,16 +226,16 @@ Use the `+` and `-` function to create a `decrement-number` user-defined method.
;; Functions - (define (say-hi) + (define-public (say-hi) "hello world") - (define (increment-number (number int)) + (define-public (increment-number (number int)) (+ 1 number)) - (define (increment-number-by-10 (number int)) + (define-public (increment-number-by-10 (number int)) (+ 10 number)) - (define (decrement-number (number int)) + (define-public (decrement-number (number int)) (- number 1))@@ -259,22 +259,22 @@ Finally, try adding a `counter` variable and be sure to store it. Increment `cou ;; Functions -(define (say-hi) +(define-public (say-hi) "hello world") -(define (increment-number (number int)) +(define-public (increment-number (number int)) (+ 1 number)) -(define (increment-number-by-10 (number int)) +(define-public (increment-number-by-10 (number int)) (+ 10 number)) -(define (decrement-number (number int)) +(define-public (decrement-number (number int)) (- number 1)) -(define (increment-counter) +(define-public (increment-counter) (set-var! counter (+ 1 counter))) -(define (get-counter) +(define-public (get-counter) (counter)) diff --git a/_data/clarityRef.json b/_data/clarityRef.json index 796032d8..1eaf6bbd 100644 --- a/_data/clarityRef.json +++ b/_data/clarityRef.json @@ -534,7 +534,7 @@ "output_type": "Not Applicable", "signature": "(define-map map-name ((key-name-0 key-type-0) ...) ((val-name-0 val-type-0) ...))", "description": "`define-map` is used to define a new datamap for use in a smart contract. Such\nmaps are only modifiable by the current smart contract.\n\nMaps are defined with a key tuple type and value tuple type. These are defined using a list\nof name and type pairs, e.g., a key type might be `((id int))`, which is a tuple with a single \"id\"\nfield of type `int`.\n\nLike other kinds of definition statements, `define-map` may only be used at the top level of a smart contract\ndefinition (i.e., you cannot put a define statement in the middle of a function body).", - "example": "\n(define-map squares ((x int)) ((square int)))\n(define (add-entry (x int))\n (map-insert squares ((x 2)) ((square (* x x)))))\n(add-entry 1)\n(add-entry 2)\n(add-entry 3)\n(add-entry 4)\n(add-entry 5)\n" + "example": "\n(define-map squares ((x int)) ((square int)))\n(define-public (add-entry (x int))\n (map-insert squares ((x 2)) ((square (* x x)))))\n(add-entry 1)\n(add-entry 2)\n(add-entry 3)\n(add-entry 4)\n(add-entry 5)\n" }, { "name": "define-data-var", @@ -542,7 +542,7 @@ "output_type": "Not Applicable", "signature": "(define-data-var var-name type value)", "description": "`define-data-var` is used to define a new persisted variable for use in a smart contract. Such\nvariable are only modifiable by the current smart contract.\n\nPersisted variable are defined with a type and a value.\n\nLike other kinds of definition statements, `define-data-var` may only be used at the top level of a smart contract\ndefinition (i.e., you cannot put a define statement in the middle of a function body).", - "example": "\n(define-data-var size int 0)\n(define (set-size (value int))\n (var-set size value))\n(set-size 1)\n(set-size 2)\n" + "example": "\n(define-data-var size int 0)\n(define-public (set-size (value int))\n (var-set size value))\n(set-size 1)\n(set-size 2)\n" }, { "name": "define-fungible-token", @@ -584,7 +584,7 @@ "name": "none", "output_type": "(optional ?)", "description": "Represents the _none_ option indicating no value for a given optional (analogous to a null value).", - "example": "\n(define (only-if-positive (a int))\n (if (> a 0)\n (some a)\n none))\n(only-if-positive 4) ;; Returns (some 4)\n(only-if-positive (- 3)) ;; Returns none\n" + "example": "\n(define-public (only-if-positive (a int))\n (if (> a 0)\n (some a)\n none))\n(only-if-positive 4) ;; Returns (some 4)\n(only-if-positive (- 3)) ;; Returns none\n" } ] }