x y
play

X:Y XandYmatch X::Y XandYareidentical sult goal, for example: X - PowerPoint PPT Presentation

2.1 Data objects 33 data objects ,/\ simple objects structures /\ of Prolog constants variables /\ atoms numbers Figure 2.1 Data objects in Prolog. Atoms and numbers 2.1.1 44 In chapter 1 we have seen some examples of atoms and variables.


  1. 2.1 Data objects 33 data objects ,/\ simple objects structures /\ of Prolog constants variables /\ atoms numbers Figure 2.1 Data objects in Prolog. Atoms and numbers 2.1.1 44 In chapter 1 we have seen some examples of atoms and variables. In general, however, atoms can take more complicated forms - that is, strings of the follow- ing characters: . upper-case letters A,B, . . . ,2 . lower-case letters a, b, . . . , z . digitsO,'J.,2,...,9 syntax and semantics of basic con- . special characters such as * -* I < >: : . & ects. The topics included are: Atoms can be constructed iri three ways: (1) Strings of ietters, digits and the underscore character, ,_,, starting with a lower- ts case letter: am anna nil meanings of a program x25 x_25 lauses and goals. x_2548 r Chapter 1. Here the treatment will .x_ xv alpha_beta procedure missJones (2) Strings of special characters: in Prolog. The Prolog system lm by its syntactic form. This is + different forms for each type of br distinguishing between atoms upper-case letters whereas atoms rmation (such as data-type decla- When using atoms of this form, some care is necessary because some strings ¡rder to recognize the t¡re of an of special characters already have a predefined meaning. An example is ,:-,.

  2. Terms 2.1 Data objects 33 data objects ,/\ simple objects structures /\ of Prolog constants variables /\ atoms numbers Figure 2.1 Data objects in Prolog. Atoms, numbers, variables and structures are all terms. Atoms and numbers 2.1.1 44 In chapter 1 we have seen some examples of atoms and variables. In general, however, atoms can take more complicated forms - that is, strings of the follow- ing characters: . upper-case letters A,B, . . . ,2 . lower-case letters a, b, . . . , z . digitsO,'J.,2,...,9 syntax and semantics of basic con- . special characters such as * -* I < >: : . & ects. The topics included are: Atoms can be constructed iri three ways: (1) Strings of ietters, digits and the underscore character, ,_,, starting with a lower- ts case letter: am anna nil meanings of a program x25 x_25 lauses and goals. x_2548 r Chapter 1. Here the treatment will .x_ xv alpha_beta procedure missJones (2) Strings of special characters: in Prolog. The Prolog system lm by its syntactic form. This is + different forms for each type of br distinguishing between atoms upper-case letters whereas atoms rmation (such as data-type decla- When using atoms of this form, some care is necessary because some strings ¡rder to recognize the t¡re of an of special characters already have a predefined meaning. An example is ,:-,.

  3. Summary 175 facilities. Therefore an interpreter is typically used in the program development phase, and a compiler is used with the final program. It should be noted, again, that the details of consulting and compiling files : in the current input file that depend on the implementation of Prolog. usually a prolog implementation also Lits original form, represented as allows the user to enter and edit the program interactively. getsentence of this section can be 5ummary A Prolog implementation normally provides a set of built-in procedures to accomplish several useful operations that are not possible in pure prolog. In this cg system by means of built-in chapter, such a set of predicates available in many Prolog implementations was ams. The details of 'consulting, introduced. :ion of Prolog. Here we look at The type of a term can be tested by the following predicates: clogs. X is a (non-instantiated) variable var( X) ile F with a goal of the forr¡ X is not a variable nonvar( X) atom( X) X is an atom X is an integer integer( X) X is a real number float( X) program3 will typically have an X is either an atom or a number atomic( X) rgram file. The effect of this goal compound( X) X is a structure and loaded into the memory, so Terms can be constructed or decomposed: rrther questions from the user. Term :.. I Functor I Argumentlist] time during the same session. this new flle are added into the functor( Term, Functor, Arity) lementation and other circum- arg( N, Term, Argument) Lt a procedure defined in the name( Atom, CharacterCodes) ry be simply added at the end of Terms can be compared: ition of this procedure may be X:Y XandYmatch X::Y XandYareidentical sult goal, for example: X \:: Y X and Y are not identical X::: Y X and Y are arithmetically equal X:\: Y X and Y are not arithmetically equal X < Y IS: adthmetic value of X is less than Y (related: :<, ), ):) X @< Y term X precedes term Y (related: @:<, @>, @>:) A Prolog program can be viewed as a relational database that can be updated by . If a Prolog implementation also the following procedures: n a compiled form. This enables r factor of 5 or 10 between the assert( Clause) add Clause to the program ed into memory in the compiled asserta( Clause) add at the beginning e: assertz( Clause) add at the end retract( Clause) remove a clause that matches Clause All the obiects that satisfy a given condition can be collected into a list by the predicates: bagof( X, P, L) L is the list of all X that satisfy condition P setof( X, P, L) d, but interpreted programs are L is the sorted list of all X that satisfy condition P findall( X, P, L) similar to bagof rd traced by Prolog's debugging

  4. Summary 175 facilities. Therefore an interpreter is typically used in the program development phase, and a compiler is used with the final program. It should be noted, again, that the details of consulting and compiling files : in the current input file that depend on the implementation of Prolog. usually a prolog implementation also Lits original form, represented as allows the user to enter and edit the program interactively. getsentence of this section can be 5ummary A Prolog implementation normally provides a set of built-in procedures to accomplish several useful operations that are not possible in pure prolog. In this cg system by means of built-in chapter, such a set of predicates available in many Prolog implementations was ams. The details of 'consulting, introduced. :ion of Prolog. Here we look at The type of a term can be tested by the following predicates: clogs. X is a (non-instantiated) variable var( X) ile F with a goal of the forr¡ X is not a variable nonvar( X) atom( X) X is an atom X is an integer integer( X) X is a real number float( X) program3 will typically have an X is either an atom or a number atomic( X) rgram file. The effect of this goal X is a structure compound( X) and loaded into the memory, so Terms can be constructed or decomposed: rrther questions from the user. Term :.. I Functor I Argumentlist] time during the same session. this new flle are added into the functor( Term, Functor, Arity) lementation and other circum- arg( N, Term, Argument) Lt a procedure defined in the name( Atom, CharacterCodes) ry be simply added at the end of Terms can be compared: ition of this procedure may be X:Y XandYmatch X::Y XandYareidentical sult goal, for example: X \:: Y X and Y are not identical X::: Y X and Y are arithmetically equal X:\: Y X and Y are not arithmetically equal X < Y IS: adthmetic value of X is less than Y (related: :<, ), ):) X @< Y term X precedes term Y (related: @:<, @>, @>:) A Prolog program can be viewed as a relational database that can be updated by . If a Prolog implementation also the following procedures: n a compiled form. This enables r factor of 5 or 10 between the assert( Clause) add Clause to the program ed into memory in the compiled asserta( Clause) add at the beginning e: assertz( Clause) add at the end retract( Clause) remove a clause that matches Clause All the obiects that satisfy a given condition can be collected into a list by the predicates: bagof( X, P, L) L is the list of all X that satisfy condition P setof( X, P, L) d, but interpreted programs are L is the sorted list of all X that satisfy condition P findall( X, P, L) similar to bagof rd traced by Prolog's debugging

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend