Guile

Inline::Scheme::Guile

Inline::Scheme::Guile is a Perl 6 binding to GNU Guile Scheme.

Synopsis

use Inline::Scheme::Guile;
my $g = Inline::Scheme::Guile.new;
    say "Scheme says 3 + 4 is " ~ $g.run('(+ 3 4)');
say "Scheme says 3 + 4 is " ~ $g.call( '+', 3, 4 );

Documentation

You obviously need to have Guile Scheme (https://www.gnu.org/software/guile/manual/guile.html) installed in order for this module to work. At some point an Alien:: package may be created to help this process. I'd prefer to have a proper repository but that would be even more yak shaving.

You can pass any Scheme code you like to the running Guile compiler, and it will respond with the return value(s) from the result of executing that expression. For a full list of object types, it's probably best to look at the test suite, but here's a brief summary of the important types:

  • nil

Unsurprisingly, maps to the Nil object in Perl 6.

  1. f

Maps to False in Perl 6.

  1. t

Maps to True

  • Integers

Those that fit into int32 map onto a regular Int in Perl 6. More research is needed for wider types as of this writing.

  • Rationals

Map onto a Perl 6 rational, with a denominator and numerator part.

  • Complex numbers

Map onto a Perl 6 complex value, with a real and imaginary part.

  • Strings

Map to the Str type.

  • Symbols ('foo)

Map onto the (somewhat unwieldy) Inline::Scheme::Guile::Symbol type. These have simply a :name('foo') attribute.

'foo expands to the macro (quote foo) inside vectors, lists and pairs. So don't expect to find the ::Symbol inside these constructs.

  • Keywords (#:foo)

Map onto the (somewhat unwieldy) Inline::Scheme::Guile::Keyword type. These have simply a :name('foo') attribute.

Keywords don't have an equivalent quoted form, so they will appear verbatim in lists, vectors and such.

  • List ('(1 2 3))

Map onto an array reference. See below about multiple-value returns to see why this was chosen.

  • Vector (#(1 2 3))

Map onto the (somewhat unwieldy) Inline::Scheme::Guile::Vector type. These have a :values(1,2,3) attribute storing the values in the vector.

Scheme functions can return a single value, or more than one value. This is not the same as a Scheme function returning a list of values. For instance:

$g.run('3') returns just the value 3.

$g.run('(+ 3 4)') returns just the value 7.

$g.run( q{'(3 4)} ) returns a list reference [3, 4].

$g.run( q{(values 3 4)} ) returns two values, (3, 4).

Multiple-value return is the main reason why lists are array references, rather than lists in and of themselves. Also, sometimes (most of the time (no, really)) lists are nested, and the inner layer would have to be a list reference anyway, so for consistency's sake all lists are considered references.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.