0
\$\begingroup\$

I am currently writing my own language and have a few queries about it, namely the custom code-page that it uses. It is well-known that languages have custom code-pages to avoid multibyte characters such as Jelly and Ohm but I have never heard of a language having more than one.

The actual problem here is: I have the commands decided, that take up 256 places on the code-page. But I'm starting on the string compressor that uses a special set of characters that aren't part of the original code-page. I have though of two solutions but wasn't sure if either of these were allowed:

1) Have a code page which uses base 23 (the closest to having 512 characters on it)

2) Use one code-page for the actual program and one for the string compressor.

I'm not sure if either of these are allowed on this site and was wondering if anyone could tell me. However, if you can think of a better solution, feel free to post it as an answer.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ I'm not sure how this would work. At the end of the day, the score of your programs will be the physical size of a file which your interpreter understands. How you interpret the bytes in that file as characters is up to you. \$\endgroup\$ May 17 '17 at 16:57
  • \$\begingroup\$ @MartinEnder so does that mean that theoretically a language could have a code page with 20000 characters on it, all interpreted as 1 byte? \$\endgroup\$ May 17 '17 at 16:58
  • 2
    \$\begingroup\$ Consider this: No matter what you decide to do, you need a bijective mapping between each character and its codepoint. If you want 512 characters, I believe you can do a 9-bit codepage and have partial byte scores but I'm not sure on that. \$\endgroup\$
    – user42649
    May 17 '17 at 17:00
  • \$\begingroup\$ @Satan'sSon No. With 1 byte, you can only have up to 2**8=256 characters. \$\endgroup\$
    – user42649
    May 17 '17 at 17:00
  • \$\begingroup\$ @HyperNeutrino why? \$\endgroup\$ May 17 '17 at 17:01
  • \$\begingroup\$ I can explain in chat. \$\endgroup\$
    – user42649
    May 17 '17 at 17:02
  • 4
    \$\begingroup\$ @Satan'sSon I'll be impressed if you can write an interpreter that can do 20000 different things given only 1-byte source files. \$\endgroup\$ May 17 '17 at 17:03
  • \$\begingroup\$ @MartinEnder now this sounds like an interesting lang-design challenge. Imagine a language (we'll call it a Malbolge-like) where each 2-byte pair represents a given instruction. The trick is that while ab does one thing (and only one thing), abc does two: ab then bc (and then abcd does three: ab, bc, and cd). We end up needing N+1 bytes of physical size to store a program of N instructions, but we can have up to 65536 code points. Fewer as we'd probably want 0b0000000 in each 256-page to be a noop so that the language is functional. Would be diabolical to golf though. \$\endgroup\$ May 17 '17 at 19:03
  • \$\begingroup\$ @MartinEnder Thank you so much! I've almost finished this language and now have a new challenge! I will notify you when finished. \$\endgroup\$ May 17 '17 at 19:18
4
\$\begingroup\$

You can use any code-page or combination you like, but...

Your score will always be the number of bytes in the smallest file needed to make your program work.

This means that when you run wc -c file, the output is the score for your program.

It's really as simple as that. When Dennis says Jelly uses a custom code-page, this doesn't mean he arbitrarily selected a bunch of characters that are allowed to be counted as one byte. It means that each character directly maps to a byte value. At the end of the day, every Jelly program (as well as every program in any language whatsoever) is just a sequence of bytes. Mapping these bytes to characters is just for human convenience.

You will not be able to store more than 256 different characters in 1 byte, no matter what code page you use. This is not because of PPCG rules, but because of math and computer architecture.

\$\endgroup\$
0
4
\$\begingroup\$

What are these bytes exactly?

In any given character encoding, each character corresponds to a number. For example, in ASCII, 'a' is 97 which is 01100001 in binary. That's 8 bits, so it fits in a byte. Each character corresponds to a number, and to avoid wasting space in Single Byte Character Sets (SBCSs), each number corresponds to a character as well.

How are bytes counted?

If we map each character to its binary representation, then we see that each character is a byte (in the case of an SBCS at least).

Why can't you encode more than 256 characters with an SBCS then?

The mapping between characters and bytes must be bijective. That is, each character maps to only one number, and each number maps to only one character. A byte can only represent 2 ** 8 = 256 different things, and consequently, you can only encode 256 characters using one byte.

\$\endgroup\$

You must log in to answer this question.

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