Z31756

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z31756"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z31754",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z610",
            "Z16K2": "def Z31754(Z31754K1, Z31754K2):\n\t\"\"\"\nConstruct a function call object (Z7) wrapped in a quote (Z99).\nArguments in Z31754K2 must be convertible into Wikifunctions objects (default conversion)\nWhere the function specifies a concrete argument type (rather than Z1), each argument must be nominally compatible with that type.\n\t\"\"\"\n#Currently, incompatible or missing arguments are substituted with Z1/object, so the result may be an invalid function call (quoted). In future, these should become structured errors instead.\n\n\tdef convertible (arg):\n\t\tif isinstance(arg, (str, bool, type(None), list, dict, ZObject, ZPair)):\n\t\t\treturn True\n\t\telse:\n\t\t\treturn False #for now\n\t\t\t#ZReference is a valid return but not a valid argument\n\tdef Z4_str(Z1):\n\t\t#reference\n\t\tdef Z9K1(Z1K1):\n\t\t\tif hasattr(Z1K1, \"Z9K1\"):\n\t\t\t\treturn Z1K1.Z9K1\n\t\t\tif isinstance(Z1K1, dict):\n\t\t\t\treturn Z1K1.get('Z9K1')\n\t\t\treturn None\n\t\tZ9K1_str = Z9K1(Z1)\n\t\tif Z9K1_str is not None:\n\t\t\treturn Z9K1_str\n\t\t# function call\n\t\tif hasattr(Z1, \"Z7K1\"):\n\t\t\tZ8 = Z1.Z7K1.Z9K1\n\t\t\targs = []\n\t\t\tif hasattr(Z1, \"_keys\"):\n\t\t\t\tfor k in Z1._keys:\n\t\t\t\t\tif k == \"Z7K1\":\n\t\t\t\t\t\tcontinue  # skip the function reference\n\t\t\t\t\tval = getattr(Z1, k)\n\t\t\t\t\targs.append(Z4_str(val))\n\t\t\treturn f\"{Z8} ({', '.join(args)})\"\n\t\t# type\n\t\tif hasattr(Z1, \"Z4K1\"):\n\t\t\treturn Z4_str(Z1.Z4K1)\n\t\t# unrecognised type\n\t\treturn None\n\tdef infer_list_type(Z881):\n\t\tif not isinstance(Z881, list):\n\t\t\treturn None\n\t\tPy_types = set(type(el) for el in Z881)\n\t\tif len(Py_types) \u003E 1:\n\t\t\treturn \"Z881 (Z1)\"\n\t\tel_Py_type = Py_types.pop()\n\t\tel_Z4 = Z4from_Py_type.get(el_Py_type)\n\t\tif el_Z4 is None:\n\t\t\tfirst = Z881[0]\n\t\t\tel_Z4 = Z4_str(first.Z1K1) if hasattr(first, \"Z1K1\") else None\n\t\t\tif el_Z4 is not None:\n\t\t\t\tfor el in Z881[1:]:\n\t\t\t\t\tif not hasattr(el, \"Z1K1\") or Z4_str(el.Z1K1) != el_Z4:\n\t\t\t\t\t\treturn \"Z881 (Z1)\"\n\t\treturn f\"Z881 ({el_Z4})\" if el_Z4 else \"Z881 (Z1)\"\n\tdef compatible(Z17, arg):\n\t\tif hasattr(Z17, \"Z17K1\"):\n\t\t\targ_Z4 = None\n\t\t\tZ17_Z4 = Z4_str(Z17.Z17K1)\n\t\t\tif Z17_Z4 == \"Z1\":\n\t\t\t\treturn True\n\t\t\telse:\n\t\t\t\tif isinstance(arg, list):\n\t\t\t\t\tif len(arg) == 0:\n\t\t\t\t\t\treturn Z17_Z4.startswith(\"Z881\")\n\t\t\t\t\telif Z17_Z4 == \"Z881 (Z1)\":\n\t\t\t\t\t\treturn True\n\t\t\t\t\targ_Z4 = infer_list_type(arg)\n\t\t\t\telif hasattr(arg, \"Z1K1\"):\n\t\t\t\t\targ_Z4 = Z4_str(arg.Z1K1)\n\t\t\t\telse:\n\t\t\t\t\targ_Z4 = Z4from_Py_type.get(type(arg))\n\t\t\treturn arg_Z4 == Z17_Z4\n\t\treturn True #for now\n\tZ4from_Py_type = {\n\t\tstr: \"Z6\",\n\t\ttype(None): \"Z21\",\n\t\tbool: \"Z40\",\n\t\tlist: \"Z881 (Z1)\"\n\t}\n\t\n\tZ8 = Z31754K1\n\targs = Z31754K2\n\t\n\tif not hasattr(Z8, \"Z8K1\"):\n\t# invalid function object\n\t\treturn Wikifunctions.Error(\"Z516\", [\"Z31754K1\", repr(Z8)])\n\t\n\tZ17_dict = {} #for errors\n\tZ7_args = {\"Z7K1\": Z8.Z8K5}\n\tfor i, Z17 in enumerate (Z8.Z8K1):\n\t\targ = args[i] if i \u003C len(args) else None\n\t\t#inject missing args\n\t\tif not convertible(arg):\n\t\t\targ = str(arg) #for now (None is convertible)\n\t\tkey = 'K' + str(i+1)\n\t\t#default local key\n\t\tif hasattr(Z17, \"Z17K2\"):\n\t\t\tif isinstance(Z17.Z17K2, str):\n\t\t\t\tkey = Z17.Z17K2\n\t\t#specified global key (assumes no duplicate keys)\n\t\tZ17_dict[key] = (Z17, arg)\n\t\t\t\n\t\tif compatible(Z17, arg):\n\t\t\tZ7_args[key] = arg\n\t\telse:\n\t\t\tZ7_args[key] = ZReference(\"Z1\")\n\n\tZ99 = ZObject(\n\t\t{\n\t\t\t\"Z1K1\": \"Z9\",\n\t\t\t\"Z9K1\": \"Z7\"\n\t\t},\n\t\t**Z7_args\n\t)\n\t# Any Z1-reference is structurally valid but is an unambiguous signal that the supplied argument was invalid or omitted\n\t#Z99 = Z31754K2[1].Z1K1['Z9K1']\n\t# Consider returning a quoted error together with the constructed call if any argument is a Z1\n\treturn ZObject(\n\t\t{\n\t\t\t\"Z1K1\": \"Z9\",\n\t\t\t\"Z9K1\": \"Z99\"\n\t\t},\n\t\tZ99K1 = Z99\n\t)"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "validated function call as quote, Python"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "#error handling deferred"
            }
        ]
    }
}