1

I'm having a bit of an issue trying to do an ascii art challenge in GS, since it requires you finishing a line with the \ symbol.

The problem is that "\"p breaks the program since it thinks you escaped a quote, and "\\"p prints two backslashes. I've tried string concatenation, removing one character at a time, printing substrings, etcetc - Nothing seems to work!

I need this string to be printed out, so how would this be done?

Mathgeek
  • 174
  • 1
  • 6

2 Answers2

0

It seems that the behavior with p is buggy. I'll look for a place to report it.

However, "\\" by itself does not print two backslashes; it prints one.

Here's a test link to prove it.

Output:

\
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • But yeah, stack-output isn't my issue - my problem is not stack-output-printing, but *using the print command*. [Two prints two](https://tio.run/##S8/PSStOLsosKPn/XykmRqng/38A "GolfScript – Try It Online") [One throws an error](https://tio.run/##S8/PSStOLsosKPn/XylGqeD/fwA "GolfScript – Try It Online") So is it just that print is awfully buggy, or does the stack output use a different function? – Mathgeek Feb 24 '20 at 13:12
  • @Mathgeek Probably a bug. I emailed the maintainer. No response yet. – S.S. Anne Feb 24 '20 at 14:24
  • @Mathgeek not a bug – Darren Smith Oct 12 '22 at 13:23
-2

"\\" creates a string with 1 backslash because strings are escaped. This is the same as languages like Ruby.

p escapes strings, so a string with one backslash will be displayed as two. This is also the same as languages like Ruby.

So if you want to print a single backslash, or print things without the quotes, you need to print unescaped strings. The best way to do this is with implicit IO (anything on the stack that is left over is printed unescaped).

The program

"\\"

Should print

\

You could also use print or puts if you don't want to use implicit IO.

Darren Smith
  • 207
  • 1
  • 4