Return urmodule as a string without writing a file

I was wondering whether it's possible to use urlang in such a way that the content of the module is simply returned, instead of writing it out to a file. That way I suppose it could be combined to insert some javascript (via urlang) into an html template.

Is that something that is already possible? It strikes me as a thing that is almost implemented already with current-urlang-echo?.

1 Like

Hi @nik

I have now added urlang/string.
Wrap urlang/string around some some (urmodule ...) and you will
get a list back consisting of module names and strings with the JavaScript.

Example:

#lang racket
(require urlang)

(urlang/string
 (urmodule demo-fact                                      
   (export fact)                                          
   (define (fact n) (if (= n 0) 1 (* n (fact (- n 1)))))
   (console.log (fact 5))))

Result:

'((demo-fact "\"use strict\";\nfunction fact(n){return (((n===0)===false)?(n*(fact((n-1)))):1);};\n((console.log)((fact(5))));\nexport {fact};"))
1 Like

Oh nice, that's really cool! Thank you for the quick response/solution! :slight_smile:

1 Like