| Did you know ... | Search Documentation: |
| Predicate json_method/1 |
For example:
:- json_method
subtract(#{type:number}, #{type:number}): #{type:number}.
subtract(A, B, R) :- R is A-B.
Methods with named arguments can be implemented using a single
argument that is an object with specified properties. For example,
the program below implements a depositing to a bank account. The
method takes an account and amount parameter and returns the new
balance. The json_rpc_error/2 throws a JSON RPC application error.
:- json_method
deposit(#{ properties:
#{ account: #{type:string},
amount: #{type:number}
}}): #{type:number},
deposit(Request, Reply),
#{account: Account, amount: Amount} :< Request =>
transaction(( retract(account(Account, Old))
-> New is Old+Amount,
asserta(account(Account, New))
; json_rpc_error(2, "Account does not exist")
)),
Reply = New.