Languag...nverter(3)

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

πŸ‘‘ Language::Prolog::Types::Converter β€” the glow-up edition πŸ’…

okay bestie, so this is a page from the User Contributed Perl Documentation, manual section 3, and it's all about Language::Prolog::Types::Converter. pull up a chair, we're converting Perl stuff into Prolog stuff and it's gonna be cute πŸŽ€


✨ NAME ✨

Language::Prolog::Types::Converter β€” converts from Perl objects to Prolog terms. literally its whole personality πŸ¦‹


🌸 SYNOPSIS 🌸

here's the vibe, copy it exactly bestie:

package MyModule;

use Language::Prolog::Types::Converter;
our @ISA=qw(Language::Prolog::Types::Converter);

sub hash2prolog {
    ...
}

sub scalar2prolog {
    ...
}

etc.

πŸ’– ABSTRACT πŸ’–

so this module implements a class that you use from interfaces to Prolog systems (SWI-Prolog, XSB, etc.) to transform complex Perl data types into Prolog types. it's the little translator bestie that makes the two of them get along 🫢


🌈 DESCRIPTION 🌈

you should use this module if you want to change the default conversions performed when passing data between Perl and Prolog. that's the assignment, periodt ✨

🧚 METHODS 🧚

  • Language::Prolog::Types::Converter->new() β€” returns a new converter object. brand new, fresh out the box, main character energy πŸ‘‘
  • $self->pass_as_opaque($class1, $class2, ...) β€” instructs the converter object to pass objects belonging to classes class1, class2, etc. to Prolog as opaque objects. the Prolog interpreter will not touch them, it just uses them in Perl call backs. hands off, she's not yours πŸ’…

so to override the default conversions performed, you have to redefine the method perl_ref2prolog.

and if you make your converter class inherit Language::Prolog::Types::Converter, you can change conversions only for selected types by overriding these methods:

  • $conv->hash2prolog($hash_ref) β€” converts a Perl hash reference to a Prolog term.

it creates a list of functors '=>/2' with the key/value pairs as arguments:

[ '=>'(key0, value0), '=>'(key1, value1), ... ]
  • $conv->scalar2prolog($scalar_ref) β€” converts a Perl scalar reference to a Prolog term.
  • $conv->glob2prolog($glob_ref) β€” converts a Perl glob reference to a Prolog term.
  • $conv->code2prolog($code_ref) β€” converts a Perl sub reference to a Prolog term.
  • $conv->object2prolog($object_ref) β€” converts any other Perl object to a Prolog term.

the default implementation looks for a method called convert2prolog_term in the object class. πŸ”

if this fails, it reverts to dumping the internal representation of the object as the functor:

perl_object(class, state)

"state" is the conversion of the perl datatype used to represent the object (array, hash, scalar, glob or sub). so yeah, plan B is literally just "show them the insides" 😭 iconic honestly


πŸŽ€ EXPORT πŸŽ€

none by default. this module has an OO interface. no sneaky exports, she does not do that πŸ™ˆ


⭐ SEE ALSO ⭐

  • Language::Prolog::Types
  • Language::XSB::Base
  • Language::Prolog::Yaswi::Low

go read those too, iykyk πŸ”₯


πŸ’œ AUTHOR πŸ’œ

Salvador FandiΓ±o, <sfandino@yahoo.com>


Copyright 2002 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 210:

Non-ASCII character seen before =encoding in 'FandiΓ±o,'. Assuming
CP1252

not the ñ catching strays 😭 bestie the encoding said what it said


and that's the whole page, no cap πŸ’– this was perl v5.42.0, dated 2025-07-25, straight from Languag...nverter(3) β€” mwah, slay, go convert some stuff βœ¨πŸ’…πŸ¦‹

πŸ“¦ where this page comes from