Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Introducing Scheme In Perl 6

by DrForr (Beadle)
on Jan 25, 2016 at 21:13 UTC ( [id://1153610]=perlnews: print w/replies, xml ) Need Help??

Introducing Scheme in Perl 6: Inline::Guile

It's currently in a very primitive state, supporting as it does only returning integers and strings. Once I figure out how to portably crack into an SCM return value, that should change drastically. Basically it lets you do the following:
use Inline::Scheme; say Inline::Scheme.new.run_i('(+ 2 (/ 27 3))');
Which is to say "Pass (+ 2 (/ 27 3))' off to the Scheme interpreter and tell me the result. I'm actually intending to uild another language on top of this, so it'll eventually be able to pass and return complex data structures, but that might have to wait until I can actually run the interpreter in a separate thread.

Replies are listed 'Best First'.
Re: Introducing Scheme In Perl 6
by grondilu (Friar) on Jan 29, 2016 at 02:39 UTC

    Nice. Do you plan on making it a slang as well?

      Yeah, once I've gotten the binding down I hope to be able to do something like:
      use Slang::Scheme::Guile; guile-sub add( $a, $b ) { + $a $b } say add(1,3); # 4
      because my *ultimate* goal is to use this to embed the logic programming language Kanren into Perl 6, which is a set of Scheme primitives that provide goal-searching and backtracking. You could do something like:
      use Slang::Kanren; kanren-fact parent('marcia','jeff'); kanren-fact parent('mike','jeff'); kanren-fact parent('gerald','mike'); # Find out if Jeff shares a common parent with Gerald kanren-goal { parent('gerald',X), parent(X,'jeff') }
      This is of course fairly abstract, and I haven't really researched what the function binding is, I've been working more on the Scheme side.
Re: Introducing Scheme In Perl 6
by jdporter (Paladin) on Jan 29, 2016 at 18:05 UTC

    Wouldn't it be more productive -- not to mention more useful -- to build a native Scheme frontend for the MoarVM?

      Scheme running on MoarVM would be nice, to be sure, if only to prove that it can be done. It would be several orders of magnitude slower because modern Scheme compilers (like modern Lisps) compile to machine code.

      Connecting to the interpreter thread is one function call, and unmarshalling back to Perl 6 is a very simple and fast callback, I expect that most of the time spent on a single invocation of $g.run('(+ 5 4)') is in the unmarshalling of the single SCM cons cell back to Perl 6.

      As to being more productive, I suppose I could have taken several months to learn MoarVM, read R6RS, do two or three test implementations until I worked out the approach, lost D20 SAN implementing call/cc, and gotten for my efforts a trivial Scheme running hundreds of times slower than any actual working implementation, and then still would have to write the Perl 6 - Scheme bridge, this time on MoarVM.

      Or I could take a few nights to read the GNU Guile docs, write a 200-line helper library, and get Perl 6 quickly talking to a fast, debugged, and more importantly working Scheme implementation. Perl 6 is -Ofun, and while doing all of the MoarVM backfill may be fun to some, and maybe if I get into it it'd be fun to me, but right now it's someone else's itch to scratch.

      All in all, I'll take the NativeCall route, and let someone that knows the MoarVM innards and loves the challenge of building a new grammar, AST generator, compiler and debugging the entire toolchain do the work. Life's too short.

        I suppose it depends on what you intend to use it for; but I for one don't see a whole lot of utility in being able merely to call out to another language as a black box, like a coprocessor. I'd want my scheme (or whatever) code to be able to access my perl code & variables, just as if it were written in perl. Using a common machine like MoarVM or JVM makes this possible.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlnews [id://1153610]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found