unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: guile-user@gnu.org
Subject: Seeking Advice on syntax/macros in separate files
Date: Mon, 1 Mar 2021 18:03:57 +0000	[thread overview]
Message-ID: <20210301180357.GN265215@embecosm.com> (raw)

Hello,

I'm trying to understand how I am supposed to make use of
define-syntax type constructs (or possibly, when working with older
code define-macros) in a code base split over many files

I'm updating a code base from guile 1.8.8, and currently having it
running successfully on guile 2 and 3.  With the new auto-compilation
in guile 2 and 3 I'm now trying to work out how users will invoke the
tool.

My concerns are based on this page of the guile manual:

  https://www.gnu.org/software/guile/manual/html_node/Compilation.html#Compilation

specifically this:

  "... Guile does not yet do proper dependency tracking, so that if
  file a.scm uses macros from b.scm, and b.scm changes, a.scm would
  not be automatically recompiled."

And just to confirm what the manual says, here's my test:

  $ cat f1.scm
  (use-modules (f2))
  (foo 123)
  (define-accessor xxx 3)
  (xxx 9)

  $ cat f2.scm
  (define-module (f2)
    #:export (foo)
    #:export-syntax (define-accessor))

  (define (foo arg)
    (display "foo: ")
    (display arg)
    (newline))

  (define-syntax-rule (define-accessor name n)
    (define (name obj)
      (display "accessor for field: ")
      (display n)
      (display " in ")
      (display obj)
      (newline)))

I'm then running `guile -L . -s f1.scm`, and indeed, as the manual
suggests, changes to `foo' are visible, but, unless I force
recompilation, changes to `define-accessor` are not.

I also tried replacing the use of `use-modules` with raw `include`,
but this is even worse, as now changes to `foo` are not seen either.

My choice of `define-accessor' is not random, this is drawn from an
example in the guile manual here:

  https://www.gnu.org/software/guile/manual/html_node/Vtable-Example.html

And here lies my confusion:

First, let me say I'm pretty much a scheme/guile newbie, but I thought
that macros (or syntax extensions) were a huge part of the power of
languages like scheme.  The guile manual itself uses them to show how
an object like system could be created.

However, it would seem natural to place such a system into a separate
file, presumably as a module.

But, and here's my problem: the first time I ship this software to the
user, everything's fine.  But if I ship them an update that touches
any of the macros, then I'm stuck.  The user now needs to be aware
that they have to take special steps in order to ensure the previously
compiled code is deleted.  And that's not great for a user experience.

So, my current thinking is to wrap the invocation of the guile script
in a shell script, which _always_ forces recompilation.  But, if I'm
doing that, I may as well just disable compilation completely.  But
this doesn't seem right.

So, I'm sure I must be missing something here.  How do others deal
with this situation?

- Am I missing an obvious solution for working with syntax/macros and
  multiple files?

- Am I wrong to think that syntax/macros are such a big part of the
  language?  Should I be limiting syntax/macro usage to small scopes,
  i.e. within a single file, and only true defines should be exposed
  outside of a file?

- Maybe Guile just isn't designed for writing large, multi-file
  projects?

- Maybe Guile projects are only ever shipped to users who are happy
  managing the compile cache themselves, e.g. more power users, and
  not really for general users?

As I said, I'm fairly new to guile/scheme so my expectation here is
that it's me that's missing something here.

Thank you for any help you can offer,

Andrew



             reply	other threads:[~2021-03-01 18:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 18:03 Andrew Burgess [this message]
2021-03-02  8:23 ` Seeking Advice on syntax/macros in separate files Ludovic Courtès
2021-03-02  9:47   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301180357.GN265215@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).