2022-12-09 04:45:46 +00:00
|
|
|
```
|
2022-12-09 04:46:43 +00:00
|
|
|
/* _ _ _
|
|
|
|
| | / | / /
|
|
|
|
| |__| ||__ _ _ __ __ _ / /
|
|
|
|
| '_ | |/ ' | '_ \ / _' | / /
|
|
|
|
| \_|| | || | | | | /_| | /_/
|
|
|
|
\___/_____/___| |__,_ / _
|
|
|
|
|____/ */
|
2022-12-09 04:45:46 +00:00
|
|
|
```
|
|
|
|
# blang!
|
|
|
|
the bang language
|
2022-12-09 04:41:52 +00:00
|
|
|
|
2022-12-09 04:45:46 +00:00
|
|
|
Public domain. 2022 DTB.
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
Bang language is an unpleasant toy designed to be used in the murderu.us IRC
|
|
|
|
server, but easily adapted anywhere due to its simplicity both in terms of
|
|
|
|
model and implementation.
|
|
|
|
|
2022-12-11 03:56:17 +00:00
|
|
|
## Glossary
|
|
|
|
|
|
|
|
### chart
|
|
|
|
|
|
|
|
The listing of the program currently running.
|
|
|
|
This can be modified during runtime.
|
|
|
|
|
|
|
|
### command
|
|
|
|
|
|
|
|
A character that indicates what the bang language executor should do next.
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
### comment
|
|
|
|
|
|
|
|
Ornamental characters, i.e. in-code notes.
|
|
|
|
|
|
|
|
Comments can start with `';'` (in which case they're discarded from the chart)
|
|
|
|
or `'#'` (in which case they're kept on the chart).
|
|
|
|
|
|
|
|
Comments end with `'!'` or `'\n'`.
|
|
|
|
|
2022-12-11 03:56:17 +00:00
|
|
|
### hand
|
|
|
|
|
|
|
|
The general-purpose register.
|
|
|
|
|
|
|
|
### catch
|
|
|
|
|
|
|
|
To set the hand to a value.
|
|
|
|
|
|
|
|
### throw
|
|
|
|
|
|
|
|
To set a value to the contents of the hand.
|
|
|
|
|
|
|
|
## Reference
|
|
|
|
|
|
|
|
All operations are one character long.
|
|
|
|
When an unknown operation is executed the resulting behavior is undefined
|
2022-12-21 05:12:26 +00:00
|
|
|
(and maliciously so; for example, execution can stop or garbage can be written
|
|
|
|
to the chart).
|
|
|
|
|
|
|
|
Operation mappings are based on ergonomics and history.
|
|
|
|
`'&'` and `'*'` are taken from C.
|
|
|
|
`'+'` and `'-'` are taken from Brainfuck.
|
|
|
|
`'<'` and `'>'` are more or less taken from the Bourne shell.
|
|
|
|
The general ergonomics of bang language are informed by the story of Mel,
|
|
|
|
part of hacker folklore.
|
2022-12-11 03:56:17 +00:00
|
|
|
|
|
|
|
### `'!'`
|
|
|
|
|
|
|
|
No-op. Does nothing.
|
|
|
|
`' '`, `'\n'`, `'\r'`, `'\t'`, and `'\v'` are all also no-ops
|
|
|
|
\- keep this in mind when styling code that contains `'?'`!
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
### `'#'`
|
2022-12-11 03:56:17 +00:00
|
|
|
|
|
|
|
Denotes a comment.
|
2022-12-21 05:12:26 +00:00
|
|
|
The contents of the comment are kept in the chart but not executed.
|
|
|
|
|
|
|
|
### `';'`
|
2022-12-11 03:56:17 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
Denotes a comment.
|
|
|
|
The contents of the comment are discarded from the chart before runtime.
|
2022-12-11 03:56:17 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
### `'^'` and `'%'`
|
2022-12-11 03:56:17 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
`'^'` palms the content of the location of the program to which chart points.
|
|
|
|
`'%'` throws at that location.
|
2022-12-11 03:56:17 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
The following program prints "Hello, world!",
|
|
|
|
by iterating over the program listing itself and terminating after printing a
|
|
|
|
line feed (10 decimal in ASCII):
|
|
|
|
```
|
|
|
|
!Hello, world!
|
|
|
|
{
|
|
|
|
&+*
|
|
|
|
^>
|
|
|
|
----------?}; subtract 10, if the value is non-zero return
|
|
|
|
vv*
|
|
|
|
```
|
2022-12-11 03:56:17 +00:00
|
|
|
|
|
|
|
### `'&'` and `'*'`
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
`'&'` (et) palms the chart. `'*'` (splat) throws the chart.
|
2022-12-11 03:56:17 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
The following program rewrites itself during runtime, navigating the chart
|
|
|
|
using et and splat. Keep in mind `'!'` must be followed by `';'` in comments
|
|
|
|
to maintain chartlessness:
|
2022-12-11 03:56:17 +00:00
|
|
|
|
|
|
|
```
|
2022-12-21 05:12:26 +00:00
|
|
|
!vv; zero out hand
|
2022-12-11 03:56:17 +00:00
|
|
|
{?>; set return point; if hand is non-zero, print hand
|
2022-12-21 05:12:26 +00:00
|
|
|
!&; palm the chart
|
|
|
|
++++*; add 4 to palm; splat the new chart
|
|
|
|
<!%; write '!;' to the new chart position
|
2022-12-11 03:56:17 +00:00
|
|
|
&++*; palm the chart; add 2 to palm; splat the new chart
|
|
|
|
<<%; write '<' to the new chart position
|
|
|
|
&+*; advance the chart one space
|
|
|
|
<
|
|
|
|
%; write '\n' to the new chart position
|
|
|
|
&+*; advance the chart one space
|
|
|
|
<>%; write '>' to the new chart position
|
|
|
|
&+*; advance the chart one space
|
2022-12-21 05:12:26 +00:00
|
|
|
<v%; write 'v' to the new chart position
|
|
|
|
&+*; advance the chart one space
|
|
|
|
<v%; write 'v' to the new chart position
|
|
|
|
<!; palm '!;'
|
2022-12-11 03:56:17 +00:00
|
|
|
}; return
|
|
|
|
```
|
|
|
|
|
|
|
|
Right before the final `'}'`, the chart is the following:
|
|
|
|
|
|
|
|
```
|
2022-12-21 05:12:26 +00:00
|
|
|
!vv; zero out hand
|
2022-12-11 03:56:17 +00:00
|
|
|
{!>; print hand
|
|
|
|
<
|
|
|
|
>; palm `'\n'`; print hand
|
2022-12-21 05:12:26 +00:00
|
|
|
vv*; splat zero to chart
|
2022-12-11 03:56:17 +00:00
|
|
|
|
|
|
|
The rest of the program isn't executed.
|
|
|
|
```
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
### `'<'` and `'>'`
|
|
|
|
|
|
|
|
`'<'` palms the next character literal.
|
|
|
|
|
|
|
|
`'>'` prints the literal contents of hand to standard output.
|
|
|
|
|
|
|
|
The following program prints "Hello, world!" the easy way:
|
2022-12-09 04:45:46 +00:00
|
|
|
|
|
|
|
```
|
2022-12-21 05:12:26 +00:00
|
|
|
!<H><e><l><l><o><,>< ><w><o><r><l><d><!>v++++++++++>v*
|
|
|
|
```
|
|
|
|
|
|
|
|
This is a quine; a program that prints itself.
|
2022-12-10 02:05:38 +00:00
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
```
|
|
|
|
{&+*!^>v?}v*
|
2022-12-09 04:45:46 +00:00
|
|
|
```
|
|
|
|
|
2022-12-21 05:12:26 +00:00
|
|
|
The following program prints the printable ASCII space:
|
|
|
|
|
2022-12-09 04:45:46 +00:00
|
|
|
```
|
2022-12-21 05:12:26 +00:00
|
|
|
!^*{; palm bang (the first printable ASCII char), splat
|
|
|
|
&>+*; et, throw onto screen, increment, splat
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------
|
|
|
|
------; subtract 126
|
|
|
|
v?}; if hand == 0, return
|
|
|
|
<
|
|
|
|
>; print newline
|
|
|
|
vv*; exit
|
2022-12-09 04:45:46 +00:00
|
|
|
```
|