We need some operators.
Assignment\\
//variable// IZ (//literal|variable|expression//)
I HAS A VAR
VAR IZ 10
VAR IZ "foo"
Integer increment\\
UP //variable//!!//literal//
UP VAR!!1
UP VAR!!7
Integer decrement\\
NERF //variable//!!//literal//
NERF VAR!!1
NERF VAR!!7
String concatenation\\
(//string_literal|variable//) N (//string_literal|variable//)
I HAS A VAR
VAR IZ "foo"
VISIBLE VAR N " bar"
----
When we were playing around on IRC, we liked the following for assignment:
LOL R
I also want to pull in the -- shorthand that was used in another article:
NERF !!
And I agree with what the previous poster said, I think (for optimization purposes?) that the *!!<> syntax should only accept a literal.
Now, a few things I was thinking about for math. One thing I think would be interesting would be to do reverse polish notation or stack based math. Granted, it might not make the code the most legible, but this is LOLCODE!
Example: (C, then LOLCODE)
// C
varF = varA + varB * varC / varD - varE
BTW LOLCODE
FIGGER VARE VARD VARB VARC
BTW {Top:VARC,VARB,VARD,VARE}
FIGGER TIMEZ DIVIDE
BTW {Top:VARB*VARC/VARD,VARE}
FIGGER MINUZ VARA ADDZ
BTW {Top:(VARB*VARC/VARD)-VARE+VARA}
I FIGGERED OUT VARF
One big advantage that this would have is that we wouldn't have to define order of operations and we wouldn't have to use punctuation to group things in our math.
--- //Kyle, 2007/05/29 04:33//
----
I've also thought about math, and my idea would be to have it graphically represent what its supposed to do, within HAXOR and HAXORED tags:
I HAS A VAR
VAR IZ HAXOR
(C) (A*B)
(___A_+_B___)+(A+B)
( 3*4 )
HAXORED
which would be the same as
var = (a+Math.pow(b,c))/(3*4)+Math.pow(a+b,a*b)
--- //Marius, 2007/05/29 11:04//
NERF works for me. FIGGER might be a bit too much. I guess it depends on how evil we want to be...but that seems //quite// evil. ;) HAXOR is a neat idea...my only complaint is that it is whitespace dependent, which is a pet peeve of mine. --- //ILikePi, 2007/05/29 12:42//
----
I don't know that it's been officially stated before, but we need to spell out the numerical operators. Here's a list so far, assuming Polish Notation to signify order, which is [[contributions:signify-order|being discussed]]:
- NERF : decrement
- NERF VAR : decrement VAR by 1
- NERF VAR!!FOO : decrement VAR by FOO
- UP : increment
- UP VAR : increment VAR by 1
- UP VAR!!FOO : increment VAR by FOO
- ADDZ : add
- 5 4 ADDZ -> 9
- TIMEZ : multiply
- 5 4 TIMEZ -> 20
- DIVIDEZ : divide
- 5 4 DIVIDEZ -> 1.25
I also propose:
- MINUSEZ : subtract
- 5 4 MINUSEZ -> 1
I don't particularly like this, or MINUZ. TAKEZAWAY is interesting, but unweildy.
- POWERZ : to the power of
- 5 4 TIMEZ -> 625
We also need to codify comparisons. I've seen:
- BIGGER THAN : greater than
I propose
- SMALLER THAN : less than
- SAMEZ AS : equal to
I think the boolean operators not, and and or, should just be NOT, AND and OR. However, while workable, I don't think postfix boolean operators read as well as postfix arithmetic. This means we may need some sort of precedence operator, like parenthesis or something.
--- //Risser, 2007/05/29 17:24//
----
Here's an interesting opportunity to use 1UP for the increment operator:
I HAS A VARBL IZ 0
1UP VARBL
BTW VARBL is now 1
By extension, you can use 2UP, 3UP, etc.
--- //z7q2, 2007/05/30 16:52//
----
Wouldn't MOAR work better for an increment operator?
I HAS INTERNETS ITZ 12
MOAR INTERNETS
BTW INTERNETS is now 13
UP has more of a nested condition or loop connotation for me. MOAR is totally unambiguous. Is MOAR already used elsewhere?
--- //Ben Reiter, 2007/05/30 18:48//
----
Shouldn't BUFF be the opposite of NERF? Although I like MOAR as an incrementer, too.
And a silly idea for testing equality:
foo AN bar ALL LOOK SAME
--- //Geordan Rosario, 2007/05/30 21:30//
----
Shift Operators
I originally suggested using [[ZOMG]], OMGZ, and OMFGZ as shift operators. However, you can't really tell at first glance what they are supposed to do, so I propose the following instead:
BTW LOLCODE : // standard
a SHIFLOL b : a << b
SHIFLOLZ a!!b : a <<= b
a SHIFZOR b : a >> b
SHIFZORZ a!!b : a >>= b
Like C, whether a right shift is arithmetic or logical should depend on the variable type, whenever that gets sorted out.
--- //Tristan Griffith, 2007/06/01 02:41//