I know
nothing about the Swift language and whether it has a sufficient
C-like
FFI to achieve this, but you may get some inspiration from the
following, which enables scheme code to be run as an extension
language
within a C++ program:
https://sourceforge.net/p/cxx-gtk-utils/git/ci/master/tree/c++-gtk-utils/extension.h
However there are various issues. First, guile's exceptions
(based on C's longjmp()/setjmp() and cognates) are almost
certainly
not implemented in the same way as Swift's exceptions (assuming
Swift
has exceptions), which means amongst other things that, if Swift
has
something akin to destructors/deinitialization, you should not
allow
guile exceptions to leave Swift objects undestroyed were guile
to
jump out of local scope on raising an exception
(scm_dynwind_begin(),
scm_dynwind_end and scm_dynwind_unwind_handler can be useful
here if
you are able to manage your Swift objects manually in C). Nor
more
generally should you allow Swift exceptions (if Swift has them)
to
escape out of a guile scm_dynwind_begin()/scm_dynwind_end()
pair, or
you will stop guile's resource management working correctly.
Secondly, there are some issues relating to the fact that
guile's
'make-fresh-user-module' and 'load' procedures leak memory,
which can
be problematic if all tasks run as scheme code are not to share
the
same top level.
Thirdly you will need to cater for translating guile return
values such
as lists or vectors into containers that Swift can work with,
and vice
versa.
This is all pretty well documented in the C++ code mentioned
above, but
it is not for the faint hearted.