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

Assignable Methods

thbwd opened this issue · comments

commented

⭐️ Proposed change

So I already wrote documentation for this once, but it never came into existence.

You can also define instance methods to which values can be assigned.

Consider that to get a value from a list the 🐽 method is used as in this
example:

🐽 a_list 1❗️

It would be very intuitive, if we could — to assign a value — write this:

🔤Coco🔤 ➡️ 🐽 a_list 1❗️

And, indeed, we can. This works, because Emojicode allows us to define methods
that can be assigned to. Although this might sound complicated to you, in fact,
it isn’t. Take a look at this example, in which an assignee method is defined.

❗️ 🐽 index 🔢 ➡️ 🍬Element 🍇
  💭 ...
🍉

➡️ 🐽 assigned_value Element index 🔢 🍇
  💭 ...
🍉

In this example two methods are defined. The first one is rather obviously just
the getter we used before. The second method, on the other hand, uses the
assignment operator (➡️) instead of ❗️. This indicates to the compiler that this
method should be called, when an assignment to a method of the name 🐽 occurs.

The first argument of the assignee method is always the value that is being
assigned. It must not be provided on the right hand side of the assignment, as
we have seen in the assignment example before. The method itself than is free
to do whatever it needs to do with one limitation: It may not return a value.

🤔 Rationale

Because

🔤Coco🔤 ➡️ 🐽 a_list 1❗️

is cooler and more intuitive than

🐷 a_list 1 🔤Coco🔤❗️

With 🧠 even more so:

🐽 data🐚Element🍆 index✖️⚖️Element❗️
🐷 data🐚Element🍆 value index✖️⚖️Element❗️

vs

🐽 data🐚Element🍆 index✖️⚖️Element❗️
value ➡️ 🐽 data🐚Element🍆 index✖️⚖️Element❗️

This can also be used for getters and setters:

🐇 👩‍💼 🍇
  🖍🆕 firstname 🔡
  🖍🆕 lastname 🔡
  🖍🆕 creditcard 💳

  ❗️💳 ➡️💳🍇
      ↩️ creditcard
   🍉

  ➡️💳 value💳🍇
      value ➡️🖍creditcard
   🍉
🍉
💳susan❗️ ➡️ card
newCard ➡️💳susan❗️

🕺Example

Provided above.