Language::Prolog::Types - Prolog types in Perl.


Language-Prolog-Types documentation Contained in the Language-Prolog-Types distribution.

Index


Code Index:

NAME

Top

Language::Prolog::Types - Prolog types in Perl.

SYNOPSIS

Top

  use Language::Prolog::Types::overload;

  use Language::Prolog::Types qw(:ctors);

  $atom=prolog_atom('foo');
  $list=prolog_list(1,2,3,4,5);
  $functor=prolog_functor('foo',1,2,3,'bar');
  $nil=prolog_nil;




  use Language::Prolog::Types qw(:is);

  print "$atom is an atom\n" if prolog_is_atom($atom);
  print "$list is a list\n" if prolog_is_list($list);
  print "$nil is nil\n" if prolog_is_nil($nil);




  use Language::Prolog::Types qw(:short);

  $atom=A('foo');
  $list=L(1,2,3,4);
  $functor=F('foo',1,2,3,'bar')

  print "$atom is an atom\n" if isA($atom);
  print "$list is a list\n" if isL($list);
  print "$nil is nil\n" if isN($nil);







ABSTRACT

Top

Language::Prolog::Types is a set of modules implementing Prolog types in Perl.

DESCRIPTION

Top

This module exports subroutines to create Prolog terms in Perl, to test term types and also some utility functions to convert data between Prolog and Perl explicitly.

You will see that there is not any kind of constructor for Prolog atoms, this is because Perl scalars (numbers or strings) are directly used as Prolog atoms.

You can also use Perl list references as Prolog lists, and Perl undef as Prolog nil ([]).

EXPORT_TAGS

Subroutines are grouped in three tags:

:is

Subroutines to test typing of terms.

prolog_is_atom($term)

true if $term is a valid Prolog atom (Perl number or string).

prolog_is_nil($term)

true if $term is Prolog nil []. Perl undef is equivalent to Prolog nil.

prolog_is_list($term)

true if $term is Prolog list.

It should be noted that Prolog nil although represented with the empty list [] is not a list.

prolog_is_list_or_nil($term)

true if $term is a Prolog list or nil.

prolog_is_functor($term)

true if $term is a Prolog functor.

It should be noted that list are formed with the functor '.'/2.

prolog_is_variable($term)
prolog_is_var($term)

true if $term is a Prolog variable.

prolog_is_ulist($term)

true if $term is a Prolog unfinished list (those whose tail is not nil).

prolog_is_string($term)

true if $term can be converted to a string, a list whose elements are integers in the range [0..255].

:ctors

Subruotines to create new Prolog terms.

prolog_list(@terms)

returns a new prolog list with elements @terms.

prolog_ulist(@terms, $tail)

returns a new prolog unfineshed list with elements @terms and tail $tail.

prolog_functor($name, @args)

returns a new prolog functor which name $name and arguments @args.

prolog_variable($name)
prolog_var($name)

returns a new prolog variable with name $name.

prolog_atom($atom)

As normal Perl strings and numbers are used to represent Prolog atoms this function only ensures that its argument is properly converted to a string.

prolog_nil()

returns Prolog nil ([]).

prolog_string($string)

returns Prolog string, that is a list with the ASCII codes of $string.

prolog_chain($ftr, $term1, $term2, ..., $termn, $termo)

creates prolog structure

  $ftr($term1,
       $ftr($term2,
            $ftr($term3,
                 $ftr(...
                          $ftr($termn, $termo) ... ))))

it should be noted that

  prolog_chain($ftr, $term)

returns

  $term

prolog_opaque($object)

creates a proxy opaque object to tell Perl to pass the object to Prolog as an opaque reference that can not be directly used from Prolog but just passed back to Perl in callbacks.

:util

Subroutines to convert Prolog data to Perl.

prolog_list2perl_list($term)

converts a Prolog_list to a Perl array acounting for all the different possibilities of Prolog list representations.

prolog_list2perl_string($term)

converts a Prolog list to a Perl string. All the elements in the list have to be integers in the range [0..255] or an exception will be raised.

:short

For the lazy programmer, :short includes a set of abreviations for the :is and :ctors groups:

isL($term)
isUL($term)
isF($term)
isV($term)
isA($term)
isN($term)
isS($term)
L(@terms)
UL(@terms, $tail)
F($name, @args)
V($name)
A($atom)
N()
S($string)
C($term1, $term2, ..., $termn, $termo)

SEE ALSO

Top

Language::Prolog::Types::overload

Language::Prolog::Sugar

Language::XSB

COPYRIGHT AND LICENSE

Top


Language-Prolog-Types documentation Contained in the Language-Prolog-Types distribution.

package Language::Prolog::Types;

our $VERSION = '0.10';

use strict;
use warnings;

use Carp;

require Exporter;
our @ISA=qw(Exporter);
our %EXPORT_TAGS = ( is => [qw( prolog_is_term
				prolog_is_atom
				prolog_is_nil
				prolog_is_list
				prolog_is_list_or_nil
				prolog_is_functor
				prolog_is_variable
				prolog_is_var
				prolog_is_ulist
				prolog_is_string )],
		     ctors => [qw( prolog_list
				   prolog_ulist
				   prolog_functor
				   prolog_variable
				   prolog_variables
				   prolog_var
				   prolog_vars
				   prolog_atom
				   prolog_nil
				   prolog_string
				   prolog_chain
				   prolog_opaque )],
		     util => [qw( prolog_list2perl_list
				  prolog_list2perl_string )],
		     short => [qw( isL
				   isUL
				   isF
				   isV
				   isA
				   isN
				   isS
				   L
				   UL
				   F
				   V
				   Vs
				   A
				   N
				   S
				   C )] );

our @EXPORT_OK=map { @{$EXPORT_TAGS{$_}} } keys(%EXPORT_TAGS);
our @EXPORT=();

use Language::Prolog::Types::Internal;

# ctors come from ...::Types::Factory:
use Language::Prolog::Types::Factory;

# sets default factory to ...::Types::Internal one
Language::Prolog::Types::Factory::set_factory
    Language::Prolog::Types::Internal->new_factory();

# prolog_is_* functions come from ...::Types::Abstract:
use Language::Prolog::Types::Abstract;



# short aliases for constructors
*L=\&prolog_list;
*UL=\&prolog_ulist;
*F=\&prolog_functor;
*V=\&prolog_variable;
*Vs=\&prolog_variables;
*A=\&prolog_atom;
*N=\&prolog_nil;
*S=\&prolog_string;
*C=\&prolog_chain;

# short aliases for is* functions
*isL=\&prolog_is_list;
*isUL=\&prolog_is_ulist;
*isF=\&prolog_is_functor;
*isV=\&prolog_is_variable;
*isA=\&prolog_is_atom;
*isN=\&prolog_is_nil;
*isS=\&prolog_is_string;


1;
__END__
# Below is stub documentation for your module. You'd better edit it!