Previous: Ngspice, Up: Language Quirks [Contents]
Hoot is tricky because of how closely it is tied to Guile. There are several methods one may want to write and evaluate Scheme code with Hoot.
The code field may be either an s-expression or a string. Use the
hoot-expression language procedure for expressions and hoot for
strings.
Hoot can either be compiled to a wasm Guile Scheme object or
assembled + written to a .wasm file. The former can be manipulated
in Guile Scheme using Hoot’s procedures. The latter can be combined
with a JavaScript wrapper and run in a web browser. To control whether
the WebAssembly is written to a file, you can provide a file
keyword argument to both the hoot and hoot-expression languages.
(block-result (make-block*
#:language (hoot-expression)
#:code '(+ 1 2)))
;;=> wasm object
(block-result (make-block*
#:language (hoot-expression #:file "foo.wasm")
#:code '(+ 1 2)))
;; "foo.wasm"
When using hoot-expression, the expression will be prepended with a
begin syntax unless begin? #f is passed.
(make-block*
#:language (hoot-expression)
#:code ((define x 1)
(+ x 2)))
;; is equivalent to
(make-block*
#:language (hoot-expression #:begin? #f)
#:code (begin (define x 1)
(+ x 2)))
Both hoot-expression and hoot take two keyword arguments:
assemble-flags and compile-flags. assemble-flags is used in
Hoot’s assemble-wasm procedure. For the hoot-expression language
procedure, compile-flags is passed to compile. For hoot, it is
passed to read-and-compile.
(make-block*
#:language (hoot-expression #:file "foo.wasm"
#:compile-flags
'(#:imports ((guile)
(ice-9 match))))
#:code
'((match '(1 2 3)
((a b c) c))))