Language::Prolog::Types::Abstract - Abstract classes for Prolog terms in Perl.
use Language::Prolog::Types::Abstract; if prolog_is_atom('hello') { print "'hello' is a Prolog atom\n" } ... etc.
Language::Prolog::Types::Abstract defines a set of abstract classes for Prolog terms.
It also includes functions to check for Prolog types and some utility functions to perform explicit conversion between Prolog and Perl.
This module define abstract classes for the usual Prolog functors, lists, variables and nil.
Atoms are not included because perl scalars do the work.
Perl undef is equivalent to Prolog nil ([]), although a different representation is allowed for the Prolog term.
undef
[]
Perl lists can be directly used as Prolog lists. The inverse is not always true and depends of the implementations used.
prolog_is_term($term)
returns true if $term is a valid Prolog term (actually a perl number, string or array or any object descending from Language::Prolog::Types::Term).
$term
prolog_is_atom($term)
returns true if $term is a valid Prolog atom (actually a perl number or string).
prolog_is_nil($term)
returns true if $term is Prolog nil value ([]).
prolog_is_functor($term)
returns true if $term is a Prolog functor.
It should be noted that lists are equivalent to functor '.'/2 and because of that, this function will also return true when $term is a list.
prolog_is_list($term)
returns true if $term is a Prolog list.
It should be noted that although Prolog nil is usually represented as the empty list [], it is not really a Prolog list and this function will return false for it.
prolog_is_list_or_nil($term)
returns true if $term is Prolog nil or a list.
prolog_is_variable($term)
prolog_is_var($term)
return true if $term is a free (unbounded) Prolog variable
prolog_is_ulist($term)
returns true if $term is an unfinished Prolog list, that means, one with doesn't end in nil. i.e. difference lists.
prolog_list2perl_list($term)
converts a Prolog list or nil to a Perl array.
prolog_list2perl_string($list)
Strings are usually represented in Prolog as lists of numbers. This function do the oposite conversion, from a list of numbers to a Perl string.
It should be noted that all the elements in the Prolog list have to be integers in the range [0..255] or an execption will be raised.
common abstract class for every Prolog term.
This class is used to account for the intrinsec differences between empty lists in Perl and Prolog.
In Prolog, nil although represented as the empty list, is not really a list.
This class provides a set of methods that apply both to lists and nil if it is considered to be the empty list.
BTW, you should mostly ignore this class and use Prolog::Language::Types::Nil or Prolog::Language::Types::List instead.
$lon->length()
returns the number of terms in the list. If the list is unfinished, the tail is not counted.
$lon->largs()
returns the terms in the list. If the list is unfinished, the tail is ignored.
$lon->tail()
returns the list tail, that will be nil if the list is finished or is nil
$lon->larg($index)
returns element number $index on the list, if $index is negative, the list is indexed from the end.
$index
Common abstract class for Prolog nil term representation.
This class doesn't define any method on its own.
Common abstract class for Prolog variable representation.
$var->name()
returns the variable name.
Common abstract class for Prolog functor representations.
$f->functor()
returns the functor name.
$f->arity()
returns the number of arguments of the functor.
$f->fargs()
returns the arguments of the functor.
$f->farg($index)
returns the argument of the functor in the position $index, if $index is negative the arguments are indexed begining from the end.
Be aware that arguments are indexed from 0, not from 1 as in prolog.
Common abstract class for Prolog list representations.
A Prolog list is actually the functor '.'/2. i.e.
[1, 4, hello, foo]
is equivalent to:
'.'(1, '.'(4, '.'(hello, '.'(foo, []))))
List methods are shared with Language::Prolog::Types::Nil and this is the reasong, to descent also from this class.
$l->car()
returns the list car.
car
$l->cdr()
returns the list cdr.
cdr
$l->car_cdr()
returns both the car and the cdr of the list.
Common abstract class to represent unfinished lists (those whose tail is not nil).
None of its own.
just in case...
None.
This class should be only used by Prolog <-> Perl interface authors.
Usually Perl objects are converted to Prolog structures when passed to a Prolog implementation. This class defines a proxy that stops the conversion to happen and just pass a reference to the Perl object.
Opaque objects should not be returned from Prolog interfaces, they should only be used to indicate to the Prolog implementations to not convert Perl data to Prolog. When returning from Prolog the original object should be directly returned to improve usability.
It should be noted that not all prolog implementations would support this type.
$this->opaque_reference
returns the object that it shields from prolog
$this-
returns comment string that will show in Prolog representation
returns object class as should been seen from Prolog side
Not really an abstract class but a simple implementation to be used as a base class to provide automatic opacity to objects.
So, objects of any class that has it as an ancestor will be passed to prolog as a reference.
Language::Prolog::Types.
Language::Prolog::Types::Internal contains an actual implementation for the classes defined in this module.
Any good Prolog book will also help :-)
Salvador Fandiño, <sfandino@yahoo.com>
Copyright 2002-2007 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'Fandiño,'. Assuming CP1252
To install Language::Prolog::Types, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Language::Prolog::Types
CPAN shell
perl -MCPAN -e shell install Language::Prolog::Types
For more information on module installation, please visit the detailed CPAN module installation guide.