Hi,
I would like to use the -target js mode of Gambit to compile a scheme program and run in in a browser. I read on this list that the functionality is still incomplete but I wonder if there are plans to make it work in the near future.
I was able to compile trivial programs but my first try at a “real life” example is failing. It seems the generated javascript is missing some library functions like that the generated code is calling like:
Gambit_Symbol.stringToSymbol() Gambit_Char.fxToChar() Gambit_String.jsstringToString() …
Is there a more complete version somewhere that defines those gambit structures in javascript? I used Gambit-4.7.0 for my tests.
Thank you, François Magnan
Afficher les réponses par date
On Nov 12, 2013, at 12:39 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi,
I would like to use the -target js mode of Gambit to compile a scheme program and run in in a browser. I read on this list that the functionality is still incomplete but I wonder if there are plans to make it work in the near future.
I was able to compile trivial programs but my first try at a “real life” example is failing. It seems the generated javascript is missing some library functions like that the generated code is calling like:
Gambit_Symbol.stringToSymbol() Gambit_Char.fxToChar() Gambit_String.jsstringToString() …
Is there a more complete version somewhere that defines those gambit structures in javascript? I used Gambit-4.7.0 for my tests.
Could you try with the most recent version on the Gambit repo? The JS backend is not complete, but it has progressed substantially about a month ago. My plan is for the JS backend to be sufficiently complete to compile the standard Gambit runtime system. Because it is not there yet, currently, you have to write your own versions of some of the standard runtime library functions (append, member, etc).
Marc
On Nov 12, 2013, at 1:13 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On Nov 12, 2013, at 12:39 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi,
I would like to use the -target js mode of Gambit to compile a scheme program and run in in a browser. I read on this list that the functionality is still incomplete but I wonder if there are plans to make it work in the near future.
I was able to compile trivial programs but my first try at a “real life” example is failing. It seems the generated javascript is missing some library functions like that the generated code is calling like:
Gambit_Symbol.stringToSymbol() Gambit_Char.fxToChar() Gambit_String.jsstringToString() …
Is there a more complete version somewhere that defines those gambit structures in javascript? I used Gambit-4.7.0 for my tests.
Could you try with the most recent version on the Gambit repo? The JS backend is not complete, but it has progressed substantially about a month ago. My plan is for the JS backend to be sufficiently complete to compile the standard Gambit runtime system. Because it is not there yet, currently, you have to write your own versions of some of the standard runtime library functions (append, member, etc).
Marc
Actually, I should have asked if you did a "make from-scratch" (which is the new way to bootstrap Gambit from the github repo). So you should be doing:
% git clone https://github.com/feeley/gambit.git % make -j8 from-scratch
Once this is done, you will have a current Gambit to test things out with.
Marc
Hi Marc,
Yes it works much better. Now I just need to implement some library functions in javascript. For example I get:
TypeError: ‘undefined’ is not a function (evaluating 'Gambit_glo['with-output-to-string']()')
I will tweak my Scheme code to avoid those abstractions for the moment.
Thank you, Francois
On 2013-11-13, at 16:20, Marc Feeley feeley@iro.umontreal.ca wrote:
On Nov 12, 2013, at 1:13 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On Nov 12, 2013, at 12:39 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi,
I would like to use the -target js mode of Gambit to compile a scheme program and run in in a browser. I read on this list that the functionality is still incomplete but I wonder if there are plans to make it work in the near future.
I was able to compile trivial programs but my first try at a “real life” example is failing. It seems the generated javascript is missing some library functions like that the generated code is calling like:
Gambit_Symbol.stringToSymbol() Gambit_Char.fxToChar() Gambit_String.jsstringToString() …
Is there a more complete version somewhere that defines those gambit structures in javascript? I used Gambit-4.7.0 for my tests.
Could you try with the most recent version on the Gambit repo? The JS backend is not complete, but it has progressed substantially about a month ago. My plan is for the JS backend to be sufficiently complete to compile the standard Gambit runtime system. Because it is not there yet, currently, you have to write your own versions of some of the standard runtime library functions (append, member, etc).
Marc
Actually, I should have asked if you did a "make from-scratch" (which is the new way to bootstrap Gambit from the github repo). So you should be doing:
% git clone https://github.com/feeley/gambit.git % make -j8 from-scratch
Once this is done, you will have a current Gambit to test things out with.
Marc
On Nov 13, 2013, at 11:08 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi Marc,
Yes it works much better. Now I just need to implement some library functions in javascript. For example I get:
TypeError: ‘undefined’ is not a function (evaluating 'Gambit_glo['with-output-to-string']()')
I will tweak my Scheme code to avoid those abstractions for the moment.
Thank you, Francois
Very well. By the way, I have made a few changes this morning that may make things easier for handling strings, characters and symbols. If all you need is something to convert Scheme data to a string in order to display it, then use the object->string function defined in the attached file. It also includes a pretty-printer.
Marc
Hi,
When I compile your program ‘gsc -c -target js …’, I get a working program when I try it in node javascript i.e. “node obj2str.js”, Safari an Chrome. Note that I had to define the print function to make it work. I also took the latest gambit from the git repo. Thank you for the code.
What I don’t understand now is that you seem to use the pair? function and it works fine. When I compile my program the javascript interpreter complains:
Gambit_r1 = (Gambit_bb1_pair_3f_); ^ ReferenceError: Gambit_bb1_pair_3f_ is not defined
???
Thank you, Francois
On 2013-11-14, at 13:02, Marc Feeley feeley@iro.umontreal.ca wrote:
On Nov 13, 2013, at 11:08 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi Marc,
Yes it works much better. Now I just need to implement some library functions in javascript. For example I get:
TypeError: ‘undefined’ is not a function (evaluating 'Gambit_glo['with-output-to-string']()')
I will tweak my Scheme code to avoid those abstractions for the moment.
Thank you, Francois
Very well. By the way, I have made a few changes this morning that may make things easier for handling strings, characters and symbols. If all you need is something to convert Scheme data to a string in order to display it, then use the object->string function defined in the attached file. It also includes a pretty-printer.
Marc
<obj2str.scm>
By the way ##inline-host-code doesn’t seem to work anymore.
(define (console.log x) ;; Note: the parameter x will be in variable Gambit_r1 (##inline-host-code “console.log(Gambit_r1);\n”))
How can I inline javascript code now? Thank you, Francois
On 2013-11-14, at 14:54, Francois Magnan magnan@categoricaldesign.com wrote:
Hi,
When I compile your program ‘gsc -c -target js …’, I get a working program when I try it in node javascript i.e. “node obj2str.js”, Safari an Chrome. Note that I had to define the print function to make it work. I also took the latest gambit from the git repo. Thank you for the code.
What I don’t understand now is that you seem to use the pair? function and it works fine. When I compile my program the javascript interpreter complains:
Gambit_r1 = (Gambit_bb1_pair_3f_); ^ ReferenceError: Gambit_bb1_pair_3f_ is not defined
???
Thank you, Francois
On 2013-11-14, at 13:02, Marc Feeley feeley@iro.umontreal.ca wrote:
On Nov 13, 2013, at 11:08 PM, Francois Magnan magnan@categoricaldesign.com wrote:
Hi Marc,
Yes it works much better. Now I just need to implement some library functions in javascript. For example I get:
TypeError: ‘undefined’ is not a function (evaluating 'Gambit_glo['with-output-to-string']()')
I will tweak my Scheme code to avoid those abstractions for the moment.
Thank you, Francois
Very well. By the way, I have made a few changes this morning that may make things easier for handling strings, characters and symbols. If all you need is something to convert Scheme data to a string in order to display it, then use the object->string function defined in the attached file. It also includes a pretty-printer.
Marc
<obj2str.scm>
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On Nov 14, 2013, at 4:23 PM, Francois Magnan magnan@categoricaldesign.com wrote:
By the way ##inline-host-code doesn’t seem to work anymore.
(define (console.log x) ;; Note: the parameter x will be in variable Gambit_r1 (##inline-host-code “console.log(Gambit_r1);\n”))
How can I inline javascript code now? Thank you, Francois
Recall that ##inline-host-code no longer exists... you have to use ##inline-host-statement and ##inline-host-expression depending on the nature of the code. For example, this works for me using node:
(declare (extended-bindings) (not safe))
(define (show arg) (##inline-host-statement "console.log(Gambit_r1.toString());"))
(show 'hello)
(show "world")
(show (##inline-host-expression "1+2+3"))
Marc