unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: Guile Development <guile-devel@gnu.org>
Subject: Re: Should psyntax pass through a compiled VM program?
Date: Wed, 16 Sep 2009 21:36:00 +0200	[thread overview]
Message-ID: <m3eiq6bs2n.fsf@pobox.com> (raw)
In-Reply-To: <87iqfm7de9.fsf@arudy.ossau.uklinux.net> (Neil Jerram's message of "Sun, 13 Sep 2009 22:17:34 +0100")

On Sun 13 Sep 2009 23:17, Neil Jerram <neil@ossau.uklinux.net> writes:

> I think that's the right eventual question, anyway.  The context is
> running Alan Grover's mod_lisp-for-guile in 1.9.2.
>
> The mod_lisp-for-guile code includes a use of read-hash-extend to
> define a syntax for a compiled regular expression - so that you can
> write things like
>
>   (if (#m/^Error: +/ line)
>       ...)
>
> with a similar effect to Perl
>
>   if (line ~= /^Error: +/)
>     ...
>
> So:
>
>   (read-hash-extend #\m (lambda (c port)
>                           ...
>                           (lambda (string)
>                             ...)))
>
> In other words, the custom reader procedure returns another
> procedure.

So what happens when you compile this file? You would have to serialize
that procedure somehow, a procedure that could be a closure, etc...

No, I think all macros have to return syntax and not values.

This particular case is a bit unfortunate, though. You really want to
compile the regex once, preferably at compile-time... ideally the regex
compiles to scheme, and thence to bytecode/native code, but that's not
how things are right now.

So yes, I think the best we can do is to do what you did:

>   (define-public (make-regexp-fn regexp-string)
>     (lambda (string)
>       ...))

And make-regexp-fn should memoize results.

> but I wonder if there is a case for supporting the code as it was
> before, by

I'm afraid not, because you need to be able to compile a file to
bytecode, write it out to disk, then load it later.

> Also, is it definitely correct to call read-hash-extend procedures
> first, and do the psyntax pass later?  I guess it must be, as we need
> to call the read-hash-extend procedure in order even to determine the
> extent of the relevant lexeme.

Right. More thought (and documentation!) is needed here, though.

Andy
-- 
http://wingolog.org/




      reply	other threads:[~2009-09-16 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-13 21:17 Should psyntax pass through a compiled VM program? Neil Jerram
2009-09-16 19:36 ` Andy Wingo [this message]

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=m3eiq6bs2n.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=neil@ossau.uklinux.net \
    /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).