<div dir="ltr">Sires,<br><br>I got the Gambit Javascript Backend working suiting my needs yesterday. It was somewhat difficult and a little overworking, but I got my needed results.<br><br>Since the job to do so is not trivial, I'm posting my steps, here, to let it documented. Maybe, as my work advances, I can create an article on Medium, to show everybody how to create small, efficient and compiled scheme applications in the web.<br><br>My objectives were:<br><br>1 - To compile scheme scripts in Javascript, to import them from Javascript projects or from any language running on Javascript or compiling to Javascript. So, interpreters, like BiwaScheme, or Chibi-Scheme on WebASM wouldn't suit. If I couldn't achieve this objective, I would try a workaround with some Scheme interpreter in Javascript.<br><br>2 - These compiled scripts be small, or very small, since the algorithms I need to compile to Javascript are simple, only to make some numeric analysis, and User Interface manipulation in real time. Javascript has a very good performance to do these tasks, but the language is cumbersome to program these kinds of programs. I know this is a matter of opinion, but, in my opinion, scheme is better than Javascript to do this due scheme consistency and clarity.<br><br>3 - I would need to call to and from javascript native calls, to enable interoperability. Usually, scheme environments and native environment are orthogonal, due Scheme specificities (like call/cc and required TCO), but this orthogonality is no problem to me, since I can wrap the compiled scheme code in a consistent Javascript interface.<br><br>4 - The language to be compiled needed to be TRUE SCHEME. No Common-Lisp, nor Scheme-Like, nor Clojure. Clojure has a very competent Javascript Compiler, but, as a language, it's not suitable to be, due its complexity and compromises, regarding TCO and continuations.<br><br>Considering these objectives, I started to look for scheme->javascript COMPILERS, not interpreters. As a matter of fact, I've been using BiwaScheme as a Scheme interpreter in Javascript, and the only thing I'm really missing is syntax-case and syntax-rules macros, since BiwaScheme doesn't support define-syntax clauses. I've had some performance problems with BiwaScheme, but I've realized, during the experiments I was perfoming with Biwa and other compiled Schemes, that these performance issues are due my misuse of the interpreter, not due BiwaScheme properties. BiwaScheme has an excellent call/cc and TCO implementation, and if the algorithms use these, avoiding populating the stack (which access in BiwaScheme is slow), this Scheme implementation performs really well.<br><br>So, I decided to try these Scheme->Javascript compilers:<br><br>1 - Spock, from Chicken scheme.<br>2 - Gambit-C Javascript Compiler.<br>3 - Whalesong or RacketScript, from the Racket Project.<br>4 - Scheme2JS<br><br>I thought Whalesong and RacketScript somewhat low documented, although belonging to a huge project like Racket. So I decided to pass it. And I didn't want to deal with the huge complexity of Racket - I needed a more focused Scheme project to deal, since these smaller projects, by the rule, have more approachable people to deal with. My choice on Gambit has just proved this point. Other point, is that I would need to hack any Scheme->Javascript compiler, and in a smaller, more focused, project, it's easier to do.<br><br>Scheme2JS uses the GPL license, and, since I'll need to distribute my software in a proprietary format, although I think I could (and I will) open-source the entire Javascript Scheme Stack I'm developing, I discarded Scheme2JS as as an option.<br><br>The other two options were Spock and Gambit-C. After reading this article: <a href="http://www.schemeworkshop.org/2012/papers/thivierge-feeley-paper-sfp12.pdf">http://www.schemeworkshop.org/2012/papers/thivierge-feeley-paper-sfp12.pdf</a>, I decided to give Gambit-C a try.<br><br>Since I'm using windows as operating system, I installed Gambit from Chocolatey and tried to use the information I've gotten from the Gambit mail group to compile some Javascript code. No success with default Gambit installation from Chocolatey (version 4.6.6).<br><br>Then I tried a more up to date version, from Gambit web site (version 4.9.3). No success at all. So, I contacted the newsgroup by myself, with my doubts, and I realized that Javascript Backend is an experimental one, so I decided to use a very up to date version of Gambit, from source code repository, in Github.<br><br>No success too. So I decided to hack the Javascript created by Gambit, and I realized that this javascript, although complex, is very, very readable - and I discovered that the generated code has some undeclared objects (mainly the Gambit object), with procedural functions replacing their previous usage. So I decided to hack this generated code and, voilà, the script worked suitably in Node.js and in Web browser (Firefox and Chrome).<br><br>This process has been a little cumbersome and overworking, but the results were beautiful. <br><br>I started the process installing MSYS2 from Chocolatey:<br><br>;; Windows CMD Shell:<br>> choco install -y msys2<br><br>Then, after installing msys2, I loaded the bash shell, and installed the development environment:<br><br>;; MSYS2 Bash Shell:<br>$ pacman -Syu<br>$ pacman -S base-devel gcc git<br><br>Then, my computer was ready to build Gambit-C. The next steps can be done in a Linux and MacOS X machines, as well, since they have the correct tools installed.<br><br>I created a directory to receive the Gambit code, then I download its source from Github, compiled it and installed it in a specific directory on my computer, to avoid clashes with the default installed Gambit distribution:<br><br>;; MSYS2 Bash Shell:<br>$ git clone git@github.com:gambit/gambit.git<br>$ cd gambit<br>$ git log # To show the EXACT version of the repository, if you want to repeat this process I'm presenting here, without any surprise:<br>commit 55a0b75ed9391c6e27475b251bd2bb9babfd9aab (HEAD -> master, origin/master, origin/HEAD)<br>Author: Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>><br>Date: Tue Jul 16 08:46:48 2019 -0400<br><br> Don't ignore the settings parameter of ##open-predefined<br> <br>...<br>Other commit information...<br>...<br>...<br>$ ./configure --prefix=/c/tools/gambit-c --enable-cplusplus --enable-c-opt --enable-gcc-opts --enable-shared --enable-single-host<br>configure: loading site script /etc/config.site<br>checking build system type... x86_64-pc-msys<br>checking host system type... x86_64-pc-msys<br>checking target system type... x86_64-pc-msys<br>checking for gcc... gcc<br>checking whether the C compiler works... yes<br>...<br>Lots of output!!!<br>...<br>...<br>$ make<br>making all in include<br>make[1]: Entering directory '/c/Users/.../gambit/include'<br>make[1]: Leaving directory '/c/Users/.../gambit/include'<br>making all in lib<br>make[1]: Entering directory '/c/Users/.../gambit/lib'<br>making deselect-gen-for-commit in gambit<br>...<br>Lots of output!!!<br>...<br>...<br>$ make install<br>...<br>...<br>Lots of output!!!<br>...<br>...<br><br>On you need to update suitably the next environment variables:<br>* LIBRARY_PATH: add "/tools/gambit-c/lib directory or the correspondent directory you installed gambit."<br>* INCLUDE: add "/tools/gambit-c/include directory or the correspondent directory you installed gambit."<br>* LIB: add "/tools/gambit-c/lib directory or the correspondent directory you installed gambit."<br>* CPATH: add "/tools/gambit-c/lib directory or the correspondent directory you installed gambit."<br>* PATH: : add "/tools/gambit-c/lib and /tools/gambit/bin directories or the correspondent directories you installed gambit."<br><br>After that, you need to return to your gambit source code folder and build the Gambit javascript library:<br><br>;; MSYS2 Bash Shell, going to the gambit source, downloaded from Git:<br>$ cd gambit<br><br>Then, go to the lib directory, and build the Javascript runtime:<br><br>;; MSYS2 Bash Shell:<br>$ cd lib<br>$ make _gambit.js # This command finally build the needed Gambit Javascript runtime<br>LD_LIBRARY_PATH=..: ../gsc/gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(define-cond-expand-feature|enable-type-checking|)(define-cond-expand-feature|disable-auto-forcing|)(define-cond-expand-feature|enable-sharp-dot|)(define-cond-expand-feature|enable-bignum|)(define-cond-expand-feature|enable-ratnum|)(define-cond-expand-feature|enable-cpxnum|)(define-cond-expand-feature|disable-smp|)(##include\"../lib/header.scm\")" -o _gambit.js ../lib/_univlib.scm<br>$ cp _gambit.js /c/tools/gambit-c/lib/_gambit.js # This command publish the Javascript runtime to the installed Gambit-C.<br>$<br><br>At this point, the Gambit-C Javascript Backend is fully installed. Maintain Gambit-C source code in this state, in the case of any future updates, which can be common, since the Javascript backend is experimental.<br><br>Now, we need to build and execute a sample. You can build such sample with the next instructions.<br><br>First, in a suitable place, create a directory:<br><br>;; MSYS2 bash (assuming the new installed Gambit is in PATH, and all other environment variables are set)<br>$ mkdir test<br>$ cd test<br><br>Initialize the folder as an NPM project, to use Uglify-JS to minify a little the generated files. The minification isn't very efficient, but improve the file sizes. You need to install npm and put it on path:<br><br>;; Windows CMD Shell, with Administrative roles:<br>> choco install -y npm<br><br>Then, in the created test directory, perform the next proceedings:<br>;; MSYS2 bash<br>$ npm init<br>... Accept all given options, or customize them in according to your needs.<br>$ npm i uglify-js<br><br>Then, now, create the files below:<br><br>;; FILE app.scm<br>(declare (standard-bindings) (extended-bindings) (not safe) (not run-time-bindings))<br><br>(println ">>> app.scm")<br><br>(define (fib n)<br> (fib-iter 1 0 n))<br><br>(define (fib-iter a b count)<br> (if (= count 0)<br> b<br> (fib-iter (+ a b) a (- count 1))))<br><br>(for-each<br> (lambda (x)<br> (println (fib x)))<br> (append '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)<br> '(16 17 18 19 20 21 22 23 24 25 26 27 28 29 30)))<br><br>(let* ((start (current-milliseconds))<br> (result (fib 35))<br> (end (current-milliseconds)))<br> (js-alert (fx- end start))<br> (js-alert result))<br><br>(console.log 123456)<br>(console.log "This is a scheme string!!!")<br>(console.log 22.22)<br>(console.log '(1 2 3 4))<br>(console.log '(1 . 2))<br><br>(js-global "teste" <br> (lambda () (println "Function test")))<br><br>(js-global "fib" ; Javascript exported calls can't be recursive!!!!!<br> (lambda (n) (fib n)))<br><br>;; FILE lib.scm<br>(declare (standard-bindings) (extended-bindings) (not safe) (not run-time-bindings))<br><br>(println ">>> lib.scm")<br><br>(define (for-each f lst)<br> (if (pair? lst)<br> (begin<br> (f (car lst))<br> (for-each f (cdr lst)))))<br><br>(define (append lst1 lst2)<br> (if (pair? lst1)<br> (cons (car lst1) (append (cdr lst1) lst2))<br> lst2))<br><br>(define (current-milliseconds)<br> (##inline-host-expression "Date.now()"))<br><br>(define (js-alert obj)<br> (##inline-host-statement "console.log(g_scm2js(@1@));" obj))<br><br><br>(define (console.log obj)<br> (##inline-host-statement "console.log(g_scm2js(@1@));" obj))<br><br>(define (js-global name obj)<br> (##inline-host-statement "window[g_scm2js(@1@)]=g_scm2js(@2@);" name obj))<br> <br>(app#)<br><br>;; FILE makefile<br>GSC=gsc -target js<br><br>all: run<br><br>lib.js: lib.scm<br> $(GSC) -c lib.scm<br><br>app.js: app.scm<br> $(GSC) -c app.scm<br><br>app_.js: lib.js app.js<br> $(GSC) -link -l lib app.js<br><br>linked_app.js: lib.js app.js app_.js<br> $(GSC) -c lib.scm<br> cat app_.js lib.js app.js > linked_app.js<br> wc *.js<br><br>run: linked_app.js<br> node linked_app.js<br><br>clean:<br> rm -f lib.js app.js app_.js linked_app.js<br><br>;; FILE patch.sh<br>#!/usr/bin/env bash<br>sed -i 's/Gambit\.sp/g_sp/g' linked_app.js<br>sed -i 's/Gambit\.stack/g_stack/g' linked_app.js<br>sed -i 's/Gambit\.void_obj/void 0/g' linked_app.js<br>sed -i 's/Gambit\.nargs/g_nargs/g' linked_app.js<br>sed -i 's/Gambit\.stack/g_stack/g' linked_app.js<br>sed -i 's/Gambit\.underflow/g_underflow/g' linked_app.js<br>sed -i 's/Gambit\.trampoline/g_trampoline/g' linked_app.js<br>sed -i 's/Gambit\.scm2js/g_scm2js/g' linked_app.js<br>sed -i 's/Gambit\.r/g_r/g' linked_app.js<br>sed -i 's/Gambit\.js2scm_call/g_js2scm_call/g' linked_app.js<br>sed -i 's/Gambit\.scm2js/g_scm2js/g' linked_app.js<br>sed -i 's/Gambit\.String/G_ScmString/g' linked_app.js<br>sed -i 's/Gambit\.Flonum/G_Flonum/g' linked_app.js<br>sed -i 's/Gambit\.Pair/G_Pair/g' linked_app.js<br>sed -i 's/Gambit\.Structure/G_Structure/g' linked_app.js<br>sed -i 's/Gambit\./g_/g' linked_app.js<br>sed -i 's/var fs = require\(.*\);//g' linked_app.js<br>sed -i 's/var g_argv;/var g_argv = ["web-browser"];\/\*/g' linked_app.js<br>sed -i 's/g_argv = arguments;/g_argv = arguments;*\//g' linked_app.js<br>npx uglifyjs --compress --mangle --output linked_app.min.js -- linked_app.js<br><br>;; FILE index.html<br><!DOCTYPE html><br><html><br><head><br> <title>fib</title><br> <script type="text/javascript"><br> function print(x) { console.log(x); }<br> </script><br> <script type="text/javascript" src="linked_app.min.js"></script><br></head><br><body></body><br></html><br><br>After creating all these files, you can create the project with the next proceedings:<br><br>;; MSYS2 bash shell:<br>$ chmod ugo+x patch.sh # Turn the patch script executable<br>$ make linked_app.js<br>gsc -target js -link -l lib app.js<br>gsc -target js -c lib.scm<br>cat app_.js lib.js app.js > linked_app.js<br>wc *.js<br> 889 2224 20534 app.js<br> 722 2048 16061 app_.js<br> 427 1025 10221 lib.js<br> 2038 5297 46816 linked_app.js<br> 4076 10594 93632 total<br> <br> If you only run Make, the scripts will be compiled, but the patches aren't applied, so the process will fail.<br> <br> After you created the linked_app.js file, patch it:<br> <br>;; MSYS2 bash shell:<br>$ ./patch.sh<br><br>After that, the script, compatible with web browser, is ready.<br><br>You can load it using your default browser:<br><br>$ explorer index.html<br><br>And, in the browser (Firefox or Chrome), you can hit <F12>, and select the console. And you'll see the output:<br><br>>>> lib.scm <br>>>> app.scm <br>1 <br>1<br>2 <br>3 <br>5 <br>8 <br>13 <br>21 <br>34 <br>55 <br>89 <br>144 <br>233 <br>377 <br>610 <br>987 <br>1597 <br>2584 <br>4181 <br>6765 <br>10946 <br>17711 <br>28657 <br>46368 <br>75025 <br>121393 <br>196418 <br>317811 <br>514229 <br>832040 <br>2 <br>9227465 <br>123456 <br>This is a scheme string!!! <br>22.22 <br>Object(4) [ 1, 2, 3, 4 ]<br>Object [ 1 ]<br><br>The generated script isn't compatible with node.js, because the function js-global assume the existence of the "window" object, which is absent in Node.js. But, if in this function you replace "window" by "global", the script will work.<br><br>So:<br><br>;; MSYS2 bash shell:<br>$ rm *.js<br>$ sed -i 's/window/global/g' lib.scm<br>$ make linked_app.js <br>$ ./patch.sh<br>$ node linked_app.min.js<br>1 <br>1 <br>2 <br>3 <br>5 <br>8 <br>13 <br>21 <br>34 <br>55 <br>89 <br>144 <br>233 <br>377 <br>610 <br>987 <br>1597 <br>2584 <br>4181 <br>6765 <br>10946 <br>17711 <br>28657 <br>46368 <br>75025 <br>121393 <br>196418 <br>317811 <br>514229 <br>832040 <br>0 <br>9227465 <br>123456 <br>This is a scheme string!!! <br>22.22 <br>{ '0': 1, '1': 2, '2': 3, '3': 4 } <br>{ '0': 1 } <br><br>But one of the most intersting things is to call Scheme code from javascript:<br><br>;; MSYS2 bash shell:<br>$ node<br>> .load linked_app.min.js<br>> fib(42) <br>267914296<br><br>Strangely, fib(42) is the biggest value I can load using the fib function. Some problem load the numerical tower. But, the entire process is very, very interesting and well suitable to my needs to generate reusable javascript libraries using Scheme. The performance is very good.<br><br>It's possible to load the entire Gambit runtime in a javascript file, which can be suitable to create Scheme Node.js programs. First, create the next files:<br><br>;; NodeApp.scm<br>(declare<br> (standard-bindings)<br> (extended-bindings)<br> (not safe)<br> (fixnum)<br> (block)<br>)<br><br>;; All function, variables and other definitions before any execution:<br><br>(define (console.log obj)<br> (##inline-host-statement "console.log(g_scm2js(@1@));" obj))<br><br>(define (js-global name obj)<br> (##inline-host-statement "global[g_scm2js(@1@)]=g_scm2js(@2@);" name obj))<br> <br>(define (fib n)<br> (fib-iter 1 0 n))<br><br>(define (fib-iter a b count)<br> (if (= count 0)<br> b<br> (fib-iter (+ a b) a (- count 1))))<br><br>(js-global "teste" <br> (lambda () (console.log "Function test")))<br><br>(js-global "fib" ; Javascript exported calls can't be recursive!!!!!<br> (lambda (n) (fib n)))<br><br>; Then some commands executing things:<br><br>(for-each<br> (lambda (x)<br> (console.log (fib x)))<br> (append '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)<br> '(16 17 18 19 20 21 22 23 24 25 26 27 28 29 30)<br> '(31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 300)))<br><br>(console.log 123456)<br>(console.log "This is a scheme string!!!")<br>(console.log 22.22)<br>(console.log '(1 2 3 4))<br>(console.log '(1 . 2))<br><br>;; patch-app.sh<br>#!/usr/bin/env bash<br>sed -i 's/Gambit\.sp/g_sp/g' NodeApp<br>sed -i 's/Gambit\.stack/g_stack/g' NodeApp<br>sed -i 's/Gambit\.void_obj/void 0/g' NodeApp<br>sed -i 's/Gambit\.nargs/g_nargs/g' NodeApp<br>sed -i 's/Gambit\.stack/g_stack/g' NodeApp<br>sed -i 's/Gambit\.underflow/g_underflow/g' NodeApp<br>sed -i 's/Gambit\.trampoline/g_trampoline/g' NodeApp<br>sed -i 's/Gambit\.scm2js/g_scm2js/g' NodeApp<br>sed -i 's/Gambit\.r/g_r/g' NodeApp<br>sed -i 's/Gambit\.js2scm_call/g_js2scm_call/g' NodeApp<br>sed -i 's/Gambit\.scm2js/g_scm2js/g' NodeApp<br>sed -i 's/Gambit\.String/G_ScmString/g' NodeApp<br>sed -i 's/Gambit\.Flonum/G_Flonum/g' NodeApp<br>sed -i 's/Gambit\.Pair/G_Pair/g' NodeApp<br>sed -i 's/Gambit\.Structure/G_Structure/g' NodeApp<br>sed -i 's/Gambit\./g_/g' NodeApp<br>sed -i 's/var fs = require\(.*\);//g' NodeApp<br>sed -i 's/var g_argv;/var g_argv = ["web-browser"];\/\*/g' NodeApp<br>sed -i 's/g_argv = arguments;/g_argv = arguments;*\//g' NodeApp<br>npx uglifyjs --compress --mangle --output Min-NodeApp -- NodeApp<br>mv Min-NodeApp NodeApp<br><br>Then make the executable:<br><br>;; MSYS2 bash shell:<br>$ chmod ugo+x patch-app.sh<br>$ gsc -target js -exe NodeApp.scm<br>$ ./patch-app.sh # This will take a while!<br><br>The NodeApp executable is 15MB heavy. It is a very big file. But it contains the ENTIRE Gambit-C runtime - it is a COMPLETE SCHEME, which can be ran in Node.JS platform! And, although very large, NodeApp load and run very fast:<br><br>;; MSYS2 bash shell:<br>$ node NodeApp<br>1<br>1<br>2<br>3<br>5<br>8<br>13<br>21<br>34<br>55<br>89<br>144<br>233<br>377<br>610<br>987<br>1597<br>2584<br>4181<br>6765<br>10946<br>17711<br>28657<br>46368<br>75025<br>121393<br>196418<br>317811<br>514229<br>832040<br>1346269<br>2178309<br>3524578<br>5702887<br>9227465<br>14930352<br>24157817<br>39088169<br>63245986<br>102334155<br>165580141<br>267914296<br>433494437<br>701408733<br>1134903170<br>2.2223224462942035e+62<br>123456<br>This is a scheme string!!!<br>22.22<br>{ '0': 1, '1': 2, '2': 3, '3': 4 }<br>{ '0': 1 }<br>##thread-end-with-uncaught-exception! not implemented yet<br><br>I don't know what is this error ##thread-end-with-uncaught-exception! not implemented yet, but it didn't bothered me, at this moment. In the future I can ask why this problem is happening and how to solve it, and I'm happy, because it seems the numerical tower is accessible from Javascript. Unfortunately, infinite precision integers aren't available - but this is no problem, since a BigNum library can be implemented.<br><br>The error ##thread-end-with-uncaught-exception thrown by this app hindered me to turn the generated NodeApp application into a Node.js library, which can be reused from Javascript; so you can help me to solve this problem, and we can turn these libraries accessible from Javascript. Loading the app from the Web Browser is possible, and I can use this entire file as a library, but from Node.JS I couldn't. I'll look for the samples sent to me to know if this problem is already solved, but, if no, can you help me to solve this exception, or to know how to avoid it?<br><br>After all this work, I thank you very much by the help.<br><br>The next steps are discovering how to solve the ##thread-end-with-uncaught-exception error, to learn how to use define-syntax/syntax-rules macros on Javascript Backend, and how to use define-macro in Javascript backend (if these macros can be used, at all), solve the numerical tower problem in the small scripts generated using makefiles, and how to import and define the runtime library for small javascript libraries, created using makefiles. I'll need to hack into the Gambit libraries, to discover how to extract from them the default library functions and definitions for my web scheme runtime.<br><div><br></div><div>After I got the suitable gambit-scheme libraries working, without exceptions, and modularized, I can write a Medium article, to spread that Clojure isn't the only advanced Lisp usable to create Javascript libraries and programs, in Node.js and in Web. Any help in my endeavor is welcome.<br></div><div><br></div>Thank you very much, best regards and bye,<br><br>Paulo Silva-Filho.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex, 19 de jul de 2019 às 15:23, Paulo Silva Filho <<a href="mailto:paulosfilho@gmail.com">paulosfilho@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Sires,<br></div><div><br></div><div>I've realized that the examples seemed to be built using a development version of Gambit-C. I tried on a very stable version (4.6.6), which is from six years ago, and I've tried from a more recent version, 4.9.3, from the default package installers, in Windows and Linux.</div><div><br></div><div>I've looked for the some hints about which version of Gambit is being used on all examples, and the features and files shown (like _univlib.scm, present in the development version of Gambit - directly from Git, on <a href="https://github.com/gambit/gambit/blob/master/lib/_univlib.scm" target="_blank">https://github.com/gambit/gambit/blob/master/lib/_univlib.scm</a>) and I realized that the compiler version used need to be an experimental one.</div><div><br></div><div>So I'll try all the samples, again, but from a version of gambit compiled directly from the source code, downloaded from the main repository.</div><div><br></div><div>Thank you from all answers. I'll keep you in touch.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex, 19 de jul de 2019 às 12:37, Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Like so:<br>
<br>
% cd gambit<br>
% cd lib<br>
% make _gambit.js<br>
../gsc/gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(define-cond-expand-feature|enable-type-checking|)(define-cond-expand-feature|disable-auto-forcing|)(define-cond-expand-feature|enable-sharp-dot|)(define-cond-expand-feature|enable-bignum|)(define-cond-expand-feature|enable-ratnum|)(define-cond-expand-feature|enable-cpxnum|)(define-cond-expand-feature|disable-smp|)(##include\"../lib/header.scm\")" -o _gambit.js ../lib/_univlib.scm<br>
% cd ..<br>
% gsc/gsc -:=. -target js -exe app.scm<br>
% ./app<br>
1<br>
256<br>
65536<br>
16777216<br>
4294967296<br>
1099511627776<br>
281474976710656<br>
72057594037927936<br>
18446744073709551616<br>
4722366482869645213696<br>
1208925819614629174706176<br>
309485009821345068724781056<br>
79228162514264337593543950336<br>
20282409603651670423947251286016<br>
5192296858534827628530496329220096<br>
1329227995784915872903807060280344576<br>
340282366920938463463374607431768211456<br>
87112285931760246646623899502532662132736<br>
22300745198530623141535718272648361505980416<br>
5708990770823839524233143877797980545530986496<br>
% cat app.scm<br>
(define n 20)<br>
(for-each (lambda (i)<br>
(println (object->string (expt 2 (* i 8)))))<br>
(iota n))<br>
(exit)<br>
<br>
This should work for the other backends too. Note that there’s some bit rot of lib/univlib.scm, so there are issues with some parts of the Gambit library (for example write and pretty-print are broken, (exit) is needed to avoid an exception on exit, etc). You can revert to previous recent releases of Gambit to get these working correctly.<br>
<br>
Sorry but lots of things are in flux right now…<br>
<br>
Marc<br>
<br>
<br>
<br>
> On Jul 19, 2019, at 11:08 AM, Amirouche Boubekki <<a href="mailto:amirouche.boubekki@gmail.com" target="_blank">amirouche.boubekki@gmail.com</a>> wrote:<br>
> <br>
> Sorry for the multiple emails!<br>
> <br>
> Le ven. 19 juil. 2019 à 13:38, Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>> a écrit :<br>
> You should look at this recent thread: <a href="https://mailman.iro.umontreal.ca/pipermail/gambit-list/2019-July/009103.html" rel="noreferrer" target="_blank">https://mailman.iro.umontreal.ca/pipermail/gambit-list/2019-July/009103.html</a><br>
> <br>
> In the above mail thread, it is described how to compile a scheme file into javascript WITHOUT "Gambit runtime".<br>
> <br>
> Q: How can I bundle the Gambit runtime into the compiled JavaScript file?<br>
> <br>
> <br>
> Thanks in advance!<br>
<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail-m_258799893270935777gmail_signature"><div dir="ltr">Paulo Silva Filho<div><br></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Paulo Silva Filho<div><br></div></div></div>