Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created March 14, 2017 11:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman01la/1d2f84357a2aef8ef053dd6ba4f0aad1 to your computer and use it in GitHub Desktop.
Save roman01la/1d2f84357a2aef8ef053dd6ba4f0aad1 to your computer and use it in GitHub Desktop.
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