{"path":"/sutl/examples/avgrefactor1","content":{"title":"Average with an explicit scope","summary":"A worked sUTL example with source data, transform, expected output and runnable-original links.","body":"[sUTL](/sutl) · [Guide](/sutl/guide) · [Reference](/sutl/reference) · [Examples](/sutl/examples)\n\nThis worked example preserves its recovered source, transform and expected result. It is a static, inspectable example in Everything.\n\n## Source\n\n```json\n{\n  \"input\": [\n    1,\n    2,\n    3,\n    4\n  ],\n  \"avgt\": {\n    \"!\": [\n      \"&&\",\n      {\n        \":\": \"&/\"\n      },\n      {\n        \"!\": [\n          \"&&\",\n          {\n            \":\": \"&+\"\n          },\n          \"^$.input\"\n        ]\n      },\n      {\n        \"&\": \"len\",\n        \"list\": \"^$.input\"\n      }\n    ]\n  }\n}\n```\n\n## Transform\n\n```json\n{\n  \"avgtransform\": \"^@.avgt\",\n  \"avg\": {\n    \"!\": \"^@.avgt\"\n  }\n}\n```\n\n## Expected result\n\n```json\n{\n  \"avgtransform\": {\n    \"!\": [\n      \"&&\",\n      {\n        \":\": \"&/\"\n      },\n      {\n        \"!\": [\n          \"&&\",\n          {\n            \":\": \"&+\"\n          },\n          \"^$.input\"\n        ]\n      },\n      {\n        \"&\": \"len\",\n        \"list\": \"^$.input\"\n      }\n    ]\n  },\n  \"avg\": 2.5\n}\n```\n\n## Run it\n\nUse the [language site example](https://sutl-bronzearch.house-of-ur.com/examples/avgrefactor1-sutllang-emlynoregan-com--dd5bdd26-bc4b-fe8a-8c02-2b89177cdf2e/) or copy it into the [playground](https://sutl-bronzearch.house-of-ur.com/playground/). If the transform calls `map_core` or another library name, load the [core distribution](/sutl/core-library) and compile its requirements; the full fixture retains that library context.\n\n[Full original fixture](https://github.com/emlynoregan/sutl-language/blob/0c3463677495ea00767f8266ae900eb4e2f98617/fixtures/studio/dd5bdd26-bc4b-fe8a-8c02-2b89177cdf2e.json) · [Curated source record](https://github.com/emlynoregan/sutllang-site/blob/e59ecafd364848cd71a1d18ce74cdf67f2f69328/content/examples/curated/avgrefactor1-sutllang-emlynoregan-com--dd5bdd26-bc4b-fe8a-8c02-2b89177cdf2e.json)\n\n## Related reading\n\n[Paths](/sutl/guide/paths) · [Quoting and evaluation](/sutl/guide/quoting-and-evaluation) · [Libraries](/sutl/guide/declarations-and-libraries)\n\n## Source\n\nAdapted from [the sUTL source material](https://github.com/emlynoregan/sutllang-site/blob/e59ecafd364848cd71a1d18ce74cdf67f2f69328/content/examples/curated/avgrefactor1-sutllang-emlynoregan-com--dd5bdd26-bc4b-fe8a-8c02-2b89177cdf2e.json).\n\n[Back to sUTL](/sutl) · [Software & Agents](/topics/software-and-agents) · [All topics](/guide)","author":"Emlyn O'Regan"}}