{"path":"/sutl/core-library/part-3","content":{"title":"sUTL core library, part 3","summary":"Named reusable transforms, with full declarations and explicit dependency lists.","body":"[sUTL](/sutl) · [Guide](/sutl/guide) · [Reference](/sutl/reference) · [Examples](/sutl/examples)\n\nThese are declarations from the core distribution. Compile their named requirements against the complete distribution; an isolated declaration may depend on others. Historical `language: \"sUTL0\"` labels are retained as archived input, accepted by the current language. See [declarations and libraries](/sutl/guide/declarations-and-libraries).\n\n## when_core_emlynoregan_com\n\n```json\n{\n  \"name\": \"when_core_emlynoregan_com\",\n  \"transform-t\": [\n    \"^%\",\n    {\n      \"&\": \"reduce\",\n      \"list\": \"^@.cases\",\n      \"accum\": {\n        \"found\": false,\n        \"result\": null\n      },\n      \"t\": {\n        \"'\": {\n          \"&\": \"if\",\n          \"cond\": {\n            \"'\": \"^@.accum.found\"\n          },\n          \"true\": {\n            \"'\": \"^@.accum\"\n          },\n          \"false\": {\n            \"'\": {\n              \"&\": \"if\",\n              \"cond\": {\n                \"'\": [\n                  \"&&&\",\n                  [\n                    \"&=\",\n                    {\n                      \"&\": \"type\",\n                      \"value\": \"^@.item\"\n                    },\n                    \"list\"\n                  ],\n                  [\n                    \"&=\",\n                    {\n                      \"&\": \"len\",\n                      \"list\": \"^@.item\"\n                    },\n                    2\n                  ]\n                ]\n              },\n              \"true\": {\n                \"'\": {\n                  \"&\": \"if\",\n                  \"cond\": {\n                    \"'\": {\n                      \"!\": {\n                        \"!\": \"^@.item.0\"\n                      }\n                    }\n                  },\n                  \"true\": {\n                    \"'\": {\n                      \"found\": true,\n                      \"result\": {\n                        \"!\": \"^@.item.1\"\n                      }\n                    }\n                  },\n                  \"false\": {\n                    \"'\": \"^@.accum\"\n                  }\n                }\n              },\n              \"false\": {\n                \"'\": {\n                  \"found\": true,\n                  \"result\": {\n                    \"!\": \"^@.item\"\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    },\n    \"result\"\n  ]\n}\n```\n\n## isdict_core_emlynoregan_com\n\n```json\n{\n  \"name\": \"isdict_core_emlynoregan_com\",\n  \"transform-t\": [\n    \"&=\",\n    {\n      \"&\": \"type\",\n      \"value\": \"^@.item\"\n    },\n    \"map\"\n  ]\n}\n```\n\n## islist_core_emlynoregan_com\n\n```json\n{\n  \"name\": \"islist_core_emlynoregan_com\",\n  \"transform-t\": [\n    \"&=\",\n    {\n      \"&\": \"type\",\n      \"value\": \"^@.item\"\n    },\n    \"list\"\n  ]\n}\n```\n\n## issimple_core_emlynoregan_com\n\nRequires: `isdict_core`, `islist_core`.\n\n```json\n{\n  \"name\": \"issimple_core_emlynoregan_com\",\n  \"transform-t\": [\n    \"&!\",\n    [\n      \"&||\",\n      {\n        \"&\": \"isdict_core\"\n      },\n      {\n        \"&\": \"islist_core\"\n      }\n    ]\n  ],\n  \"requires\": [\n    \"isdict_core\",\n    \"islist_core\"\n  ]\n}\n```\n\n## newdiff_core_emlynoregan_com\n\nRequires: `hasitems`, `isdict`, `islist`, `switch`, `map_core`, `isinlist`, `newdiff_core`.\n\n```json\n{\n  \"name\": \"newdiff_core_emlynoregan_com\",\n  \"transform-t\": {\n    \"!\": {\n      \":\": {\n        \"!\": {\n          \":\": {\n            \"&\": \"if\",\n            \"cond\": {\n              \":\": {\n                \"!\": \"^@.keepvalue\"\n              }\n            },\n            \"true\": {\n              \":\": \"^@.value\"\n            }\n          }\n        },\n        \"value\": {\n          \"&\": \"switch\",\n          \"value\": {\n            \"&\": \"type\",\n            \"value\": \"^@.new\"\n          },\n          \"cases\": [\n            [\n              \"map\",\n              {\n                \"&\": \"if\",\n                \"cond\": {\n                  \"'\": {\n                    \"&\": \"isdict\",\n                    \"item\": \"^@.old\"\n                  }\n                },\n                \"true\": {\n                  \"'\": {\n                    \"&\": \"makemap\",\n                    \"value\": {\n                      \"&\": \"map_core\",\n                      \"list\": {\n                        \"&\": \"keys\",\n                        \"map\": \"^@.new\"\n                      },\n                      \"t\": {\n                        \":\": {\n                          \"&\": \"if\",\n                          \"cond\": {\n                            \":\": {\n                              \"&\": \"isinlist\",\n                              \"list\": {\n                                \"&\": \"keys\",\n                                \"map\": \"^@.old\"\n                              }\n                            }\n                          },\n                          \"true\": {\n                            \"'\": {\n                              \"&\": \"if\",\n                              \"cond\": {\n                                \":\": [\n                                  \"&=\",\n                                  [\n                                    \"^%\",\n                                    \"^@.new\",\n                                    \"^@.item\"\n                                  ],\n                                  [\n                                    \"^%\",\n                                    \"^@.old\",\n                                    \"^@.item\"\n                                  ]\n                                ]\n                              },\n                              \"true\": null,\n                              \"false\": {\n                                \":\": {\n                                  \"!\": {\n                                    \":\": {\n                                      \"&\": \"if\",\n                                      \"cond\": {\n                                        \":\": {\n                                          \"!\": \"^@.keepvalue\"\n                                        }\n                                      },\n                                      \"true\": {\n                                        \":\": [\n                                          \"^@.item\",\n                                          \"^@.value\"\n                                        ]\n                                      }\n                                    }\n                                  },\n                                  \"value\": {\n                                    \"&\": \"newdiff_core\",\n                                    \"old\": [\n                                      \"^%\",\n                                      \"^@.old\",\n                                      \"^@.item\"\n                                    ],\n                                    \"new\": [\n                                      \"^%\",\n                                      \"^@.new\",\n                                      \"^@.item\"\n                                    ]\n                                  }\n                                }\n                              }\n                            }\n                          },\n                          \"false\": {\n                            \":\": [\n                              \"^@.item\",\n                              [\n                                \"^%\",\n                                \"^@.new\",\n                                \"^@.item\"\n                              ]\n                            ]\n                          }\n                        }\n                      }\n                    }\n                  }\n                },\n                \"false\": {\n                  \":\": \"^@.new\"\n                }\n              }\n            ],\n            [\n              \"list\",\n              {\n                \"!\": {\n                  \":\": {\n                    \"&\": \"if\",\n                    \"cond\": {\n                      \":\": {\n                        \"&\": \"hasitems\"\n                      }\n                    },\n                    \"true\": {\n                      \":\": \"^@.list\"\n                    },\n                    \"false\": []\n                  }\n                },\n                \"list\": {\n                  \"&\": \"if\",\n                  \"cond\": {\n                    \"'\": {\n                      \"&\": \"islist\",\n                      \"item\": \"^@.old\"\n                    }\n                  },\n                  \"true\": {\n                    \"'\": [\n                      \"^%\",\n                      {\n                        \"&\": \"reduce\",\n                        \"list\": \"^@.new\",\n                        \"accum\": {\n                          \"index\": 0,\n                          \"result\": []\n                        },\n                        \"t\": {\n                          \":\": {\n                            \"index\": [\n                              \"&+\",\n                              \"^@.accum.index\",\n                              1\n                            ],\n                            \"result\": [\n                              \"&&\",\n                              \"^@.accum.result\",\n                              [\n                                {\n                                  \"!\": {\n                                    \":\": {\n                                      \"&\": \"if\",\n                                      \"cond\": {\n                                        \":\": {\n                                          \"!\": \"^@.keepvalue\"\n                                        }\n                                      },\n                                      \"true\": {\n                                        \":\": \"^@.value\"\n                                      }\n                                    }\n                                  },\n                                  \"value\": {\n                                    \"&\": \"newdiff_core\",\n                                    \"old\": [\n                                      \"^%\",\n                                      \"^@.old\",\n                                      \"^@.accum.index\"\n                                    ],\n                                    \"new\": \"^@.item\"\n                                  }\n                                }\n                              ]\n                            ]\n                          }\n                        }\n                      },\n                      \"result\"\n                    ]\n                  },\n                  \"false\": {\n                    \":\": \"^@.new\"\n                  }\n                }\n              }\n            ],\n            {\n              \"&\": \"if\",\n              \"cond\": {\n                \":\": [\n                  \"&=\",\n                  \"^@.new\",\n                  \"^@.old\"\n                ]\n              },\n              \"false\": {\n                \":\": \"^@.new\"\n              }\n            }\n          ]\n        }\n      }\n    },\n    \"keepvalue\": {\n      \":\": [\n        \"&||\",\n        \"^@.value\",\n        [\n          \"&!\",\n          {\n            \"&\": \"isinlist\",\n            \"item\": {\n              \"&\": \"type\"\n            },\n            \"list\": [\n              \"null\",\n              \"map\",\n              \"list\"\n            ]\n          }\n        ]\n      ]\n    }\n  },\n  \"requires\": [\n    \"hasitems\",\n    \"isdict\",\n    \"islist\",\n    \"switch\",\n    \"map_core\",\n    \"isinlist\",\n    \"newdiff_core\"\n  ]\n}\n```\n\n\n[Core library contents](/sutl/core-library)\n\n## Source\n\nAdapted from [the sUTL source material](https://github.com/emlynoregan/sutl-language/blob/0c3463677495ea00767f8266ae900eb4e2f98617/core-library.json).\n\n[Back to sUTL](/sutl) · [Software & Agents](/topics/software-and-agents) · [All topics](/guide)","author":"Emlyn O'Regan"}}