10
\$\begingroup\$

Preface

I've 'failed' twice at this whole golf language design thing, once with JAISBaL and again with Clack. Now that I've had a go twice, I am obviously an expert and am attempting to design the perfect golfing language. One of the things in particular that annoys me about Clack, JAISBaL, Jelly, APL, etc. is the fact that they have some wonderfully strange characters. Not only can they be difficult to type (Jelly being the exception here), but I prefer just seeing some ASCII source code. Therefore, before I create my new language, I'm designing a character encoding. The standard character encoding, is of course, just a code page, but my encoding is a little different.

The Encoding

The idea is that the encoding only uses ASCII characters, but certain 2-character pairs are encoded as one byte. For example, a-zA-Z are all encoded as one byte, but @, ~ or _ followed by any a-zA-Z are also encoded as one byte. This means that, with this encoding, @A, ~x and _r are all one byte. There's other things that are strange to, such as " changing the behavior of the encoding itself, rather than just beginning a string, and the fact that ~@_ won't actually have there own bytes in the encoding, but will only serve as prefixes.

Encoding specification draft (may need refinement):

a-z A-Z = 52 bytes

~ @ _ = 156 bytes

`!#$%^&*()-+={}[]:;'<>,.?/\|1234567890  = 38 bytes

\n \t space = 3 bytes

"0 "1 "2 "3
"r "c "g = 7 bytes

---------------------------------------------------

a-z, A-Z and `!#$%^&*()-+={}[]:;'<>,.?/\|1234567890 
will each be represented by a single byte.

~ @ and _ will be prefixes, each can be followed by 
any of a-z A-Z, each of these pairs will be encoded
with a single byte.

\n \t and space will each be represented by a single
byte.

"0 "1 "2 "3 will signify the start of a string, and
will each be represented as 1 byte:
 - 0, 1, 2, 3 = use escape byte #0, #1, #2, or #3


"r "c "g will signify the end of a string and will
each be represented as 1 byte:
 - r = raw utf8
 - c = compressed
 - g = gzip

Question

Basically, is this allowed? Do we have any standards regarding how character encodings work? A loophole had been posted that forbade compression of source code (which this borders on), but it was downvoted & deleted, so I don't think I need to worry about it... UTF8 and the like also don't have a 1 byte = 1 character encoding, but the difference is that every character in this encoding would be 1 byte, or less than that... Would there be any reason this would be forbidden or banned? Thanks for any help!

\$\endgroup\$
  • 5
    \$\begingroup\$ I don't see any problem. As long as your interpreter/compiler can actually run weird-looking single-byte code (not needing it to be decoded first), it is just a language. Compare to TI-BASIC which encodes apparently long identifiers as single or two-byte tokens. \$\endgroup\$ – Adám Jun 27 '17 at 12:48
  • 1
    \$\begingroup\$ That's not a problem, but a user must actually be able to run the single-byte code without any other steps. \$\endgroup\$ – Adám Jun 27 '17 at 12:55
  • \$\begingroup\$ @Adám silly me... you mean decoded by hand first... yes that makes sense, it should be fine then, thanks... it'll all be bundled up in one program anyway :) \$\endgroup\$ – Socratic Phoenix Jun 27 '17 at 12:55
  • \$\begingroup\$ Why is Jelly the exception? Is there an easy way to type the dot-above/dot-below letter characters that I'm not aware of? \$\endgroup\$ – scatter Jun 27 '17 at 16:06
  • \$\begingroup\$ @Christian I'm not entirely sure how too, but the codepage says they are easy to type \$\endgroup\$ – Socratic Phoenix Jun 27 '17 at 16:30
  • \$\begingroup\$ @Christian I'm assuming Alt codes \$\endgroup\$ – Stephen Jun 28 '17 at 22:41
  • \$\begingroup\$ @SocraticPhoenix you need to have your keyboard set to "international layout." Says so on that page you linked. \$\endgroup\$ – Draco18s Jul 6 '17 at 14:09
19
\$\begingroup\$

Character encodings are just a convenience to make programs more readable if they make use of more than the usual 97 ASCII bytes (printable, plus linefeeds and tabs). At the end of the day, the only thing that matters is there must be an actual file with the claimed byte count that, when fed to your interpreter, runs the intended program. How you interpret the bytes (or bits) in that file as characters is entirely up to you, as is whether you internally or externally provide conversion methods between the unreadable binary file and the readable ASCII-only interpretation of the file.

\$\endgroup\$
  • 2
    \$\begingroup\$ Do we have any standard distinction between compilation and interpretation? Where does it cross the line from a syntax-aware encoding to a compilation to bytecode (this, I think, is especially vague in java's case, since it's bytecode is interpreted)? Great answer though, I was just wondering how far encodings can stretch... \$\endgroup\$ – Socratic Phoenix Jul 18 '17 at 12:27
  • 1
    \$\begingroup\$ This makes me want to make a golfing language with a TI-basic style tokeniser that converts into binary via a Huffman code, thus allowing commands to take up variable numbers of bits (not bytes!) and also being much more readable than Jelly style character encodings. (Actually I've been thinking about this for a while, but I'm not so likely to actually get around to it.) \$\endgroup\$ – Nathaniel Mar 31 '18 at 6:13
  • \$\begingroup\$ What if the character encoding encodes the program in bits instead of bytes? \$\endgroup\$ – PyRulez Nov 27 '18 at 22:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .