blob: 217b7b7dfbf2747f392cfab23efc18eda6ecfb2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
---
language: LOLCODE
filename: learnLOLCODE.lol
contributors:
- ["abactel", "https://github.com/abactel"]
---
LOLCODE is an esoteric programming language designed to resemble the speech of [lolcats](https://upload.wikimedia.org/wikipedia/commons/a/ab/Lolcat_in_folder.jpg?1493656347257).
```
BTW This is an inline comment
BTW All code must begin with `HAI <language version>` and end with `KTHXBYE`
HAI 1.3
CAN HAS STDIO? BTW Importing standard headers
OBTW
==========================================================================
================================= BASICS =================================
==========================================================================
TLDR
BTW Displaying text:
VISIBLE "HELLO WORLD"
BTW Declaring variables:
I HAS A MESSAGE ITZ "CATZ ARE GOOD"
VISIBLE MESSAGE
OBTW
(This is a codeblock.) Variables are dynamically typed so you don't need to
declare their type. A variable's type matches its content. These are the
types:
TLDR
I HAS A STRING ITZ "DOGZ ARE GOOOD" BTW type is YARN
I HAS A INTEGER ITZ 42 BTW type is NUMBR
I HAS A FLOAT ITZ 3.1415 BTW type is NUMBAR
I HAS A BOOLEAN ITZ WIN BTW type is TROOF
I HAS A UNTYPED BTW type is NOOB
BTW Accepting user input:
I HAS A AGE
GIMMEH AGE
BTW The variable is stored as a YARN. To convert it into NUMBR:
AGE IS NOW A NUMBR
OBTW
==========================================================================
================================== MATH ==================================
==========================================================================
TLDR
BTW LOLCODE uses polish notation style math.
BTW Basic mathematical notation:
SUM OF 21 AN 33 BTW 21 + 33
DIFF OF 90 AN 10 BTW 90 - 10
PRODUKT OF 12 AN 13 BTW 12 * 13
QUOSHUNT OF 32 AN 43 BTW 32 / 43
MOD OF 43 AN 64 BTW 43 modulo 64
BIGGR OF 23 AN 53 BTW max(23, 53)
SMALLR OF 53 AN 45 BTW min(53, 45)
BTW Binary notation:
BOTH OF WIN AN WIN BTW and: WIN if x=WIN, y=WIN
EITHER OF FAIL AN WIN BTW or: FAIL if x=FAIL, y=FAIL
WON OF WIN AN FAIL BTW xor: FAIL if x=y
NOT FAIL BTW unary negation: WIN if x=FAIL
ALL OF WIN AN WIN MKAY BTW infinite arity AND
ANY OF WIN AN FAIL MKAY BTW infinite arity OR
BTW Comparison:
BOTH SAEM "CAT" AN "DOG" BTW WIN if x == y
DIFFRINT 732 AN 184 BTW WIN if x != y
BOTH SAEM 12 AN BIGGR OF 12 AN 4 BTW x >= y
BOTH SAEM 43 AN SMALLR OF 43 AN 56 BTW x <= y
DIFFRINT 64 AN SMALLR OF 64 AN 2 BTW x > y
DIFFRINT 75 AN BIGGR OF 75 AN 643 BTW x < y
OBTW
==========================================================================
============================== FLOW CONTROL ==============================
==========================================================================
TLDR
BTW If/then statement:
I HAS A ANIMAL
GIMMEH ANIMAL
BOTH SAEM ANIMAL AN "CAT", O RLY?
YA RLY
VISIBLE "YOU HAV A CAT"
MEBBE BOTH SAEM ANIMAL AN "MAUS"
VISIBLE "NOM NOM NOM. I EATED IT."
NO WAI
VISIBLE "AHHH IS A WOOF WOOF"
OIC
BTW Case statement:
I HAS A COLOR
GIMMEH COLOR
COLOR, WTF?
OMG "R"
VISIBLE "RED FISH"
GTFO
OMG "Y"
VISIBLE "YELLOW FISH"
BTW Since there is no `GTFO` the next statements will also be tested
OMG "G"
OMG "B"
VISIBLE "FISH HAS A FLAVOR"
GTFO
OMGWTF
VISIBLE "FISH IS TRANSPARENT OHNO WAT"
OIC
BTW For loop:
I HAS A TEMPERATURE
GIMMEH TEMPERATURE
TEMPERATURE IS NOW A NUMBR
IM IN YR LOOP UPPIN YR ITERATOR TIL BOTH SAEM ITERATOR AN TEMPERATURE
VISIBLE ITERATOR
IM OUTTA YR LOOP
BTW While loop:
IM IN YR LOOP NERFIN YR ITERATOR WILE DIFFRINT ITERATOR AN -10
VISIBLE ITERATOR
IM OUTTA YR LOOP
OBTW
=========================================================================
================================ Strings ================================
=========================================================================
TLDR
BTW Linebreaks:
VISIBLE "FIRST LINE :) SECOND LINE"
BTW Tabs:
VISIBLE ":>SPACES ARE SUPERIOR"
BTW Bell (goes beep):
VISIBLE "NXT CUSTOMER PLS :o"
BTW Literal double quote:
VISIBLE "HE SAID :"I LIKE CAKE:""
BTW Literal colon:
VISIBLE "WHERE I LIVE:: CYBERSPACE"
OBTW
=========================================================================
=============================== FUNCTIONS ===============================
=========================================================================
TLDR
BTW Declaring a new function:
HOW IZ I SELECTMOVE YR MOVE BTW `MOVE` is an argument
BOTH SAEM MOVE AN "ROCK", O RLY?
YA RLY
VISIBLE "YOU HAV A ROCK"
NO WAI
VISIBLE "OH NO IS A SNIP-SNIP"
OIC
GTFO BTW This returns NOOB
IF U SAY SO
BTW Declaring a function and returning a value:
HOW IZ I IZYELLOW
FOUND YR "YELLOW"
IF U SAY SO
BTW Calling a function:
I IZ IZYELLOW MKAY
KTHXBYE
```
## Further reading:
- [LCI compiler](https://github.com/justinmeza/lci)
- [Official spec](https://github.com/justinmeza/lolcode-spec/blob/master/v1.2/lolcode-spec-v1.2.md)
|