<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div>Marc,</div><div><br></div><div>Thank you for your reply.  This was exactly what I was looking for.  Is the "Gambit_js2scm" function available in v4.7.2, or will I need to upgrade to the latest code?</div><div><br></div><div>I'm glad to hear you are continuing to improve the universal backend and am excited that first-class continuations are now implemented.  With first-class continuations available are there plans to implement green threads as well?  I've thought that green threads may be a interesting method to implement sprites for a HTML5 game.</div><div><br></div><div><span></span></div><div>Bob</div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
 font-size: 12pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Thursday, March 6, 2014 2:23 AM, Marc Feeley <feeley@iro.umontreal.ca> wrote:<br> </font> </div>  <div class="y_msg_container"><br clear="none">On Mar 5, 2014, at 5:19 PM, Bob Coleman <<a shape="rect" ymailto="mailto:bobcolem@yahoo.com" href="mailto:bobcolem@yahoo.com">bobcolem@yahoo.com</a>> wrote:<br clear="none"><br clear="none">> Greetings,<br clear="none">> <br clear="none">> I have been playing around with the javascript backend and have been impressed with it's capabilities.<br clear="none"><br clear="none">I’m glad you like it.  Over the past week I have made several enhancements with the short term goal of implementing a remote debugger (so that Scheme code running in the browser can be debugged live using a REPL running on the
 server).  Just a few minutes ago I committed the support for first-class continuations which are needed for the exception handling of the REPL.<br clear="none"><br clear="none">>  Interacting with other javascript libraries is not a problem, but I haven't found a way for other javascript code to call scheme defined functions.  Is there a way to define functions to be called by javascript similar to c-lambda or c-define?<br clear="none"><br clear="none">It is quite easy to interface to JavaScript functions from Scheme.  In fact, using JavaScript’s eval gives a much simpler approach than using Gambit’s C interface for the C back-end.  For example, you can define<br clear="none"><br clear="none"> (define js<br clear="none">   (##inline-host-expression "Gambit_js2scm(eval)"))<br clear="none"><br clear="none">This creates a Scheme callable function which performs a JavaScript eval.  Then, in your code you can say:<br
 clear="none"><br clear="none"> (define alert (js "alert"))<br clear="none"> (alert "hello!")<br clear="none"><br clear="none">This will “convert” the JavaScript “alert” function to a Scheme function.<br clear="none"><br clear="none">For the other way around (exporting a Scheme function callable from JavaScript), the js function can be used like this:<br clear="none"><br clear="none"> (define setglo (js "function (name,val) { window[name] = val; }"))<br clear="none"><br clear="none">then<br clear="none"><br clear="none"> (setglo "foo" (lambda (n) (* n n)))<br clear="none"><br clear="none">And then in JavaScript land your can call (foo 10).<br clear="none"><br clear="none">> Also, is it possible to access the value of the -target flag in scheme?  I would like to define some functions differently based on whether the program is being built for the C or javascript backend.<br clear="none"><br clear="none">Define this macro:<br
 clear="none"><br clear="none"> (##define-macro (case-target . clauses)<br clear="none">   (let ((target (if (and (pair? ##compilation-options)<br clear="none">                          (pair? (car ##compilation-options)))<br clear="none">                     (let ((t (assq 'target ##compilation-options)))<br clear="none">                       (if t (cadr t) 'c))<br clear="none">                     'c)))<br clear="none">     (let loop ((clauses clauses))<br clear="none">       (if (pair? clauses)<br clear="none">           (let* ((clause (car clauses))<br clear="none">                  (cases (car clause)))<br clear="none">   
          (if (or (eq? cases 'else)<br clear="none">                     (memq target cases))<br clear="none">                 `(begin ,@(cdr clause))<br clear="none">                 (loop (cdr clauses))))<br clear="none">           `(begin)))))<br clear="none"><br clear="none">and use it like this:<br clear="none"><br clear="none"> (case-target<div class="yqt9712683962" id="yqtfd82890"><br clear="none">   ((c)</div><br clear="none">    (define foo (c-lambda () int "foo")))<br clear="none">   ((js)<br clear="none">    (define foo (lambda () (##inline-host-expression "42")))))<br clear="none"><br clear="none">Marc<br clear="none"><br clear="none"><br clear="none">_______________________________________________<br clear="none">Gambit-list mailing list<br
 clear="none"><a shape="rect" ymailto="mailto:Gambit-list@iro.umontreal.ca" href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br clear="none"><a shape="rect" href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br><br></div>  </div> </div>  </div> </div></body></html>