Introducing Scheme in Perl 6
Introducing Scheme in Perl 6: https://github.com/drforr/perl6-Inline-Guile
This is very much in its early days, and the interface is likely to change as I find the method(s) in the Guile library that I need. Specifically once I can figure out how to portably crack into a SCM return value the need for separate _i and _s functions should go away. Perl 6 is perfectly capable of making the distinction, but it's a segfault waiting to happen from C should I get the return values wrong.
Also I need to cleanly dispose of the returned string, as it is it'll leak memory.
Or I just need to use the appropriate scm_$type_p predicates. Strings need dynwind-protect in order to not leak, and I've partially figured out list return values. It'll probably eventually look something like:
my @out = Inline::Guile.run(q{'(a "b" 3)});
is-deeply \@out, [ Inline::Guile::Atom.new('a'), "b", 3 ];
Maybe even a Slang to go with it:
guile-sub car ( $x ) { car $x }
guile-sub cdr ( $x) { cdr $x }
is car( <a b c> ), 'a';
is-deeply \cdr( <a b c> ), [ 'b', 'c' ];
It'll also be easier if I generate my C binding code directly from Perl 6, so the Perl 6, C and Guile Scheme code all share the same constants. I am so going to h*ll for t
I've renamed it to Inline::Scheme::Guile in case anyone wants to do Racket or SIOD or something after me.
Also, multiple values now work, so:
is-deeply [ $g.run( q{(values 3 2 1)} ) ], [ 3, 2 1 ];
passes. I'll see about getting lists working at FOSDEM, it might be time to look at properly implementing Perl 6 -> Scheme variable marshalling.