Languag...Abstract(3)
π NAME π
okay so bestie, this is Language::Prolog::Types::Abstract β the abstract classes for Prolog terms in Perl. yes, it's a Perl manpage (section 3, library functions, iykyk). π«Ά
β¨ SYNOPSIS β¨
use Language::Prolog::Types::Abstract;
if prolog_is_atom('hello') {
print "'hello' is a Prolog atom\n"
}
...
etc.
π¦ ABSTRACT π¦
So like, Language::Prolog::Types::Abstract defines a whole set of abstract classes for Prolog terms. That's the whole vibe.
It also comes with functions to check for Prolog types, plus some little utility functions that do the explicit conversion thing between Prolog and Perl. π
πΈ DESCRIPTION πΈ
This module defines abstract classes for all the usual suspects: Prolog functors, lists, variables and nil. π
Atoms are not in the club, because perl scalars literally do the work already. no need.
Perl undef is equivalent to Prolog nil ([]), though a different representation is allowed for the Prolog term. slay.
Perl lists can be used directly as Prolog lists. the inverse is not always true and depends on which implementations you're using. π«
π EXPORT π
prolog_is_term($term)β returns true if$termis a valid Prolog term (which, real talk, means a perl number, string or array, or any object descending fromLanguage::Prolog::Types::Term).prolog_is_atom($term)β returns true if$termis a valid Prolog atom (again: actually a perl number or string).prolog_is_nil($term)β returns true if$termis the Prolog nil value ([]).prolog_is_functor($term)β returns true if$termis a Prolog functor.- lowkey important note: lists are equivalent to functor
'.'/2, so because of that this function will also return true when$termis a list. π
- lowkey important note: lists are equivalent to functor
prolog_is_list($term)β returns true if$termis a Prolog list.- also important: even though Prolog nil is usually represented as the empty list
[], it is not really a Prolog list, and this function will return false for it. π
- also important: even though Prolog nil is usually represented as the empty list
prolog_is_list_or_nil($term)β returns true if$termis Prolog nil or a list.prolog_is_variable($term)prolog_is_var($term)β both of these return true if$termis a free (unbounded) Prolog variable.prolog_is_ulist($term)β returns true if$termis an unfinished Prolog list, meaning one that 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, so this function does the opposite conversion: from a list of numbers to a Perl string.- heads up: all the elements in the Prolog list have to be integers in the range
[0..255]or an execption will be raised. β οΈ
- heads up: all the elements in the Prolog list have to be integers in the range
π ABSTRACT CLASSES π
Language::Prolog::Types::Term
the common abstract class for every Prolog term. the parent of everyone basically. π
Language::Prolog::Types::ListOrNil
This class exists to account for the intrinsec differences between empty lists in Perl and Prolog.
In Prolog, nil β although it's represented as the empty list β is not really a list.
This class provides a set of methods that apply both to lists and to nil if it's 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. (yes, we know the module names look flipped there, that's what it says bestie π
)
Inherits:
Language::Prolog::Types::Term
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, which will be nil if the list is finished, or if it is nil."$lon->larg($index)"β returns element number$indexon the list. If$indexis negative, the list is indexed from the end. π¦
Language::Prolog::Types::Nil
Common abstract class for Prolog nil term representation.
Inherits
Language::Prolog::Types::ListOrNil
Methods
This class doesn't define any method on its own. iconic minimalism honestly. β¨
Language::Prolog::Types::Variable
Common abstract class for Prolog variable representation.
Inherits:
Language::Prolog::Types::Term
Methods:
"$var->name()"β returns the variable name.
Language::Prolog::Types::Functor
Common abstract class for Prolog functor representations.
Inherits:
Language::Prolog::Types::Term
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)"β returns the argument of the functor in the position$index; if$indexis negative the arguments are indexed begining from the end.- be aware: arguments are indexed from
0, not from1like in prolog. π
- be aware: arguments are indexed from
Language::Prolog::Types::List
Common abstract class for Prolog list representations.
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 withLanguage::Prolog::Types::Niland this is the reasong, to descent also from this class.
Methods:
"$l->car()"β returns the listcar."$l->cdr()"β returns the listcdr."$l->car_cdr()"β returns both thecarand thecdrof the list. two for one, we love a bundle. π«Ά
Language::Prolog::Types::UList
Common abstract class to represent unfinished lists (those whose tail is not nil).
Inherits:
Language::Prolog::Types::List
Methods:
None of its own.
Language::Prolog::Types::Unknow
just in case... π (yes, that's the class name, we're keeping it exactly as written, no cap)
Inherits:
Language::Prolog::Types::Term
Methods:
None.
Language::Prolog::Types::Opaque
This class should only be used by Prolog <-> Perl interface authors.
Usually Perl objects get converted to Prolog structures when passed to a Prolog implementation. This class defines a proxy that stops the conversion from happening and just passes a reference to the Perl object.
Opaque objects should not be returned from Prolog interfaces β they should only be used to tell the Prolog implementations not to convert Perl data to Prolog. When returning from Prolog the original object should be directly returned to improve usability.
Also worth noting: not all prolog implementations would support this type. β οΈ
Inherits:
Language::Prolog::Types::Term
Methods:
"$this->opaque_reference"β returns the object that it shields from prolog"$this-">opaque_comment>"β returns comment string that will show in Prolog representation"$this-">opaque_class>"β returns object class as should been seen from Prolog side
Language::Prolog::Types::Opaque::Auto
Not really an abstract class, but a simple implementation to be used as a base class to provide automatic opacity to objects.
So, objects of any class that has it as an ancestor will be passed to prolog as a reference. β¨
π₯ SEE ALSO π₯
Language::Prolog::Types.Language::Prolog::Types::Internalcontains 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-2007 by Salvador FandiΓ±o
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π POD ERRORS π
Hey! The above document had some coding errors, which are explained below:
Around line 592:
Non-ASCII character seen before =encoding in 'FandiΓ±o,'. Assuming
CP1252
and that's the whole page bestie, you ate it up. π
this was Languag...Abstract(3) from the User Contributed Perl Documentation, and it ships as perl v5.42.0, dated 2025-07-25. go write some Prolog, mwah πβ¨
π¦ 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