Languag...g::Types(3)
π Language::Prolog::Types π
okay bestie, so this is a page from the User Contributed Perl Documentation section of the manual, and it's filed under Languag...g::Types(3) because the name was too long for the header, rip. Anyway. Sit down, grab a snack, we're doing Prolog types in Perl. π¦
β¨ NAME β¨
Language::Prolog::Types β Prolog types in Perl. that's it. that's the whole name. π
πΈ SYNOPSIS πΈ
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);
(yes, that missing semicolon on the $functor=F(...) line is canon, I'm not touching it, it's exactly what the page says π«Ά)
π ABSTRACT π
Language::Prolog::Types</purl> is a whole little set of modules that implements Prolog types in Perl. slay.
π DESCRIPTION π
So basically this module exports subroutines that let you create Prolog terms in Perl, test what type a term is, and also some utility functions to explicitly convert data back and forth between Prolog and Perl. it's giving bridge between two worlds, honestly iconic. π
Bestie, listen: there is no kind of constructor for Prolog atoms, and that's not a bug, that's a feature. it's because Perl scalars (numbers or strings) are used directly as Prolog atoms. no middleman. periodt. β¨
You can also use Perl list references as Prolog lists, and Perl undef as Prolog nil ([]). so convenient. π
π§ EXPORT_TAGS π§
The subroutines are grouped into three tags:
π¦ :is π¦
Subroutines to test the typing of terms.
prolog_is_atom($term)β true if$termis a valid Prolog atom (a Perl number or string).prolog_is_nil($term)β true if$termis Prolog nil[]. Perlundefis equivalent to Prolog nil.prolog_is_list($term)β true if$termis a Prolog list.
lowkey important note: Prolog nil, even though it's represented with the empty list [], is not a list. the way that it's just built different. π
prolog_is_list_or_nil($term)β true if$termis a Prolog list or nil. covers both, no cap.prolog_is_functor($term)β true if$termis a Prolog functor.
also worth knowing: lists are formed with the functor '.'/2. yes, a literal dot. iykyk. π
prolog_is_variable($term)prolog_is_var($term)β true if$termis a Prolog variable.prolog_is_ulist($term)β true if$termis a Prolog unfinished list (those whose tail is not nil). the little list that didn't finish. relatable. πprolog_is_string($term)β true if$termcan be converted to a string, i.e. a list whose elements are integers in the range[0..255].
πΈ :ctors πΈ
Subroutines to create new Prolog terms. (the original spells it "Subruotines" and honestly? we stan a typo queen π)
prolog_list(@terms)β returns a new prolog list with elements@terms.prolog_ulist(@terms, $tail)β returns a new prolog unfineshed list with elements@termsand tail$tail. (again, "unfineshed" is straight from the source, keeping it π)prolog_functor($name, @args)β returns a new prolog functor whose name is$nameand whose arguments are@args.prolog_variable($name)prolog_var($name)β returns a new prolog variable with name$name.prolog_atom($atom)β since normal Perl strings and numbers are what represent Prolog atoms, this function literally just makes sure its argument is properly converted to a string. that's it. that's the job. β¨prolog_nil()β returns Prolog nil ([]).prolog_string($string)β returns a Prolog string, which is a list with the ASCII codes of$string.prolog_chain($ftr, $term1, $term2, ..., $termn, $termo)β creates a prolog structure that looks like this:
$ftr($term1,
$ftr($term2,
$ftr($term3,
$ftr(...
$ftr($termn, $termo) ... ))))
and bestie, you should note that
prolog_chain($ftr, $term)
returns
$term
yeah. it just gives you back your term. no extra wrapping. π
prolog_opaque($object)β creates a proxy opaque object that tells Perl to pass the object to Prolog as an opaque reference, one that cannot be used directly from Prolog, but can only be passed back to Perl in callbacks. so like, a little sealed envelope. π
π :util π
Subroutines to convert Prolog data to Perl.
prolog_list2perl_list($term)β converts a Prolog_list to a Perl array, accounting for all the different possibilities of Prolog list representations. all of them. every last one. π€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. so mind your bytes bestie. π«Ά
π :short π
For the lazy programmer β and honestly, we love a lazy programmer, main character energy β :short includes a set of abbreviations 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 π
go read these next, bestie, they're the extended universe:
Language::Prolog::Types::overloadLanguage::Prolog::SugarLanguage::XSB
π COPYRIGHT AND LICENSE π
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.
and that's the whole page, babe β¨ this one came from perl v5.42.0 and it's dated 2025-07-25 β so when you see it in the wild, that's the version and date tag hanging off the bottom of Languag...g::Types(3). love that for us. π π π¦ π
π«Ά
π¦ where this page comes from
- fedora 43: perl-Language-Prolog-Types 0.10-38.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms