unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Strange string-append and string-match behaviour
@ 2011-02-18  4:11 Francis Southern
  2011-02-27 22:27 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Francis Southern @ 2011-02-18  4:11 UTC (permalink / raw)
  To: bug-guile

Hello Guilers,

I'm not 100% sure whether this is a bug or not, and it might not even
be legal Scheme code!  But it seemed a bit odd to me so I'm reporting
it here.
(I'm currently using 1.9.15, but I believe this to be reproducible on 2.0.)

I was trying to match strings that started with a question mark, what
I wanted was actually `(string-match "\\?.*" "?wibble")', but the
problem is that when I was trying out a few different regexes I got
some odd results.


scheme@(guile-user)> (string-match "?.*" "?wobble")
ERROR: In procedure make-regexp:
ERROR: In procedure make-regexp: Error while printing exception.

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.


This may not be a problem at all, but the error message seemed
strange.  But worse is yet to come!


scheme@(guile-user)> (string-match "\?.*" "?wobble")
While reading expression:
ERROR: In procedure scm_lreadr: standard input:3:18: illegal character
in escape sequence: #\?
;;; <unknown-location>: warning: possibly unbound variable `.*'
ERROR: In procedure #<procedure 2183020 ()>:
ERROR: In procedure module-lookup: Unbound variable: .*

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
$1 = " "
;;; <unknown-location>: warning: possibly unbound variable `?wobble'
ERROR: In procedure #<procedure 21ac020 ()>:
ERROR: In procedure module-lookup: Unbound variable: ?wobble

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.


And then it just hung and I needed to C-c C-c my way out.

While talking to cky in #guile, he pointed out that the problem is
actually with string-append and gave me two examples:
(string-append "\?")  which shows the basic error message, and
(string-append "\?" "foo")  which shows that after the error Guile
tries to read "foo" as a symbol rather than a string.

I am willing to admit the possibility that these examples are
`malformed' and maybe it's too much to ask to have something graceful
happen here, but I thought I should bring it to your attention and see
what you thought.


Thanks for your time and thanks for Guile!

Francis



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

* Re: Strange string-append and string-match behaviour
  2011-02-18  4:11 Strange string-append and string-match behaviour Francis Southern
@ 2011-02-27 22:27 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2011-02-27 22:27 UTC (permalink / raw)
  To: Francis Southern; +Cc: bug-guile

Hi Francis,

The (most unfortunately indicated!) error is actually a read error due
to malformed input and not related to any of these procedures.

On Fri 18 Feb 2011 05:11, Francis Southern <francis.southern@gmail.com> writes:

> scheme@(guile-user)> (string-match "?.*" "?wobble")
> ERROR: In procedure make-regexp:
> ERROR: In procedure make-regexp: Error while printing exception.

Heh.  Fixed this error message to at least not print an exception:

  ERROR: In procedure make-regexp:
  ERROR: In procedure make-regexp: Invalid preceding regular expression

Still not very good, but it's what libc gives us.

> scheme@(guile-user)> (string-match "\?.*" "?wobble")
> While reading expression:
> ERROR: In procedure scm_lreadr: standard input:3:18: illegal character
> in escape sequence: #\?

OK! At this point "\? was read.  It was determined that ? was an invalid
escape char, so the read was aborted.  Unfortunately we were inside a
string.  What's left is .*" "?wobble", and thus the following errors:

> ;;; <unknown-location>: warning: possibly unbound variable `.*'
> ERROR: In procedure #<procedure 2183020 ()>:
> ERROR: In procedure module-lookup: Unbound variable: .*

Because we read the symbol `.*'.

> $1 = " "

Because we read the string " ".

> ;;; <unknown-location>: warning: possibly unbound variable `?wobble'
> ERROR: In procedure #<procedure 21ac020 ()>:
> ERROR: In procedure module-lookup: Unbound variable: ?wobble

Because we read ?wobble.

> And then it just hung and I needed to C-c C-c my way out.

Because we're inside a string, waiting for the ending ".

Ironically you could have ended it with a \? ;-)

I think the right thing to do here at the REPL is to flush all pending
input when a read error occurs.  I have pushed a patch to do that, I
believe.  Thanks for the report :)

Andy
-- 
http://wingolog.org/



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

end of thread, other threads:[~2011-02-27 22:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-18  4:11 Strange string-append and string-match behaviour Francis Southern
2011-02-27 22:27 ` 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).