Languag...Abstract(3)

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

πŸ’– 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 $term is a valid Prolog term (which, real talk, means a perl number, string or array, or any object descending from Language::Prolog::Types::Term).
  • prolog_is_atom($term) β€” returns true if $term is a valid Prolog atom (again: actually a perl number or string).
  • prolog_is_nil($term) β€” returns true if $term is the Prolog nil value ([]).
  • prolog_is_functor($term) β€” returns true if $term is a Prolog functor.
    • lowkey important note: lists are equivalent to functor '.'/2, so because of that this function will also return true when $term is a list. πŸ™ˆ
  • prolog_is_list($term) β€” returns true if $term is 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. πŸ’€
  • prolog_is_list_or_nil($term) β€” returns true if $term is Prolog nil or a list.
  • prolog_is_variable($term)
  • prolog_is_var($term) β€” both of these return true if $term is a free (unbounded) Prolog variable.
  • prolog_is_ulist($term) β€” returns true if $term is 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. ⚠️

πŸ‘‘ 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 $index on the list. If $index is 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 $index is negative the arguments are indexed begining from the end.
    • be aware: arguments are indexed from 0, not from 1 like in prolog. πŸ™ˆ

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 with Language::Prolog::Types::Nil and this is the reasong, to descent also from this class.

Methods:

  • "$l->car()" β€” returns the list car.
  • "$l->cdr()" β€” returns the list cdr.
  • "$l->car_cdr()" β€” returns both the car and the cdr of 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::Internal contains 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 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