Giter Site home page Giter Site logo

perl6-inline-scheme-gambit's Introduction

Actions Status

Inline::Scheme::Gambit

This is a Raku module which allows execution of Gambit Scheme code from Raku code with inspiration from other Inline:: modules like Inline::Python, Inline::Lua, Inline::Scheme::Guile, etc.

Synopsis

use Inline::Scheme::Gambit;

my $gambit = Inline::Scheme::Gambit.new;

my $code = q:to/END/;
    (define (fib n)
     (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
END

$gambit.run($code);
say $gambit.call('fib', 8);

say $gambit.call('map',
                 $gambit.run(q{(lambda (n) (fib n))}),
                 [0 .. 8]);

Status

Testing has only been done under Rakudo MoarVM on x86-64 Linux. It requires Gambit-C 4, and Gambit-C 4.8.3 and 4.2.8 have been tested by the author.

Values can be passed to and returned from Gambit-C. Simple types like boolean, integer, number, string, list, table, vector should work. Present mapping between Gambit-C and Raku types is as following table.

Gambit-C            from Perl                       to Perl
boolean             Bool                            Bool
integer(exact)      Int                             Int
rational(exact)     Rat                             Rat
rational(inexact)   Num                             Num
complex             Complex                         Complex
string              Stringy                         Str
list                Positional                      Array            
table               Associative                     Hash            
vector                                              Array
procedure                                           OpaquePointer
other objects       OpaquePointer                   OpaquePointer

Note that at present both scheme list and vector converts to Array in Raku, but through the call() method (see below) Raku Array only converts to list.

The API is incomplete and experimental. It may change in future if necessary.

To Do

  • Think about wrapping OpaquePointer for scheme-object, so that it can do better on scheme list/vector/procedure/etc.
  • Support scheme record type.
  • Improve error handling.

Install

zef install Inline::Scheme::Gambit

It by default tries to use 'gsc-script' or 'gsc' as the gsc command, and dynamically link to libgambc.so. It supports several environment variables to override the default behavior.

For example to override gsc in case 'gsc-script' or 'gsc' is not in PATH, or 'gsc-script' is an incorrect symlink.

GSC=/usr/bin/gsc zef install Inline::Scheme::Gambit

And if on your system gambit dll is not named libgambc.so, you can override it like below,

LIBS="-l:libgambit.so.4" zef install Inline::Scheme::Gambit

Or if you would like to static link to some libgambit.a

LIBS=-lutil MYEXTLIB=/usr/lib/gambit-c/libgambit.a zef install Inline::Scheme::Gambit

You can refer to Makefile.in and Build.pm to know more details.

Usage

Inline::Scheme::Gambit

Object of Inline::Scheme::Gambit represents a global Gambit-C instance.

method new()

Returns the global Inline::Scheme::Gambit singleton. The first call to new() initializes the singleton.

method run(Str:D $code)

Runs $code and returns any resulting value.

method call(Str:D $name, **@args)

Calls the named function with @args, and returns any resulting value.

Contact

https://github.com/iynehz/perl6-Inline-Scheme-Gambit

perl6-inline-scheme-gambit's People

Contributors

b2gills avatar iynehz avatar jjatria avatar samcv avatar zoffixznet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

perl6-inline-scheme-gambit's Issues

Broken on recent versions of Raku

Good on:

  • Raku 2020.12, Debian 11

Broken on:

  • Raku 2022.02, Ubuntu 22.04
  • Raku 2022.12, Ubuntu 22.04
  • Raku 2022.12, Debian 11

Error is like (after successful zef build .)

$ prove6 -Ilib t/call.t 
(Argument 1) PROCEDURE expected
(map 0 0)

  in method handle_exception at /mnt/home/zhenyz/git/perl6-Inline-Scheme-Gambit/lib/Inline/Scheme/Gambit.rakumod (Inline::Scheme::Gambit) line 289
  in method call at /mnt/home/zhenyz/git/perl6-Inline-Scheme-Gambit/lib/Inline/Scheme/Gambit.rakumod (Inline::Scheme::Gambit) line 311
  in method call at /mnt/home/zhenyz/git/perl6-Inline-Scheme-Gambit/lib/Inline/Scheme/Gambit.rakumod (Inline::Scheme::Gambit) line 305
  in block <unit> at t/call.t line 13

t/call.t ..1/?              t/call.t .. Dubious, test returned 1
All 1 subtests passed 
All tests successful.

Test Summary Report
-------------------
t/call.t (Wstat: 256 Tests: 1 Failed: 0)
Non-zero exit status: 1
  Parse errors: No plan found in TAP output
Files=1, Tests=1,  0 wallclock secs
Result: FAILED

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.