224 posts
Location
Auckland, New Zealand
Posted 31 January 2013 - 06:22 PM
Hello I have a question:
What do <= and >= do / mean?
I've seen codes which use them and I don't actually know what they mean, I do know that they can be used in the making of Menu's / GUI's / OS's.
I've searched the wiki, wikipedia, lua wiki for an explaination and I cannot find any information that details on how to use these >= and <=
- What do they do?
- How do I use them?
- What are they called?
- How they work?
Thanks, AnthonyD98
758 posts
Location
Budapest, Hungary
Posted 31 January 2013 - 06:49 PM
They are expressions, just ike < or >
For example
lua> 5 == 6
false
lua> 5 ~= 6
true
lua> 5 < 6
true
lua> 5 > 6
false
lua> 5 >= 6 -- greater or equal
false
lua> 5 <= 6 -- lower or equal
true
1054 posts
Posted 31 January 2013 - 06:52 PM
- What are they called?
To be precise, they are called 'comparison operators'. LBPHacker listed all of them.
224 posts
Location
Auckland, New Zealand
Posted 31 January 2013 - 07:01 PM
It makes sense now, (kinda :P/>)
Also what does ~= mean?
2088 posts
Location
South Africa
Posted 31 January 2013 - 07:05 PM
It makes sense now, (kinda :P/>)
Also what does ~= mean?
Not equal to
8543 posts
Posted 31 January 2013 - 07:19 PM
The comparison operators are:
== is equal to
~= is not equal to
>= is greater than or equal to
<= is less than or equal to
> is greater than
< is less than
7508 posts
Location
Australia
Posted 31 January 2013 - 10:06 PM
Also this
if x ~= 4 then
(is not equal to) is equivalent to saying
if not x == 4 then
its just a nice shorthand. however sometimes for readability some people do this
if not (x == 1 and x == 4 and x == 6) then
this says if x is not 1, 4 or 6 then perform these tasks.
Also to cover what no one has said / is division. its an arithmetic (maths) operator
+ is addition
- is subtraction or unary negation (negative numbers)
* is multiplication
/ is divide
^ is exponentiation (to the power of)% is modulo/modulus (remainder of division)
96 posts
Posted 31 January 2013 - 10:34 PM
~= is not equal to
Hm,
this page says ~= but
this one has != in all its examples. Do both work? What about <>?
7508 posts
Location
Australia
Posted 31 January 2013 - 10:42 PM
~= is not equal to
Hm,
this page says ~= but
this one has != in all its examples. Do both work? What about <>?
!= is used in C style languages and Java as ! means not, so in an if statement in Lua like this
if not x == 4 then
would be this
if !(x == 4) {
in a C style language of course its just easier to type
if x != 4 {
but obviously not the point I was trying to make ;)/> …
Normally Lua is a wrapper on top of C++ (i think, sounds right :P/> ), meaning you can type C++ syntax and it would still work. Unfortunately our brand of Lua you can't use C syntax so no != cannot be used in the place of ~=
<> does not work either, a simple Googling of "Operators Lua" yields this:
http://www.lua.org/pil/3.2.html
1054 posts
Posted 31 January 2013 - 10:45 PM
if not (x == 1 and x == 4 and x == 6) then
this says if x is not 1, 4 or 6 then perform these tasks.
That will just always perform the task. The expression between parentheses will never be true. Anyway, he can read more about it on the wikipage of
De Morgan's Law .
Also to cover what no one has said / is division. its an arithmetic (maths) operator
I'm quite sure that the '/' in the title and question is purely splitting two verbs. Like 'what do <= and >= do' / 'what do <= and >= mean' .
~= is not equal to
Hm,
this page says ~= but
this one has != in all its examples. Do both work? What about <>?
I saw the example on that page, the '!=' is used in C++ examples (as TheOriginalBit seems to have ninjafied on me).
7508 posts
Location
Australia
Posted 31 January 2013 - 10:49 PM
That will just always perform the task. The expression between parentheses will never be true.
Ugh I could have sworn I typed 'or' … maybe its time for bed…
I'm quite sure that the '/' in the title and question is purely splitting two verbs. Like 'what do <= and >= do' / 'what do <= and >= mean' .
hmmm never read it that way, oh well, I told them about the ^ and % which quite a few don't know about, so maybe it could be useful if they didn't know :P/>
1054 posts
Posted 31 January 2013 - 11:08 PM
One more thing…
Normally Lua is a wrapper on top of C++ (i think, sounds right :P/> ), meaning you can type C++ syntax and it would still work.
Lua is written in clean C, not C++. And, ehm, you can't use C++ nor C syntax in Lua… Even if it 'would' be a wrapper around C/C++, a programming language can never breaks it syntax, that's the point about context-free languages. And to wrap it up, I don't believe that wrapper is the right word, Lua can be written in any language and libraries can use the API from numerous other programming languages. The language a program (interpreter in this case) is written in hardly matters when everything is compiled to a binary before runtime anyway (except when it's emulated, but let's not go there).
96 posts
Posted 31 January 2013 - 11:25 PM
Aah, I didn't realise that those examples are all C code and not Lua - I wasn't paying attention, I should have noticed the {} and ; etc. D'oh! So it's ~= and only ~=, no != or <>. Got it.
7508 posts
Location
Australia
Posted 31 January 2013 - 11:34 PM
a programming language can never breaks it syntax
Not true. For example I can type some C snippets when programming in Obj-C and it is fine, which obviously is breaking Obj-C syntax.
96 posts
Posted 31 January 2013 - 11:44 PM
a programming language can never breaks it syntax
Not true. For example I can type some C snippets when programming in Obj-C and it is fine, which obviously is breaking Obj-C syntax.
I think he meant "breaking the fourth wall", where for example you write some C code in a language that is implemented in C and it works
because it's implemented in C. Compiled languages can't do that, but interpreted languages can if they have an "eval" or "exec" type statement that takes a string and runs it as though it were a language statement. You can write C code ib Obj-C because Obj-C is a superset of C, not because it's written in C. Even if Obj-C were written in Pascal, you still couldn't use Pascal syntax in Obj-C and so the wall is not broken.
1054 posts
Posted 31 January 2013 - 11:44 PM
a programming language can never breaks it syntax
Not true. For example I can type some C snippets when programming in Obj-C and it is fine, which obviously is breaking Obj-C syntax.
Yeah, you're kinda true. I read something yesterday about the c++ compilers compiling syntactically incorrect code. But that's not common (C variants have been out there for a long time), modern languages usually don't support that. And strictly speaking, you're not using that programming language anymore. Syntax is defined by production rules (
like here for Lua), violating those makes your code syntactically invalid and a programming language is defined by its syntax (together with other stuff of course). Thus, compiling some code doesn't necessarily mean its in the subset of the language.
(It's odd how I like the argue about 5 words in each other sentences. :P/>)
2005 posts
Posted 31 January 2013 - 11:44 PM
"Because Objective-C is a strict superset of C, we are free to use C in an Objective-C file and it will compile fine." That is to say, Obj-C includes the complete syntax of C, therefore valid C code cannot be outside of (or breaking) Obj-C syntax.
A programming language's syntax is what you can use without breaking it, if you can use it without breaking it, then you are inside of the language's syntax, pretty much a matter of definition.
Which makes what Orwell stated that most rare of things, a tautology that is still worth saying.
1054 posts
Posted 31 January 2013 - 11:47 PM
a programming language can never breaks it syntax
Not true. For example I can type some C snippets when programming in Obj-C and it is fine, which obviously is breaking Obj-C syntax.
I think he meant "breaking the fourth wall", where for example you write some C code in a language that is implemented in C and it works
because it's implemented in C. Compiled languages can't do that, but interpreted languages can if they have an "eval" or "exec" type statement that takes a string and runs it as though it were a language statement. You can write C code ib Obj-C because Obj-C is a superset of C, not because it's written in C. Even if Obj-C were written in Pascal, you still couldn't use Pascal syntax in Obj-C and so the wall is not broken.
Oh, he's talking about a syntactically correct C program? Yeh, all C syntax is valid in Obj-C, because Obj-C is indeed a superset of C. :P/> You can ignore my wall of text in that case. :D/> (same goes for C++ of course)
Also, you're last sentence is exactly what I meant to say. :)/>
Edit: I reply too slow. Everyone passes on me. :P/>
Edit2: @ChungLing: I totally don't get your last sentence.. (And yes, I know what a tautology is :P/>)
2005 posts
Posted 01 February 2013 - 11:35 AM
Meh, just that most tautologies aren't worth stating, because they are obvious. But some are. When a statement is a tautology, but not so obvious as to be pointless, it's worth noting, generally because it is a definition, a statement about the relative meanings of terms that is essential to proper use of terminology (or language). Such statements form the essential core of intelligible communication.