emojicode / emojicode

πŸ˜€πŸ˜œπŸ”‚ World’s only programming language that’s bursting with emojis

Home Page:https://emojicode.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unary negation operator

betseg opened this issue Β· comments

✏️ Proposed change

Adding a new operator for negating an expression. I'm thinking of πŸ”ƒ, because positive values are above the negative ones, and this emoji is vertical.

πŸ€” Rationale

It's useful 🀷

πŸ•ΊExample

🍦 a 3
🍦 b πŸ”ƒa
β†ͺ️ πŸ˜› b -3

or

🍦 a 3
🍦 b πŸ”ƒa
β†ͺ️ πŸ˜› b πŸ”ƒ3
commented

I think βž– is more intuitive. In 0.6 binary operators are infix anyway, so this should work just fine:

3 ➑️ a
βž–a ➑️ b
β†ͺ️ b πŸ™Œ -3 πŸ‡ πŸ’­...

yeh forgot that, nice.

also, βž–3 πŸ™Œ -3?

commented

βž–3 πŸ™Œ -3 Yep.

commented

βž– is actually not possible – I realised when I first tried to implement this – because it is ambiguous. For instance:

🀭 10 βž–4❗️

Is this a method call on 10 with one argument or on 6 with no arguments?

We need to reconsider alternatives. The original πŸ”ƒ might not be optimal as it is very similar to πŸ”, which is a flow control statement but not an operator.

Why do you need a new operator in the first place? Why don't the minus sign work?
In every other languages I know of, you use the minus sign for this.

In Java, these two lines gives the same result:
a = 0 - b;
a = -b;

commented

As I stated before, it’s ambiguous. Technically it is possible, of course, but it probably isn't what you'd expect.

The lines you showed work in Emojicode just as well, but Java has a completely different call syntax than Java, that does not allow the ambiguity seen above:

10.beQuiet(-4)
// or
(10 -4).beQuiet(4)

πŸ”‹ because batteries have a positive and a negative side? Or 🧲 because magnets have a north and a south poles?

commented

@betseg Valid options, but I don’t think these are very clear for something as simple as this.

Giving this a second thought, we could solve the above problem with πŸ€œπŸ€› in cases like this:

🀭 10 πŸ€œβž–4πŸ€›β—οΈ

But maybe this is overly verbose.

commented

Since πŸ€œβž–4πŸ€› would still require a substantial amount of the changes to the grammar, I’ll go with @betseg’s suggestion of πŸ”‹. The + and - on the battery do make some sense and it’s important we finally resolve this.