Language::Prolog::Types - Prolog types in Perl.
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);
Language::Prolog::Types is a set of modules implementing Prolog types in Perl.
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 ([]).
undef
[]
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).
$term
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.
@terms
prolog_ulist(@terms, $tail)
returns a new prolog unfineshed list with elements @terms and tail $tail.
$tail
prolog_functor($name, @args)
returns a new prolog functor which name $name and arguments @args.
$name
@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.
$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
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)
Language::Prolog::Types::overload
Language::Prolog::Sugar
Language::XSB
Copyright 2002-2005, 2007 by Salvador Fandiño <sfandino@yahoo.com>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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.