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:
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.
Inherits
Methods
This class doesn't define any method on its own.
Inherits:
Methods:
Inherits:
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)
-
return the argument of the functor in the position
$index
, if$index
is negative the arguments are indexed begining from the end.
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 thecdr
of the list.
- Language::Prolog::Types::UList
-
Common abstract class to represent unfinished lists (those whose tail is not nil).
Inherits:
Methods:
None of its own.
Inherits:
Methods:
None.
SEE ALSO
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 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
15 POD Errors
The following errors were encountered while parsing the POD:
- Around line 246:
You forgot a '=back' before '=head3'
- Around line 291:
'=item' outside of any '=over'
- Around line 295:
You forgot a '=back' before '=head3'
- Around line 312:
'=item' outside of any '=over'
- Around line 316:
You forgot a '=back' before '=head3'
- Around line 343:
'=item' outside of any '=over'
- Around line 347:
You forgot a '=back' before '=head3'
- Around line 390:
'=item' outside of any '=over'
- Around line 394:
You forgot a '=back' before '=head3'
- Around line 455:
'=item' outside of any '=over'
- Around line 460:
You forgot a '=back' before '=head3'
- Around line 479:
'=item' outside of any '=over'
- Around line 483:
You forgot a '=back' before '=head3'
- Around line 503:
=back without =over
- Around line 522:
Non-ASCII character seen before =encoding in 'Fandiño,'. Assuming CP1252