Computer Science

Declarative Programming

Declarative programming is a programming paradigm that focuses on describing what the program should accomplish, rather than how it should accomplish it. It involves specifying the desired outcome or result, and the program automatically determines the steps needed to achieve that outcome. This approach is often used in functional programming languages.

Written by Perlego with AI-assistance

3 Key excerpts on "Declarative Programming"

  • Designing and Developing Robust Instructional Apps
    • Kenneth J. Luterbach(Author)
    • 2018(Publication Date)
    • Routledge
      (Publisher)
    Computer Programming
    Computer programming languages are tools for problem solving and creative expression. Indeed, people engaged in creative problem solving with computer programming languages developed technologies that resulted in the epochal transformation of the past half century. This information era is marked by computer programs (software) that implement the communication protocols enabling the Internet and the web; software enabling mobile communications; software enabling email and other messaging; software for shopping; software for creating 2D images and 3D models; animation software; office productivity software; voice recognition software, and software for learning, for instance. Learning a computer programming language is extremely beneficial as an outlet for creative expression and problem solving.
    One selects a particular programming language to fit a variety of circumstances. When it is necessary to receive and respond to data at particular microsecond intervals, one writes code in a low-level programming language using the CPU’s instruction set, which addresses memory and input ports directly. Commonly, though, application software is written in a high-level computer programming language, which eliminates the need to consider the computer’s architecture. After distinguishing between low-level and high-level computer programming languages, it is helpful to recognize four main programming paradigms: imperative (procedural/ structural); object-oriented; functional; and logical. Each paradigm has something to offer problem solvers (Kedar, 2011). In this book, we will not be using Haskell (Thompson, 2011) or any functional programming language (so no f(g(x)) for us in this work). Also, we do not consider a logic programming language, such as Prolog. We will consider object-oriented concepts, as necessary. Object-oriented languages, such as C++, C# (C sharp), Objective-C, and Java include imperative language components. Indeed, C++, C#, and Objective-C are implementations of C with objects. C, like JavaScript, Perl, Lua, Swift, Java, and Python, all have imperative (procedural) language components, which enable input/output, and solve problems using the following core elements:
  • Information Technology
    eBook - ePub

    Information Technology

    An Introduction for Today's Digital World

    A declarative program does not contain control constructs like loops and subroutines. Instead, the programming language environment is tasked with a repeated pattern of matching rules against known facts to determine which rules are applicable. The environment then selects one rule to “fire” (execute). The result of the rule is usually new facts to add to what is already known. The environment then has a built-in loop that repeats this process until either all knowledge is exhausted or an ending point has been reached. Every rule is a form of selection statement. So, with this style of programming there is little need to utilize other control statements.
    The original Declarative Programming language was called Prolog and was developed for AI research. Figure 8.10 provides an example of a small set of knowledge and rules that we might encode using a Declarative Programming language, presented in both English and Prolog.
    The first seven items are rules. A rule has the consequence (the “then clause”) on the left side and the condition(s) on the right side. A comma between conditions indicates “AND” and a semicolon indicates “OR.”
    After the seven rules are two pieces of knowledge, or true statements. These declare that Cocoa is a poodle and Kitty is a cat. The last item is a question that we want the Prolog environment to solve for us, “what can be an indoor pet?”
    To answer this question, Prolog looks for any rule(s) with indoorpet on the left side. It finds one: an indoorpet, X, is a pet and is small. Now Prolog must find an X that satisfies both pet and small. To find a pet, X, Prolog finds one rule that states that the pet is an animal and tame. So, to solve indoorpet(X), Prolog must solve pet(X) and small(X). To solve pet(X), it must solve animal(X) and tame(X). Tame is true if something is a dog. Animal is true if something is a dog or cat. A dog can be either a poodle or a collie. Small is true if something is a poodle. We know of a poodle named Cocoa. Therefore, because Cocoa is a poodle, Cocoa is a dog and so is tame and is also small.
  • A Companion to the Philosophy of Language
    • Bob Hale, Crispin Wright, Alexander Miller(Authors)
    • 2017(Publication Date)
    • Wiley-Blackwell
      (Publisher)
    One obstacle to this is that many readers will have little fluency with the kind of programming we need. But we can work around that. Those readers who are acquainted with programming may be thinking of it on the model of a sequence of instructions. That is the “imperatival” model of computation. But there are other models, too, such as the “declarative” or “functional” model. The existence of this model of computation may be less familiar, but what it understands computation as is closer to ideas that philosophers and linguists are well‐acquainted with, like formulas of predicate logic. On the declarative model, arithmetic expressions like 2 + 7 ≰ 9, 2 + 7, and 2 all count as programs, which evaluate to true, 9, and 2, respectively. The set of inequalities {2 + x ≰ 9, x > 5} might be a program that evaluates to a set of assignments binding x to 6 or 7. The regular expression /ima[a–z]*ng/ might be a program that evaluates to the set of English words { imaging, imagining }. And so on. There’s nothing in either of these models of computation that prevents it from expressing or achieving all that the other can; their styles of doing so will just tend to be different. We’ll work with the declarative model. If readers have ever encountered a formal semantics for a programming language (from either of the models of computing just described, or another), it’s likely to be of the form computer scientists call “operational semantics.” This will have surface resemblance to a proof theory, or a system of rules for rewriting the program text. (Those analogies have defects, but that’s not important for our purposes here.) But there are other forms of semantics for programming languages
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.