[gambit-list] Using the JavaScript back-end

Blake McBride blake at mcbride.name
Tue Feb 3 10:13:04 EST 2015


I did a git pull and rebuilt everything.  Same error.  Note that node
doesn't have a "print" function.

Thanks.

Blake

On Mon, Feb 2, 2015 at 8:26 AM, Marc Feeley <feeley at iro.umontreal.ca> wrote:

> You have to pull the latest version from the github repo.
>
> Marc
>
> > On Feb 1, 2015, at 11:35 PM, Blake McBride <blake at mcbride.name> wrote:
> >
> > Here is the result of your example:
> >
> > $ gsc -c -target js f1.scm
> > $ node f1.js
> >
> > /home/blake/gambit/f1.js:448
> >   print(obj);
> >   ^
> > ReferenceError: print is not defined
> >     at gambit_println (/home/blake/gambit/f1.js:448:3)
> >     at gambit_bb1_println (/home/blake/gambit/f1.js:323:3)
> >     at gambit_trampoline (/home/blake/gambit/f1.js:348:10)
> >     at Object.<anonymous> (/home/blake/gambit/f1.js:688:1)
> >     at Module._compile (module.js:456:26)
> >     at Object.Module._extensions..js (module.js:474:10)
> >     at Module.load (module.js:356:32)
> >     at Function.Module._load (module.js:312:12)
> >     at Function.Module.runMain (module.js:497:10)
> >     at startup (node.js:119:16)
> > $
> >
> >
> > In any case, here is a simple example and instructions on how to run the
> code in a JS shell and in the browser.  If you want to use non-primitive
> predefined Scheme library functions (such as equal?, append, map, write,
> etc) you will need to look into univ-lib .  The goal is to have all of this
> neatly packaged in gsc so that one invocation of gsc will do all that is
> necessary.  One issue is linking… should the .js file contain all of the
> application code including Scheme libraries, or should it contain just the
> code for the compiled file (so that it can be dynamically loaded by the web
> page)?  Both should be supported with an appropriate compile flag.
> >
> > Marc
> >
> >
> > ;; File: fib.scm
> > ;;
> > ;; compile with: gsc -c -target js fib.scm
> > ;;
> > ;; execute with: d8 fib.js
> > ;;
> > ;; or use it in an HTML page like this:
> > ;;
> > ;; <!DOCTYPE html>
> > ;; <html>
> > ;; <head>
> > ;;     <title>fib</title>
> > ;;     <script type="text/javascript">
> > ;;         function print(x) { console.log(x); }
> > ;;     </script>
> > ;;     <script type="text/javascript" src="fib.js"></script>
> > ;; </head>
> > ;; <body></body>
> > ;; </html>
> >
> > (declare
> >   (standard-bindings)
> >   (extended-bindings)
> >   (not safe)
> >   (fixnum)
> >   (block)
> > )
> >
> > (define (fib n)
> >
> >   (define (fib n)
> >     (if (< n 2)
> >         n
> >         (+ (fib (- n 1))
> >            (fib (- n 2)))))
> >
> >   (fib n))
> >
> > (define start (real-time-milliseconds))
> >
> > (println (fib 30))
> >
> > (define end (real-time-milliseconds))
> >
> > (println (- end start))
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20150203/3aba4e62/attachment.htm>


More information about the Gambit-list mailing list