F.E.L.T.

Functionally Equivalent Language Translation

MCALL / ->

(defvar foo (new Foo))
(mcall foo (set :age 42))                 ; set a property on fictitious instance
(mcall foo (set :id 100) (load-from-db))  ; chain two calls
(-> foo (get :age))                       ; get the age property
(-> foo :field-name (exec))               ; call exec() on sub-field field-name

This is how FELT lets you call methods on a class instance. The target of the sends (the 'receiver') is the first expression after the instruction, be in the MCALL or the short-form ->, and the remainder of the expressions within the instruction are interpreted as function calls or field-names to be de-referenced. See the fulldocumentation.


Method Calling

This instruction, MCALL, is probably the second most frequently used instruction when operating within the 'object oriented' paradigm, especially for imperative style back-end languages. FELT allows you to either use MCALL or a more convenient short-form, ->, which is identical in appearance to that used in PHP and also some other languages when de-referencing from a pointer to something.

Probably the easiest way to show you how to use this is just to give lots of examples and leave it at that.

Simple call, one method

(defvar rcvr (new ReceiverObjectClass))
(defvar age (mcall rcvr (get :age)))
(defvar id  (-> rcvr (get :id)))

Generated PHP:

$rcvr = new ReceiverObjectClass();
$age = $rcvr->get('age');
$id = $rcvr->get('id');

Generated JavaScript:

var rcvr = new ReceiverObjectClass();
var age = rcvr.get('age');
var id = rcvr.get('id');

BUG! When expanding AREF termsn, if it is :KEYOWRD then asString() as we need to be able to use a literal as well!]

Complex calls, field access, chaining

(defvar rcvr (new ReceiverObjectClass))
(defvar age "age")
(defvar id  "id_fn")
(defvar slot "slot_accessor_fn")
(defvar extracted-age (mcall rcvr age))
(defvar extracted-id  (-> rcvr id))
(defvar x (-> rcvr slot (read-thing 10)))
(defvar y (-> rcvr slot (write-thing 10) (verify-thing 10)))

Generated PHP:

$rcvr = new ReceiverObjectClass();
$age = "age";
$id = "id_fn";
$slot = "slot_accessor_fn";
$extracted_age = $rcvr->$age;
$extracted_id = $rcvr->$id;
$x = $rcvr->$slot->read_thing(10);
$y = $rcvr->$slot->write_thing(10)->verify_thing(10);

Generated JavaScript:

var rcvr = new ReceiverObjectClass();
var age = "age";
var id = "id_fn";
var slot = "slot_accessor_fn";
var extracted_age = rcvr.age;
var extracted_id = rcvr.id;
var x = rcvr.slot.read_thing(10);
var y = rcvr.slot.write_thing(10).verify_thing(10);