Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created Mar 14, 2017
Embed
What would you like to do?
Gambit Scheme JavaScript target
$ cd lib
$ make _gambit.js
$ cd ..
$ gsc/gsc -:=. -warnings -target js code.scm
$ gsc/gsc -:=. -warnings -target js -link -l lib/_gambit.js code.js
$ cat code_.js code.js lib/_gambit.js > p.js
$ node p.js
(declare (extended-bindings))
(##inline-host-declaration "
function rand(n) {
return Math.floor(n * Math.random());
}
")
(define (rand n)
(+ 1 (##inline-host-expression "g_host2scm(rand(g_scm2host(@1@)))" n)))
(println (rand 6))
(println (rand 6))
(println (rand 6))
(println (rand 6))
(##inline-host-statement "console.log(@1@);" 123)
(##inline-host-statement "console.log(@1@);" "hello")
(##inline-host-statement "console.log(@1@);" 'world)
(##inline-host-statement "console.log(@1@);" (cons 11 22))
(##inline-host-statement "console.log(@1@);" (vector 11 22 33))
(##inline-host-statement "console.log(@1@);" rand)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment