[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Should psyntax pass through a compiled VM program?
From: |
Andy Wingo |
Subject: |
Re: Should psyntax pass through a compiled VM program? |
Date: |
Wed, 16 Sep 2009 21:36:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) |
On Sun 13 Sep 2009 23:17, Neil Jerram <address@hidden> 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/