Comments
Browse / Mercury Programming Language Cheatsheet
Mercury Programming Language Cheatsheet
A concise reference for the Mercury programming language, covering syntax, data types, control flow, and module system.
Core Syntax and Types
Basic Syntax
|
|
|
|
Predicates |
|
|
Functions |
|
|
Clauses |
|
|
Mode Declarations |
|
|
Type Declarations |
|
Data Types
|
Integer |
|
|
Float |
|
|
String |
|
|
Boolean |
|
|
List |
|
|
Tuple |
|
|
User-defined Types |
Using |
Mode Annotations
|
Mode annotations specify how arguments are used in a predicate or function. Common modes include:
|
Control Flow and Logic
Conditional Statements
|
If-Then-Else |
|
|
If-Then |
|
Loops and Recursion
|
Recursion |
Mercury encourages recursion for iterative processes.
|
Determinism
|
Mercury uses determinism annotations to indicate the number of solutions a predicate can produce:
|
Negation
|
Negation as Failure |
|
Module System
Module Declaration
|
Module Header |
|
|
Interface Declaration |
|
|
Implementation Declaration |
|
Importing Modules
|
Importing Predicates |
|
|
Selective Import |
|
Exporting Symbols
|
Exporting Predicates |
|
Error Handling and Debugging
Exception Handling
|
Throwing Exceptions |
|
|
Catching Exceptions |
|
Debugging
|
Mercury provides debugging tools for tracing predicate execution and inspecting variables. Utilize the Mercury debugger (if available in your environment) to step through code, set breakpoints, and examine the state of variables. |