The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Language::Prolog::Types::Abstract - Abstract classes for Prolog terms in Perl.

SYNOPSIS

  use Language::Prolog::Types::Abstract;
  if prolog_is_atom('hello') {
      print "'hello' is a Prolog atom\n"
  }

  ...

  etc.

ABSTRACT

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.

DESCRIPTION

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.

Perl lists can be directly used as Prolog lists. The inverse is not always true and depends of the implementations used.

EXPORT

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).

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.

ABSTRACT CLASSES

Language::Prolog::Types::Term

common abstract class for every Prolog term.

Language::Prolog::Types::ListOrNil

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.

Inherits:

Language::Prolog::Types::Term

Methods:

$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.

Language::Prolog::Types::Nil

Common abstract class for Prolog nil term representation.

Inherits

Language::Prolog::Types::ListOrNil

Methods

This class doesn't define any method on its own.

Language::Prolog::Types::Variable

Common abstract class for Prolog variable representation.

Inherits:

Language::Prolog::Types::Term

Methods:

$var->name()

returns the variable name.

Language::Prolog::Types::Functor

Common abstract class for Prolog functor representations.

Inherits:

Language::Prolog::Types::Term

Methods:

$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.

Language::Prolog::Types::List

Common abstract class for Prolog list representations.

Inherits:

Language::Prolog::Types::Functor

A Prolog list is actually the functor '.'/2. i.e.

  [1, 4, hello, foo]

is equivalent to:

  '.'(1, '.'(4, '.'(hello, '.'(foo, []))))
Language::Prolog::Types::ListOrNil

List methods are shared with Language::Prolog::Types::Nil and this is the reasong, to descent also from this class.

Methods:

$l->car()

returns the list car.

$l->cdr()

returns the list cdr.

$l->car_cdr()

returns both the car and the cdr of the list.

Language::Prolog::Types::UList

Common abstract class to represent unfinished lists (those whose tail is not nil).

Inherits:

Language::Prolog::Types::List

Methods:

None of its own.

Language::Prolog::Types::Unknow

just in case...

Inherits:

Language::Prolog::Types::Term

Methods:

None.

Language::Prolog::Types::Opaque

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.

Inherits:

Language::Prolog::Types::Term

Methods:

$this->opaque_reference

returns the object that it shields from prolog

$this->opaque_comment>

returns comment string that will show in Prolog representation

$this->opaque_class>

returns object class as should been seen from Prolog side

Language::Prolog::Types::Opaque::Auto

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.

SEE ALSO

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 :-)

AUTHOR

Salvador Fandiño, <sfandino@yahoo.com>

COPYRIGHT AND LICENSE

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:

Around line 592:

Non-ASCII character seen before =encoding in 'Fandiño,'. Assuming CP1252