Programming in Picat

Picat (picat-lang.org) is a logic-based multi-paradigm programming language that integrates logic programming, functional programming, constraint programming, and scripting. Picat takes many features from other languages, including logic variables, unific

  • PDF / 183,015 Bytes
  • 16 Pages / 439.37 x 666.142 pts Page_size
  • 106 Downloads / 152 Views

DOWNLOAD

REPORT


Abstract. Picat (picat-lang.org) is a logic-based multi-paradigm programming language that integrates logic programming, functional programming, constraint programming, and scripting. Picat takes many features from other languages, including logic variables, unification, backtracking, pattern-matching rules, functions, list/array comprehensions, loops, assignments, tabling for dynamic programming and planning, and constraint solving with CP (constraint programming), SAT (satisfiability), and MIP (mixed integer programming). These features make Picat more convenient than Prolog for scripting and modeling, and more suitable than functional languages (such as Haskell and F#) and scripting languages (such as Python and Ruby) for symbolic computations. This article provides a quick introduction to Picat using examples from Google Code Jam (GCJ).

1

Introduction

Picat is a simple, and yet powerful, logic-based multi-paradigm programming language. The desire for a logic-based general-purpose programming language that is as powerful as Python for scripting, and on a par with OPL [8] and MiniZinc [11] for modeling combinatorial problems, led to the design of Picat. Early attempts to introduce arrays and loops into Prolog for modeling failed to produce a satisfactory language: most noticeably, array accesses are treated as functions only in certain contexts; and loops require the declaration of global variables in ECLiPSe [14] and local variables in B-Prolog [16]. Picat departs from Prolog in many aspects, including the successful introduction of arrays and loops. Picat uses pattern-matching rather than unification in the selection of rules. Unification might be a natural choice in Horn clause resolution [9] for theorem proving, but its power is rarely needed for general programming tasks. Pattern-matching rules are fully indexed, and therefore Picat can be more scalable than Prolog. Unification can be considered as an equation over terms [4], and just like constraints over finite domains, Picat supports unification as an explicit call. Non-determinism, a powerful feature of logic programming, makes concise solutions possible for many problems, including simulation of non-deterministic automata, parsers of ambiguous grammars, and search problems. Nevertheless, non-determinism is not needed for deterministic computations. In Prolog, Horn clauses are backtrackable by default. As it is undecidable to detect determinism in general [5], programmers tend to excessively use the cut operator to c Springer International Publishing Switzerland 2016  J.J. Alferes et al. (Eds.): RuleML 2016, LNCS 9718, pp. 3–18, 2016. DOI: 10.1007/978-3-319-42019-6 1

4

N.-F. Zhou

prune unnecessary clauses. Picat supports explicit non-determinism, which renders the cut operator unnecessary. Rules are deterministic unless they are explicitly denoted as backtrackable. Picat supports functions, like many other logic-based languages, such as Curry [7], Erlang [2], and Mozart-Oz [13]. In Prolog, it’s often that queries fail, but the system gives no clue about