Languag...g::Types(3)

πŸ“¦
version 0.10 Β· 2 versions
, in fedora 43

πŸ’– 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 $term is a valid Prolog atom (a 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 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 $term is a Prolog list or nil. covers both, no cap.
  • prolog_is_functor($term) β€” true if $term is 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 $term is a Prolog variable.
  • prolog_is_ulist($term) β€” true if $term is a Prolog unfinished list (those whose tail is not nil). the little list that didn't finish. relatable. πŸ™ˆ
  • prolog_is_string($term) β€” true if $term can 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 @terms and tail $tail. (again, "unfineshed" is straight from the source, keeping it πŸ’€)
  • prolog_functor($name, @args) β€” returns a new prolog functor whose name is $name and 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::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.


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