Jump to content

Abstract Wikipedia/Builtin call

From Meta, a Wikimedia project coordination wiki

The following is assuming the pre-generic model.

Let the definition of Z802/if be as follows (that is stored on wiki):

{
 "type": "Function",
 "arguments": [
  {
   "type": "Argument declaration",
   "argument type": "Boolean",
   "key id": "Z802K1",
   "label": {
    "type": "Multilingual text",
    "texts": [
     {
      "type": "Monolingual text",
      "language": "English",
      "text": "condition"
     }
    ]
   }
  },
  {
   "type": "Argument declaration",
   "argument type": "Object",
   "key id": "Z802K2",
   "label": {
    "type": "Multilingual text",
    "texts": [
     {
      "type": "Monolingual text",
      "language": "English",
      "text": "consequent"
     }
    ]
   }
  },
  {
   "type": "Argument declaration",
   "argument type": "Object",
   "key id": "Z802K3",
   "label": {
    "type": "Multilingual text",
    "texts": [
     {
      "type": "Monolingual text",
      "language": "English",
      "text": "alternative"
     }
    ]
   }
  }
 ],
 "return type": "Object",
 "testers": [],
 "implementation": [
  "if builtin"
 ],
 "identity": "if"
}
{
 "Z1K1": "Z8",
 "Z8K1": [
  {
   "Z1K1": "Z17",
   "Z17K1": "Z40",
   "Z17K2": "Z802K1",
   "Z17K3": {
    "Z1K1": "Z12",
    "Z12K1": [
     {
      "Z1K1": "Z11",
      "Z11K1": "en",
      "Z11K2": "condition"
     }
    ]
   }
  },
  {
   "Z1K1": "Z17",
   "Z17K1": "Z1",
   "Z17K2": "Z802K2",
   "Z17K3": {
    "Z1K1": "Z12",
    "Z12K1": [
     {
      "Z1K1": "Z11",
      "Z11K1": "en",
      "Z11K2": "consequent"
     }
    ]
   }
  },
  {
   "Z1K1": "Z17",
   "Z17K1": "Z1",
   "Z17K2": "Z802K3",
   "Z17K3": {
    "Z1K1": "Z12",
    "Z12K1": [
     {
      "Z1K1": "Z11",
      "Z11K1": "en",
      "Z11K2": "alternative"
     }
    ]
   }
  }
 ],
 "Z8K2": "Z1",
 "Z8K3": [],
 "Z8K4": [
  "Z902"
 ],
 "Z8K5": "Z802"
}

In reality, there will hopefully be testers there, and maybe even more than just a single implementation.

The original implementation, Z902/if builtin, though will look like follows (a bit disappointing, also stored in wiki):

{
 "type": "Implementation",
 "function": "if",
 "built in": "Z902"
}
{
 "Z1K1": "Z14",
 "Z14K1": "Z802",
 "Z14K4": "Z902"
}

Now let's have the following function call:

{
 "type": "Function call",
 "function": "if",
 "condition": "true",
 "consequent": "this",
 "alternative": "that"
}
{
 "Z1K1": "Z7",
 "Z7K1": "Z802",
 "Z802K1": "Z41",
 "Z802K2": "this",
 "Z802K3": "that"
}

When the orchestrator receives this function call, here are the steps it should do (this is incomplete - it probably should also do things such as normalisation and validation, but let's keep our eyes on the evaluation path for now):

  1. look up the definition of the function Z802/if being called and get the list of implementations (Z8K4)
  2. choose the implementation to run (in this case there is only one implementation, Z902/if builtin, so we choose that one)
  3. check whether the types of the arguments given in the function call match the declared types of the given arguments. So for each argument:
    1. if the declared type is Z1/Object, everything matches and the argument is handed over as is
    2. if the declared type and the given type are not the same, but the given type is Z7/Function call or Z9/Reference, evaluate that Z7/Function call or fetch that Z9/Reference. Repeat that until a fix point is reached.
    3. if the type of the result and the declared type still don't match, throw a type error. If they match, hand the argument over.
  4. Find the built in function identified as Z902, and run it with the arguments.
  5. Return the result.

The result of the above function call should be (fully normalized):

{
 "type": {
  "type": "Reference",
  "reference ID": "String"
 },
 "value": "this"
}
{
 "Z1K1": {
  "Z1K1": "Z9",
  "Z9K1": "Z6"
 },
 "Z6K1": "this"
}

Or, in canonical form, simply:

"this"
"this"