Recently I was reading this article about Esoteric Programming Languages, shortened form: esolangs.
Esolangs are generally created out of curiosity, for fun, sometime to test boundaries of computer programming but mostly they have very little practical significance, as they are not created keeping any particular problem in mind.
Yet they are interesting in a way that you don't have to put much brain to understand their semantics(most of the time but not for all). They are easy to learn hard to write, that give you code-writing challenges. There are many such languages exist, such as whitespaces, brainfuck, chef, lolcode, intercal etc.
So, last sunday I gave a try to learn and test one of them(which was BrainFuck). As its neither a complete-lost language nor a practically feasible one. Primary reason for choosing BrainFuck was reasonably simple though: the name itself (:D). But as I started writing code in it, I found it really challenging even to output a simple string.
Since the term itself seems to be derogatory, I will call it #BF from here on.
#BF was invented by Urban Müller, whose goal was to create the smallest possible compiler, which is 171 bytes in size (as of now). The language has only 8 operators that are all written as a single character. The 8 operators are: + - < > [ ] . ,
- + increase byte under pointer
- - decrease byte under pointer
- > increase pointer
- < decrease pointer
- [ start a loop if byte under pointer is not 0
- ] return to matching [
- . print byte under pointer to standard output (often screen)
- , read input from standard input (often keyboard) to byte under pointer
#BF heavily depends on your understanding of data-pointers.
A simple string like 'MUKESH' can be written as:
++++++++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/80
> +++++ ++ add 7 to cell #1
> +++++ +++ add 8 to cell #2
<<- decrement counter (cell #0)
]
>>---. print 'M' ASCII value: 77 i.e pointer moves 3 step behind cell#2
++++++++. print 'U' ASCII value: 85 i.e. pointer moves 8 step ahead
<+++++. print 'K' ASCII value: 75 i.e. pointer steps back to cell#1
------. print 'E' ASCII value: 69 i.e. pointer moves 6 step behind
>--. print 'S' ASCII value: 83 and so on...
<+++. print 'H' ASCII value: 72
And now after this small but succinct session on #BF, here is a simple program for you to scratch your head :P.
//Starts here
+++++ +++++
[
> +++
> +++++ ++
> +++++ +++
> +++++ ++++
> +++++ +++++
> +++++ +++++ +
<<<<<<-
]
>>+.
>>>>+.
.
<.
<<<<+++.
-.
>>>>>+++++ +++++.
----- -----.
+++++ +.
<<<<<.
>>>>-.
>---.
<--.
++.
>----- --.
<<<<<.
>>>>+++++ +.
>+++++ ++++.
<<<<<+++++ +++++ ++++.
----- ----- ----.
>>--.
>>>-----.
+++++ +++.
<<<<<.
+++++ +++++.
.
.
.
----- -----.
>>>>>----- ---.
<---.
.
<<<<+.
.
.
//Ends here
Note: [Part of it is taken from wiki and other references. Code snippets are mine though. Enjoy reading and please give your valuable suggestions on improvement of further posts. Thanks :)]