Arc Forumnew | comments | leaders | submitlogin
Atpos bug?
1 point by dreisigmeyer 5644 days ago | 1 comment
If I make the following calls, e.g.:

> (atpos "@@hjk@" 0) string-ref: index 7 out of range [0, 5] for string: "@@hjk@" > (atpos "@hjk@" 1) string-ref: index 6 out of range [0, 4] for string: "@hjk@"

atpos from ac.scm is below. This is using DrRacket 5.0.1.

Thanks, -Dave

(define (atpos s i) (cond ((eqv? i (string-length s)) #f) ((eqv? (string-ref s i) #\@) (if (and (< (+ i 1) (string-length s)) (not (eqv? (string-ref s (+ i 1)) #\@))) i (atpos s (+ i 2)))) (#t (atpos s (+ i 1)))))



2 points by rocketnia 5644 days ago | link

What do you expect it to do?

In case you didn't know, the point of 'atpos is to implement atstrings, an optional string interpolation feature that lets "@qty @(plural qty \"taco\") @@ $@price" compile so that it evaluates to things like "2 tacos @ $11". This option isn't enabled by default, so any Arc program that uses atstrings, such as news.arc, has to (declare 'atstrings t) first.

IMO, an @ at the end of an atstring is a syntax error, since it isn't escaping anything. It might be convenient to give "...@" a meaning like (sym "..."), (err "..."), or even just "...@@", but that's adding functionality rather than fixing bugs.

-----