unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Should psyntax pass through a compiled VM program?
@ 2009-09-13 21:17 Neil Jerram
  2009-09-16 19:36 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Neil Jerram @ 2009-09-13 21:17 UTC (permalink / raw)
  To: Guile Development

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 the read code (for the above example) becomes

  (if (#<procedure (string)> line)
      ...)

In pre-VM Guile, (I assume) this worked because there wasn't a psyntax
pass, and because the evaluator regards procedures as self-evaluating.

But in VM Guile, the read code is

  (if (#<program ...> line)
      ...)

And psyntax errors when it hits the #<program>.

I've worked around this by rewriting the read-hash-extend code as

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

  (read-hash-extend #\m (lambda (c port)
                          ...
                          `(make-regexp-fn ,regexp-string)))

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

- teaching psyntax to pass through a #<program> if it sees one

- making programs self-evaluating (and in fact they may already be so,
  I haven't checked).

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.

Regards,
        Neil




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-16 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-13 21:17 Should psyntax pass through a compiled VM program? Neil Jerram
2009-09-16 19:36 ` Andy Wingo

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).