Arc Forumnew | comments | leaders | submitlogin
Atstring problem
4 points by lg 5568 days ago | 6 comments
I think I found a bug with atstrings. I was trying to escape the @ with a backslash, and it gave me an error, and caused arc to behave strangely and hang until I ctrl-C'd and (tl)'d back. arc> (declare 'atstrings t) t arc> (= x 1) 1 arc> "@x" "1" arc> "\@x" Error: "UNKNOWN::36: read: unknown escape sequence \\@ in string" arc> 1 (this line was printed by arc, not me typing) arc> "@x" "\n" arc> Error: "reference to undefined identifier: _@x" (also printed by arc) arc> x (arc hangs until i ctrl-C)


1 point by conanite 5568 days ago | link

My favourite topic!

You'll also need to watch out for this:

  arc> (declare 'atstrings t)
  #<void>
  arc> (assign user "conanite")
  "conanite"
  arc> "/Users/@user"
  "/Users/conanite"
  arc> "/Users/@user/file.arc"
  Error: "reference to undefined identifier: _user/file"
  arc> 
I confess, this is a seriously contrived example: nested strings need to be escaped -

  arc> "database/@(+ user "_file.arc")"
  Error: "UNKNOWN::0: read: expected a `)'"
  arc> Error: "reference to undefined identifier: __file"
  arc> ")"

  arc> "database/@(+ user \"_file.arc\")"
  "database/conanite_file.arc"
  arc>
This is because arc relies on the scheme reader, which doesn't know anything about atstrings; the arc compiler later compiles "a @b c" into (string "a " b " c"). "\@" isn't a valid string escape sequence in scheme, so arc has to use "@@" instead.

I know this is more than you asked, but I just had to vent :)

[forum hint] Indent code samples with two spaces and delimit with blank lines to get it to format properly

-----

1 point by lg 5568 days ago | link

whoops, I forgot about the formatting and now it's too late to edit.

Maybe my original problem wasn't important then. Also it seems like your first problem means there should be more parens for disambiguation. "x/@(y)/z" or "x/@((funcall))/z" etc. "add more parens" always seems too easy to be right, though :)

-----

3 points by palsecam 5568 days ago | link

I agree the interpreter behaviour is kind of strange here.

Anyway, if you don't already know it, use "@@" to escape "@", and not "\@".

-----

2 points by pg 5567 days ago | link

Right: @@ to escape. Eventually I'll take over the reader, but it's not the top priority at the moment.

I'm not sure I'll even keep @strings. I find I don't use them as much as I expected. Does anyone use them a lot?

-----

1 point by rntz 5566 days ago | link

I find them quite useful for my irc bot, although I do run into the problem of not being able to @-substitute a simple variable unless it's going to be followed by something not permissible in a symbol. In particular, colons will be parsed as part of the symbol, which is a PITA. There is a workaround for this, but it's ugly:

  arc> (with (nick 'hbovik msg "hullo there") "@(idfn nick): @msg")
  "hbovik: hullo there"

-----

1 point by coconutrandom 5566 days ago | link

I tried for half a second, but dropped it in favor of string substitution.

-----