schemeorg-community / try.scheme.org

Try Scheme - Run a Scheme REPL in the browser
https://try.scheme.org
2 stars 0 forks source link

Pre-compiled JS version of Gambit #2

Open lassik opened 3 years ago

lassik commented 3 years ago

@feeley wrote:

I’ve added some files to the try.scheme.org github repo to show how a barebones Scheme interpreter webapp can be created using Gambit. It is a makefile and a 45 line Scheme source file.

I managed to run make on my machine and it works. Here's the gzipped version of the build product: https://misc.lassi.io/2020/gambit/interp-barebones.js.gz

feeley commented 3 years ago

Ideally the gzipped .js file should be the thing that is transferred over the network by the web server. This can be done with proper configuration of the web server, which is beyond my control.

For additional compression you can also do:

make interp-barebones.minjs

and then gzip the result. The difference in size is as follows:

% ls -l interp-barebones.*gz
-rw-r--r--  1 feeley  staff  2308550 29 Dec 18:20 interp-barebones.js.gz
-rw-r--r--  1 feeley  staff  1666437 29 Dec 18:21 interp-barebones.minjs.gz

So that's 30% less data to transfer and 20x more compact than the original uncompressed .js file.

lassik commented 3 years ago

Good thing! Pre-built product at https://misc.lassi.io/2020/gambit/interp-barebones.minjs.gz

jcubic commented 3 years ago

I've tried to compile gambit and this project but was not able to, got error that that there are no modules in makefile, I've ignored that and installed gambit, it installed itself in weird location, but after adding it to path I was not able to build interp-barebones, maybe I use wrong version of make, I use Fedora and GNU Make 4.2.1.

Any hints how to use this thing? Also this thing is huge, min.js file have 22MB of data. in comparison BiwaScheme is about 250KB (version 0.7.1) and LIPS is about 150kB of js and about 100kB of Scheme code so the size is similar (not even close to 1MB). If this file include all the modules then maybe, modules can be separated and loaded on demand and load only minimal Scheme.

Is Gambit all written in C/C++ or standard libraries are written in Scheme? Looking at repo, stats show only 17.6% is Scheme.

Maybe we should pick another Scheme implementations that is close to R7RS? I'm not saying LIPS, but something that can be compiled to JS and that have standard libraries written in scheme that can be loaded using AJAX when needed.

Maybe Gambit is great when run on users machine, but if something is more then 2MB it's of no use in browser.

lassik commented 3 years ago

@jcubic Did you do make && make modules && make install? Note the make modules. To change where it's installed, ./configure --prefix=/path/to/installdir.

lassik commented 3 years ago

Is Gambit all written in C/C++ or standard libraries are written in Scheme? Looking at repo, stats show only 17.6% is Scheme.

It's written almost entirely in Scheme, which is then compiled to C. Like many Scheme and Lisp systems, Gambit is developed by continually compiling itself (i.e. an older version of Gambit compiles a newer version of Gambit, "bootstrapping"). The only C code written by hand is some glue for the OS interface, and maybe the runtime (GC and such).

feeley commented 3 years ago

I've tried to compile gambit and this project but was not able to, got error that that there are no modules in makefile, I've ignored that and installed gambit, it installed itself in weird location, but after adding it to path I was not able to build interp-barebones, maybe I use wrong version of make, I use Fedora and GNU Make 4.2.1.

Any hints how to use this thing? Also this thing is huge, min.js file have 22MB of data. in comparison BiwaScheme is about 250KB (version 0.7.1) and LIPS is about 150kB of js and about 100kB of Scheme code so the size is similar (not even close to 1MB). If this file include all the modules then maybe, modules can be separated and loaded on demand and load only minimal Scheme.

I’m sorry you are having problems building and installing Gambit. Are you sure you followed the build steps exactly? The bootstrap process can cause problems if it is not done correctly. I regularly compile Gambit on different Unix variants with no problems. You have to:

 git clone git@github.com:gambit/gambit.git
 cd gambit
 ./configure --enable-single-host --enable-targets=js
 make
 make modules
 make install

These steps are at the top of the try.scheme.org repo's interp/makefile file.

If you would like to install Gambit somewhere else than /usr/local/Gambit then just do:

./configure --enable-single-host --enable-targets=js --prefix=/path/for/install

Is Gambit all written in C/C++ or standard libraries are written in Scheme? Looking at repo, stats show only 17.6% is Scheme.

Gambit is written mostly in Scheme. The GC and the interface to the OS is written in portable C code.

Maybe we should pick another Scheme implementations that is close to R7RS? I'm not saying LIPS, but something that can be compiled to JS and that have standard libraries written in scheme that can be loaded using AJAX when needed.

I don’t know of any other Scheme system that can be compiled to JS and that conforms to R7RS and that is full featured (debugger, single-stepper, pretty-printer, hash-tables, etc).

It would be really sad if the “Try Scheme” link of scheme.org was a toy. It would give a wrong impression of what Scheme is and what it can do.

Maybe Gambit is great when run on users machine, but if something is more then 2MB it's of no use in browser.

The .js can be minified and when gzip compressed it is 1.6 MB. Frankly that’s quite usable on the web and should not cause a bad user experience. A web page with a few pictures will be more than 2 MB.

To build the minified gzipped .js file (interp-barebones.minjs.gz), in the try.scheme.org repo’s interp directory do:

 make interp-barebones.minjs

As I said the UI is barebones. To make it user friendly we need to add an emulated terminal, which could be Terminus (https://github.com/breuleux/terminus) or JQueryTerminal. I have more experience with Terminus (which was used for gambit-in-the-browser: https://feeley.github.io/gambit-in-the-browser/), but if you want to take care of interfacing to JQueryTerminal then that’s ok with me.

Additionally we should provide an in-browser editor to edit some Scheme source files. I have experience with CodeMirror and also ymacs (an emacs subset in JavaScript). The ymacs editor was used for gambit-in-emacs-in-the-browser: https://feeley.github.io/gambit-in-emacs-in-the-browser/ . Emacs is used by many Schemers so that might provide a user experience that is more “typical” for Schemers. On the other hand newcomers might get the impression that Scheme and emacs are inseperable, and it might scare some newcomers that expect a “plain” code editor. I guess the ideal situation would be to support both editors.

jcubic commented 3 years ago

Ok, I was able to compile Gambit. I think that the build system is kind of broken, if you made mistake and invoke make in wrong way (I've had $CDPATH added) you need to clone the repo again and do exactly those steps because make clean make no effect and you will not have clean state.

feeley commented 3 years ago

If you make a mistake and want a fresh start, you shouldn't do make clean (because this is not how the bootstrap process works). You need to:

rm -rf boot
git checkout master

because there is (possibly inconsistent) state in the boot subdirectory and some of the .c files may have been changed by the mistaken build.

I'm sorry that you think this is "broken". I think "unusual" is a more appropriate term. That is the price to pay to get the benefits of a bootstrapped system (and avoid git history bloat).