Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hey! 

I'm struggling using conditional expand with guile hoot. E.g., I want to have a "message" function display stuff either to terminal (when called there) or to a  HTML element (when called in wasm).

I tried something like:

(cond-expand
 (hoot 
  (define-module (ui ui)     #:use-module (web dom)     #:export (message)))  (else   (define-module (ui ui)     #:export (message)))) (cond-expand  (hoot   (define (message msg)     "Display a text message"     (append-child! (document-body) (make-text-node msg))))  (else   (define (message msg)     "Display a text message"     (display msg)     (newline)))) (message "Foo")

This works when called in normal guile, but not when trying to build wasm ("hoot/library-group.scm:604:5: In procedure parse-library:invalid module forms (lot of stuff)")

I'd be really thankful if I could have any pointer on the way to do that cleanly :)

(Thought in any case given the deadline I'm afraid I won't be able to send more than a hello world to this jam 😭 )

You can't cond-expand a module definition because you need the module definition in order to know what names are imported, including cond-expand. Rather than wrapping define-module in cond-expand, you need an inner cond-expand.  Unfortunately, Guile's define-module doesn't support a cond-expand form. Fortunately, R7RS's define-library does! So, you'd want to do something like this:

(define-library
  (cond-expand
    (hoot (import (web dom)))
    (else))
  (export message)
  ...)

Thanks a lot!