]
-
- Examples:
- (let*
- ((qry (lambda (k obj) true)) ;; select all rows
- (f (lambda (x) [(at 'firstName x), (at 'b x)]))
- )
- (fold-db people (qry) (f))
- )
- |])
- ,("format", [text|
- native `format`
-
- Interpolate VARS into TEMPLATE using {}.
-
- Type:
- template:string vars:[*] -> string
-
- Examples:
- > (format "My {} has {}" ["dog" "fleas"])
- |])
- ,("format-time", [text|
- native `format-time`
-
- Format TIME using FORMAT. See ["Time Formats"
- docs](pact-reference.html#time-formats) for supported formats.
-
- Type:
- format:string time:time -> string
-
- Examples:
- > (format-time "%F" (time "2016-07-22T12:00:00Z"))
- |])
- ,("hash", [text|
- native `hash`
-
- Compute BLAKE2b 256-bit hash of VALUE represented in unpadded base64-url.
- Strings are converted directly while other values are converted using their
- JSON representation. Non-value-level arguments are not allowed.
-
- Type:
- value: -> string
-
- Examples:
- > (hash "hello")
- > (hash { 'foo: 1 })
- |])
- ,("hours", [text|
- native `hours`
-
- N hours, for use with 'add-time'
-
- Type:
- n:decimal -> decimal
- n:integer -> decimal
-
- Examples:
- > (add-time (time "2016-07-22T12:00:00Z") (hours 1))
- |])
- ,("identity", [text|
- native `identity`
-
- Return provided value.
-
- Type:
- value: ->
-
- Examples:
- > (map (identity) [1 2 3])
- |])
- ,("if", [text|
- native `if`
-
- Test COND. If true, evaluate THEN. Otherwise, evaluate ELSE.
-
- Type:
- cond:bool then: else: ->
-
- Examples:
- > (if (= (+ 2 2) 4) "Sanity prevails" "Chaos reigns")
- |])
- ,("insert", [text|
- native `insert`
-
- Write entry in TABLE for KEY of OBJECT column data, failing if data already
- exists for KEY.
-
- Type:
- table:table:<{row}> key:string object:object:<{row}> -> string
-
- Examples:
- (insert accounts id { "balance": 0.0, "note": "Created account." })
- |])
- ,("install-capability", [text|
- native `install-capability`
-
- Specifies, and provisions install of, a _managed_ CAPABILITY, defined in a
- 'defcap' in which a '@managed' tag designates a single parameter to be managed
- by a specified function. After install, CAPABILITY must still be brought into
- scope using 'with-capability', at which time the 'manager function' is invoked
- to validate the request. The manager function is of type 'managed:
- requested:
->
', where '
' indicates the type of the managed
- parameter, such that for '(defcap FOO (bar:string baz:integer) @managed baz
- FOO-mgr ...)', the manager function would be '(defun FOO-mgr:integer
- (managed:integer requested:integer) ...)'. Any capability matching the
- 'static' (non-managed) parameters will cause this function to be invoked with
- the current managed value and that of the requested capability. The function
- should perform whatever logic, presumably linear, to validate the request, and
- return the new managed value representing the 'balance' of the request. NOTE
- that signatures scoped to a managed capability cause the capability to be
- automatically provisioned for install similarly to one installed with this
- function.
-
- Type:
- capability: -> bool -> string
-
- Examples:
- (install-capability (PAY "alice" "bob" 10.0))
- |])
- ,("int-to-str", [text|
- native `int-to-str`
-
- Represent integer VAL as a string in BASE. BASE can be 2-16, or 64 for
- unpadded base64URL. Only positive values are allowed for base64URL conversion.
-
- Type:
- base:integer val:integer -> string
-
- Examples:
- > (int-to-str 16 65535)
- > (int-to-str 64 43981)
- |])
- ,("is-charset", [text|
- native `is-charset`
-
- Check that a string INPUT conforms to the a supported character set CHARSET.
- Character sets currently supported are: 'CHARSET_LATIN1' (ISO-8859-1), and
- 'CHARSET_ASCII' (ASCII). Support for sets up through ISO 8859-5 supplement
- will be added in the future.
-
- Type:
- charset:integer input:string -> bool
-
- Examples:
- > (is-charset CHARSET_ASCII "hello world")
- > (is-charset CHARSET_ASCII "I am nÖt ascii")
- > (is-charset CHARSET_LATIN1 "I am nÖt ascii, but I am latin1!")
- |])
- ,("is-principal", [text|
- native `is-principal`
-
- Tell whether PRINCIPAL string conforms to the principal format without proving
- validity.
-
- Type:
- principal:string -> bool
-
- Examples:
- (enforce (is-principal 'k:462e97a099987f55f6a2b52e7bfd52a36b4b5b470fed0816a3d9b26f9450ba69) "Invalid account structure: non-principal account")
- |])
- ,("keylog", [text|
- native `keylog`
-
- Return updates to TABLE for a KEY in transactions at or after TXID, in a list
- of objects indexed by txid.
-
- Type:
- table:table:<{row}> key:string txid:integer -> [object:*]
-
- Examples:
- (keylog accounts "Alice" 123485945)
- |])
- ,("keys", [text|
- native `keys`
-
- Return all keys in TABLE.
-
- Type:
- table:table:<{row}> -> [string]
-
- Examples:
- (keys accounts)
- |])
- ,("keys-2", [text|
- native `keys-2`
-
- Keyset predicate function to match at least 2 keys in keyset.
-
- Type:
- count:integer matched:integer -> bool
-
- Examples:
- > (keys-2 3 1)
- |])
- ,("keys-all", [text|
- native `keys-all`
-
- Keyset predicate function to match all keys in keyset.
-
- Type:
- count:integer matched:integer -> bool
-
- Examples:
- > (keys-all 3 3)
- |])
- ,("keys-any", [text|
- native `keys-any`
-
- Keyset predicate function to match any (at least 1) key in keyset.
-
- Type:
- count:integer matched:integer -> bool
-
- Examples:
- > (keys-any 10 1)
- |])
- ,("keyset-ref-guard", [text|
- native `keyset-ref-guard`
-
- Creates a guard for the keyset registered as KEYSET-REF with 'define-keyset'.
- Concrete keysets are themselves guard types; this function is specifically to
- store references alongside other guards in the database, etc.
-
- Type:
- keyset-ref:string -> guard
- |])
- ,("length", [text|
- native `length`
-
- Compute length of X, which can be a list, a string, or an object.
-
- Type:
- x:],string,object:<{o}>]> -> integer
-
- Examples:
- > (length [1 2 3])
- > (length "abcdefgh")
- > (length { "a": 1, "b": 2 })
- |])
- ,("list", [text|
- native `list`
-
- Create list from ELEMS. Deprecated in Pact 2.1.1 with literal list support.
-
- Type:
- elems:* -> [*]
-
- Examples:
- > (list 1 2 3)
- |])
- ,("list-modules", [text|
- native `list-modules`
-
- List modules available for loading.
-
- Type:
- -> [string]
- |])
- ,("ln", [text|
- native `ln`
-
- Natural log of X.
-
- Type:
- x: ->
-
- Examples:
- > (round (ln 60) 6)
- |])
- ,("log", [text|
- native `log`
-
- Log of Y base X.
-
- Type:
- x: y: ->
- x: y: -> decimal
-
- Examples:
- > (log 2 256)
- |])
- ,("make-list", [text|
- native `make-list`
-
- Create list by repeating VALUE LENGTH times.
-
- Type:
- length:integer value: -> []
-
- Examples:
- > (make-list 5 true)
- |])
- ,("map", [text|
- native `map`
-
- Apply APP to each element in LIST, returning a new list of results.
-
- Type:
- app:x: -> list:[] -> []
-
- Examples:
- > (map (+ 1) [1 2 3])
- |])
- ,("minutes", [text|
- native `minutes`
-
- N minutes, for use with 'add-time'.
-
- Type:
- n:decimal -> decimal
- n:integer -> decimal
-
- Examples:
- > (add-time (time "2016-07-22T12:00:00Z") (minutes 1))
- |])
- ,("mod", [text|
- native `mod`
-
- X modulo Y.
-
- Type:
- x:integer y:integer -> integer
-
- Examples:
- > (mod 13 8)
- |])
- ,("namespace", [text|
- native `namespace`
-
- Set the current namespace to NAMESPACE. All expressions that occur in a
- current transaction will be contained in NAMESPACE, and once committed, may be
- accessed via their fully qualified name, which will include the namespace.
- Subsequent namespace calls in the same tx will set a new namespace for all
- declarations until either the next namespace declaration, or the end of the
- tx.
-
- Type:
- namespace:string -> string
-
- Examples:
- (namespace 'my-namespace)
- |])
- ,("not", [text|
- native `not`
-
- Boolean not.
-
- Type:
- x:bool -> bool
-
- Examples:
- > (not (> 1 2))
- |])
- ,("not?", [text|
- native `not?`
-
- Apply logical 'not' to the results of applying VALUE to APP.
-
- Type:
- app:x: -> bool value: -> bool
-
- Examples:
- > (not? (> 20) 15)
- |])
- ,("or", [text|
- native `or`
-
- Boolean logic with short-circuit.
-
- Type:
- x:bool y:bool -> bool
-
- Examples:
- > (or true false)
- |])
- ,("or?", [text|
- native `or?`
-
- Apply logical 'or' to the results of applying VALUE to A and B, with
- short-circuit.
-
- Type:
- a:x: -> bool b:x: -> bool value: -> bool
-
- Examples:
- > (or? (> 20) (> 10) 15)
- |])
- ,("pact-id", [text|
- native `pact-id`
-
- Return ID if called during current pact execution, failing if not.
-
- Type:
- -> string
- |])
- ,("pact-version", [text|
- native `pact-version`
-
- Obtain current pact build version.
-
- Type:
- -> string
-
- Examples:
- > (pact-version)
- |])
- ,("pairing-check", [text|
- native `pairing-check`
-
- Perform pairing and final exponentiation points in G1 and G2 in BN254, check
- if the result is 1
-
- Type:
- points-g1:[] points-g2:[] -> bool
- |])
- ,("parse-time", [text|
- native `parse-time`
-
- Construct time from UTCVAL using FORMAT. See ["Time Formats"
- docs](pact-reference.html#time-formats) for supported formats.
-
- Type:
- format:string utcval:string -> time
-
- Examples:
- > (parse-time "%F" "2016-09-12")
- |])
- ,("point-add", [text|
- native `point-add`
-
- Add two points together that lie on the curve BN254. Point addition either in
- Fq or in Fq2
-
- Type:
- type:string point1: point2: ->
-
- Examples:
- > (point-add 'g1 {'x: 1, 'y: 2} {'x: 1, 'y: 2})
- |])
- ,("poseidon-hash-hack-a-chain", [text|
- native `poseidon-hash-hack-a-chain`
-
- Poseidon Hash Function. Note: This is a reference version of the Poseidon hash
- function used by Hack-a-Chain.
-
- Type:
- i:integer j:integer k:integer l:integer m:integer n:integer o:integer p:integer -> integer
-
- Examples:
- > (poseidon-hash-hack-a-chain 1)
- > (poseidon-hash-hack-a-chain 1 2)
- > (poseidon-hash-hack-a-chain 1 2 3 4 5 6)
- > (poseidon-hash-hack-a-chain 1 2 3 4 5 6 7 8)
- |])
- ,("public-chain-data", [text|
- (defschema
- public-chain-data
- "Schema type for data returned from 'chain-data'."
-
- [ chain-id:string
- , block-height:integer
- , block-time:time
- , prev-block-hash:string
- , sender:string
- , gas-limit:integer
- , gas-price:decimal ])
- |])
- ,("read", [text|
- native `read`
-
- Read row from TABLE for KEY, returning database record object, or just COLUMNS
- if specified.
-
- Type:
- table:table:<{row}> key:string -> object:<{row}>
- table:table:<{row}> key:string columns:[string] -> object:<{row}>
-
- Examples:
- (read accounts id ['balance 'ccy])
- |])
- ,("read-decimal", [text|
- native `read-decimal`
-
- Parse KEY string or number value from top level of message data body as
- decimal.
-
- Type:
- key:string -> decimal
-
- Examples:
- (defun exec ()
- (transfer (read-msg "from") (read-msg "to") (read-decimal "amount")))
- |])
- ,("read-integer", [text|
- native `read-integer`
-
- Parse KEY string or number value from top level of message data body as
- integer.
-
- Type:
- key:string -> integer
-
- Examples:
- (read-integer "age")
- |])
- ,("read-keyset", [text|
- native `read-keyset`
-
- Read KEY from message data body as keyset ({ "keys": KEYLIST, "pred": PREDFUN
- }). PREDFUN should resolve to a keys predicate.
-
- Type:
- key:string -> keyset
-
- Examples:
- (read-keyset "admin-keyset")
- |])
- ,("read-msg", [text|
- native `read-msg`
-
- Read KEY from top level of message data body, or data body itself if not
- provided. Coerces value to their corresponding pact type: String -> string,
- Number -> integer, Boolean -> bool, List -> list, Object -> object.
-
- Type:
- ->
- key:string ->
-
- Examples:
- (defun exec ()
- (transfer (read-msg "from") (read-msg "to") (read-decimal "amount")))
- |])
- ,("read-string", [text|
- native `read-string`
-
- Parse KEY string or number value from top level of message data body as
- string.
-
- Type:
- key:string -> string
-
- Examples:
- (read-string "sender")
- |])
- ,("remove", [text|
- native `remove`
-
- Remove entry for KEY from OBJECT.
-
- Type:
- key:string object:object:<{o}> -> object:<{o}>
-
- Examples:
- > (remove "bar" { "foo": 1, "bar": 2 })
- |])
- ,("require-capability", [text|
- native `require-capability`
-
- Specifies and tests for existing grant of CAPABILITY, failing if not found in
- environment.
-
- Type:
- capability: -> bool -> bool
-
- Examples:
- (require-capability (TRANSFER src dest))
- |])
- ,("resume", [text|
- native `resume`
-
- Special form binds to a yielded object value from the prior step execution in
- a pact. If yield step was executed on a foreign chain, enforce endorsement via
- SPV.
-
- Type:
- binding:binding:<{r}> ->
- |])
- ,("reverse", [text|
- native `reverse`
-
- Reverse LIST.
-
- Type:
- list:[] -> []
-
- Examples:
- > (reverse [1 2 3])
- |])
- ,("round", [text|
- native `round`
-
- Performs Banker's rounding value of decimal X as integer, or to PREC precision
- as decimal.
-
- Type:
- x:decimal prec:integer -> decimal
- x:decimal -> integer
-
- Examples:
- > (round 3.5)
- > (round 100.15234 2)
- |])
- ,("scalar-mult", [text|
- native `scalar-mult`
-
- Multiply a point that lies on the curve BN254 by an integer value
-
- Type:
- type:string point1: scalar:integer ->
-
- Examples:
- > (scalar-mult 'g1 {'x: 1, 'y: 2} 2)
- |])
- ,("select", [text|
- native `select`
-
- Select full rows or COLUMNS from table by applying WHERE to each row to get a
- boolean determining inclusion.
-
- Type:
- table:table:<{row}> where:row:object:<{row}> -> bool -> [object:<{row}>]
- table:table:<{row}> columns:[string] where:row:object:<{row}> -> bool -> [object:<{row}>]
-
- Examples:
- (select people ['firstName,'lastName] (where 'name (= "Fatima")))
- (select people (where 'age (> 30)))?
- |])
- ,("shift", [text|
- native `shift`
-
- Shift X Y bits left if Y is positive, or right by -Y bits otherwise. Right
- shifts perform sign extension on signed number types; i.e. they fill the top
- bits with 1 if the x is negative and with 0 otherwise.
-
- Type:
- x:integer y:integer -> integer
-
- Examples:
- > (shift 255 8)
- > (shift 255 -1)
- > (shift -255 8)
- > (shift -255 -1)
- |])
- ,("sort", [text|
- native `sort`
-
- Sort a homogeneous list of primitive VALUES, or objects using supplied FIELDS
- list.
-
- Type:
- values:[] -> []
- fields:[string] values:[object:<{o}>] -> [object:<{o}>]
-
- Examples:
- > (sort [3 1 2])
- > (sort ['age] [{'name: "Lin",'age: 30} {'name: "Val",'age: 25}])
- |])
- ,("sqrt", [text|
- native `sqrt`
-
- Square root of X.
-
- Type:
- x: ->
-
- Examples:
- > (sqrt 25)
- |])
- ,("str-to-int", [text|
- native `str-to-int`
-
- Compute the integer value of STR-VAL in base 10, or in BASE if specified.
- STR-VAL can be up to 512 chars in length. BASE must be between 2 and 16, or 64
- to perform unpadded base64url conversion. Each digit must be in the correct
- range for the base.
-
- Type:
- str-val:string -> integer
- base:integer str-val:string -> integer
-
- Examples:
- > (str-to-int 16 "abcdef123456")
- > (str-to-int "123456")
- > (str-to-int 64 "q80")
- |])
- ,("str-to-list", [text|
- native `str-to-list`
-
- Takes STR and returns a list of single character strings
-
- Type:
- str:string -> [string]
-
- Examples:
- > (str-to-list "hello")
- > (concat (map (+ " ") (str-to-list "abcde")))
- |])
- ,("take", [text|
- native `take`
-
- Take COUNT values from LIST (or string), or entries having keys in KEYS from
- OBJECT. If COUNT is negative, take from end. If COUNT exceeds the interval
- (-2^63,2^63), it is truncated to that range.
-
- Type:
- count:integer list:],string]> -> ],string]>
- keys:[string] object:object:<{o}> -> object:<{o}>
-
- Examples:
- > (take 2 "abcd")
- > (take (- 3) [1 2 3 4 5])
- > (take ['name] { 'name: "Vlad", 'active: false})
- |])
- ,("time", [text|
- native `time`
-
- Construct time from UTCVAL using ISO8601 format (%Y-%m-%dT%H:%M:%SZ).
-
- Type:
- utcval:string -> time
-
- Examples:
- > (time "2016-07-22T11:26:35Z")
- |])
- ,("try", [text|
- native `try`
-
- Attempt a pure ACTION, returning DEFAULT in the case of failure. Pure
- expressions are expressions which do not do i/o or work with non-deterministic
- state in contrast to impure expressions such as reading and writing to a
- table.
-
- Type:
- default: action: ->
-
- Examples:
- > (try 3 (enforce (= 1 2) "this will definitely fail"))
- (expect "impure expression fails and returns default" "default" (try "default" (with-read accounts id {'ccy := ccy}) ccy))
- |])
- ,("tx-hash", [text|
- native `tx-hash`
-
- Obtain hash of current transaction as a string.
-
- Type:
- -> string
-
- Examples:
- > (tx-hash)
- |])
- ,("txids", [text|
- native `txids`
-
- Return all txid values greater than or equal to TXID in TABLE.
-
- Type:
- table:table:<{row}> txid:integer -> [integer]
-
- Examples:
- (txids accounts 123849535)
- |])
- ,("txlog", [text|
- native `txlog`
-
- Return all updates to TABLE performed in transaction TXID.
-
- Type:
- table:table:<{row}> txid:integer -> [object:*]
-
- Examples:
- (txlog accounts 123485945)
- |])
- ,("typeof", [text|
- native `typeof`
-
- Returns type of X as string.
-
- Type:
- x: -> string
-
- Examples:
- > (typeof "hello")
- |])
- ,("typeof-principal", [text|
- native `typeof-principal`
-
- Return the protocol type of a given PRINCIPAL value. If input value is not a
- principal type, then the empty string is returned.
-
- Type:
- principal:string -> string
-
- Examples:
- (typeof-principal 'k:462e97a099987f55f6a2b52e7bfd52a36b4b5b470fed0816a3d9b26f9450ba69)
- |])
- ,("update", [text|
- native `update`
-
- Write entry in TABLE for KEY of OBJECT column data, failing if data does not
- exist for KEY.
-
- Type:
- table:table:<{row}> key:string object:object:~<{row}> -> string
-
- Examples:
- (update accounts id { "balance": (+ bal amount), "change": amount, "note": "credit" })
- |])
- ,("validate-keypair", [text|
- native `validate-keypair`
-
- Enforce that the Curve25519 keypair of (PUBLIC,SECRET) match. Key values are
- base-16 strings of length 32.
-
- Type:
- public:string secret:string -> bool
-
- Examples:
- (validate-keypair pubkey privkey)
- |])
- ,("validate-principal", [text|
- native `validate-principal`
-
- Validate that PRINCIPAL unambiguously identifies GUARD.
-
- Type:
- guard:guard principal:string -> bool
-
- Examples:
- (enforce (validate-principal (read-keyset 'keyset) account) "Invalid account ID")
- |])
- ,("verify-spv", [text|
- native `verify-spv`
-
- Performs a platform-specific spv proof of type TYPE on PAYLOAD. The format of
- the PAYLOAD object depends on TYPE, as does the format of the return object.
- Platforms such as Chainweb will document the specific payload types and return
- values.
-
- Type:
- type:string payload:object: -> object:
-
- Examples:
- (verify-spv "TXOUT" (read-msg "proof"))
- |])
- ,("where", [text|
- native `where`
-
- Utility for use in 'filter' and 'select' applying APP to FIELD in VALUE.
-
- Type:
- field:string app:x: -> bool value:object:<{row}> -> bool
-
- Examples:
- > (filter (where 'age (> 20)) [{'name: "Mary",'age: 30} {'name: "Juan",'age: 15}])
- |])
- ,("with-capability", [text|
- native `with-capability`
-
- Specifies and requests grant of _acquired_ CAPABILITY which is an application
- of a 'defcap' production. Given the unique token specified by this
- application, ensure that the token is granted in the environment during
- execution of BODY. 'with-capability' can only be called in the same module
- that declares the corresponding 'defcap', otherwise module-admin rights are
- required. If token is not present, the CAPABILITY is evaluated, with
- successful completion resulting in the installation/granting of the token,
- which will then be revoked upon completion of BODY. Nested 'with-capability'
- calls for the same token will detect the presence of the token, and will not
- re-apply CAPABILITY, but simply execute BODY. 'with-capability' cannot be
- called from within an evaluating defcap. Acquire of a managed capability
- results in emission of the equivalent event.
-
- Type:
- capability: -> bool body:[*] ->
-
- Examples:
- (with-capability (UPDATE-USERS id) (update users id { salary: new-salary }))
- |])
- ,("with-default-read", [text|
- native `with-default-read`
-
- Special form to read row from TABLE for KEY and bind columns per BINDINGS over
- subsequent body statements. If row not found, read columns from DEFAULTS, an
- object with matching key names.
-
- Type:
- table:table:<{row}> key:string defaults:object:~<{row}> bindings:binding:~<{row}> ->
-
- Examples:
- (with-default-read accounts id { "balance": 0, "ccy": "USD" } { "balance":= bal, "ccy":= ccy }
- (format "Balance for {} is {} {}" [id bal ccy]))
- |])
- ,("with-read", [text|
- native `with-read`
-
- Special form to read row from TABLE for KEY and bind columns per BINDINGS over
- subsequent body statements.
-
- Type:
- table:table:<{row}> key:string bindings:binding:<{row}> ->
-
- Examples:
- (with-read accounts id { "balance":= bal, "ccy":= ccy }
- (format "Balance for {} is {} {}" [id bal ccy]))
- |])
- ,("write", [text|
- native `write`
-
- Write entry in TABLE for KEY of OBJECT column data.
-
- Type:
- table:table:<{row}> key:string object:object:<{row}> -> string
-
- Examples:
- (write accounts id { "balance": 100.0 })
- |])
- ,("xor", [text|
- native `xor`
-
- Compute bitwise X xor Y.
-
- Type:
- x:integer y:integer -> integer
-
- Examples:
- > (xor 127 64)
- > (xor 5 -7)
- |])
- ,("yield", [text|
- native `yield`
-
- Yield OBJECT for use with 'resume' in following pact step. With optional
- argument TARGET-CHAIN, target subsequent step to execute on targeted chain
- using automated SPV endorsement-based dispatch.
-
- Type:
- object:object:<{y}> -> object:<{y}>
- object:object:<{y}> target-chain:string -> object:<{y}>
-
- Examples:
- (yield { "amount": 100.0 })
- (yield { "amount": 100.0 } "some-chain-id")
- |])
- ,("zip", [text|
- native `zip`
-
- Combine two lists with some function f, into a new list, the length of which
- is the length of the shortest list.
-
- Type:
- f:x: y: -> list1:[] list2:[] -> []
-
- Examples:
- > (zip (+) [1 2 3 4] [4 5 6 7])
- > (zip (-) [1 2 3 4] [4 5 6])
- > (zip (+) [1 2 3] [4 5 6 7])
- |])
- ,("|", [text|
- native `|`
-
- Compute bitwise X or Y.
-
- Type:
- x:integer y:integer -> integer
-
- Examples:
- > (| 2 3)
- > (| 5 -7)
- |])
- ,("~", [text|
- native `~`
-
- Reverse all bits in X.
-
- Type:
- x:integer -> integer
-
- Examples:
- > (~ 15)
- |])
- ]
+builtinDocs :: M.Map Text MarkdownDoc
+builtinDocs = $$mkBuiltinDocs
diff --git a/pact/Pact/Core/Repl/BuiltinDocs/Internal.hs b/pact/Pact/Core/Repl/BuiltinDocs/Internal.hs
new file mode 100644
index 000000000..ab44ffbe0
--- /dev/null
+++ b/pact/Pact/Core/Repl/BuiltinDocs/Internal.hs
@@ -0,0 +1,96 @@
+-- |
+{-# LANGUAGE DeriveLift #-}
+
+module Pact.Core.Repl.BuiltinDocs.Internal where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Syntax
+
+import System.Directory
+import System.FilePath
+
+import Control.Monad
+import qualified Data.Text.IO as T
+import qualified Data.Text as T
+import qualified Data.Map.Strict as M
+import Data.Functor
+
+listBuiltinDocs :: IO [FilePath]
+listBuiltinDocs = do
+ let baseDir = "docs/builtins"
+ cats <- listDirectory baseDir
+ files <- forM cats $ \cat -> do
+ let catPath = baseDir > cat
+ docs <- listDirectory catPath
+ <&> filter (\f -> takeExtension f == ".md")
+ pure $ (catPath >) <$> docs
+ pure $ concat files
+
+
+embedIO :: Lift a => IO a -> Code Q a
+embedIO action = runIO action `bindCode` liftTyped
+
+newtype MarkdownDoc
+ = MarkdownDoc { _markdownDoc :: T.Text }
+ deriving (Lift, Eq, Show)
+
+mkBuiltinDocs :: Code Q (M.Map T.Text MarkdownDoc)
+mkBuiltinDocs = embedIO action
+ where
+ action = do
+ files <- listBuiltinDocs
+ cnt <- forM files $ \f -> do
+ let bname = takeBaseName f
+ content <- T.readFile f
+ pure (normalizedNameToBuiltin $ T.pack bname, MarkdownDoc content)
+ pure $ M.fromList cnt
+
+
+builtinToNormalizedName :: T.Text -> T.Text
+builtinToNormalizedName = \case
+ "!=" -> "neq"
+ "&" -> "bitwise-and"
+ "*" -> "mult"
+ "+" -> "add"
+ "-" -> "sub"
+ "/" -> "div"
+ "<" -> "lt"
+ "<=" -> "leq"
+ "=" -> "eq"
+ ">" -> "gt"
+ ">=" -> "geq"
+ "^" -> "pow"
+ "and?" -> "and-q"
+ "not?" -> "not-q"
+ "or?" -> "or-q"
+ "|" -> "bitwise-or"
+ "~" -> "bitwise-reverse"
+ "begin-named-tx" -> "begin-tx"
+ "continue-pact-rollback-yield" -> "continue-pact"
+ "continue-pact-rollback-yield-object" -> "continue-pact"
+ "continue-pact-with-rollback" -> "continue-pact"
+ "enforce-pact-version-range" -> "enforce-pact-version"
+ "env-set-gas" -> "env-gas"
+ "expect-failure-match" -> "expect-failure"
+ other -> other
+
+normalizedNameToBuiltin :: T.Text -> T.Text
+normalizedNameToBuiltin = \case
+ "neq" -> "!="
+ "bitwise-and" -> "&"
+ "mult" -> "*"
+ "add" -> "+"
+ "sub" -> "-"
+ "div" -> "/"
+ "lt" -> "<"
+ "leq" -> "<="
+ "eq" -> "="
+ "gt" -> ">"
+ "geq" -> ">="
+ "pow" -> "^"
+ "and-q" -> "and?"
+ "not-q" -> "not?"
+ "or-q" -> "or?"
+ "bitwise-or" -> "|"
+ "bitwise-reverse" -> "~"
+ other -> other