Discussion:
more on nyacc extension languages
Matt Wette
2018-08-31 14:42:02 UTC
Permalink
Just goofing off a bit:

scheme@(guile-user)> ,use (nyacc lang nx-lib)
scheme@(guile-user)> (install-inline-language-evaluator)

scheme@(guile-user)> #<nx-matlab: a=[1, 2, 3]; >#
scheme@(guile-user)> (define b (vector-ref a 2))
scheme@(guile-user)> #<nx-javascript: var c = b + 2; >#
scheme@(guile-user)> c
$1 = 5

scheme@(guile-user)> (define d 1)
scheme@(guile-user)> (set! d #<nx-matlab: d + 1; >#)
scheme@(guile-user)> (set! d #<nx-javascript: d + 1; >#)
scheme@(guile-user)> d
$2 = 3

This is using read-hash-extend with a handler that looks
up the language then compiles the code to tree-il, then
decompiles to scheme and returns the scheme form.

Matt
Matt Wette
2018-09-01 19:38:02 UTC
Permalink
Working on nx-tcl now. I am working to extract common utilities for
generating language extensions based on the three I have now:
nx-tcl, nx-octave (was nx-matlab) and nx-javascript.

scheme@(guile-user)> ,L nx-tcl
Happy hacking with nx-tcl! To switch back, type `,L scheme'.

nx-tcl@(guile-user)> proc foo {a {b 1} args} { set c 1; return [expr $a+$b+$c] }

nx-tcl@(guile-user)> ,L scheme
Happy hacking with Scheme! To switch back, type `,L nx-tcl'.

scheme@(guile-user)> (foo "5" "6")
$1 = 12

scheme@(guile-user)> (foo 5 6)
$2 = 12

scheme@(guile-user)> (foo 5)
$3 = 7

Making nx-tcl compatible with other languages is still something I'm thinking
about. In Tcl all values are strings, but some items are intended to be non-
strings. So the implementation needs to deal with converting to strings. I
am trying to be lazy about that and see where it turns out.

Matt

Loading...