{
  "id": 15982335,
  "title": "Embedding EYG in Erlang programs",
  "url": "https://urgent.news/2026/10/21/embedding-eyg-in-erlang-programs",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-21T21:27:36.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://eyg.run/guides/embedding-eyg-in-erlang-programs"
  },
  "original_language": "en",
  "account": "This guide provides instructions for incorporating EYG scripting capabilities into an Erlang application. EYG offers a scripting environment with strict controls on accessible resources. The guide includes the necessary steps to implement EYG in a simple Erlang module.\n\nTo begin, load the EYG module in an Erlang shell and execute your initial scripts. The guide outlines two enhancements to improve usability: pretty-printing errors and handling runtime values and errors as binaries. This allows for better presentation to users.\n\nIn the examples provided, EYG programs are executed within the Erlang shell, enabling the use of charlists alongside binaries in the run function. The current version of the EYG program is limited to configuration scripts due to the absence of side effects.\n\nTo handle errors, the guide explains that any error encountered while interpreting an EYG program results in a reason and the complete program state. Unhandled effects are a specific type of break that occurs when execution halts. The guide also introduces the concept of algebraic effects and their implementation.\n\nThe run function is updated to include a loop that continues running the program after each handled break. The loop function matches on the unhandled_effect and, if the extrinsic implementation succeeds, recurses to handle the next break. Effects can be implemented at various levels of abstraction, ranging from core utilities like logging to application-specific effects.\n\nBefore executing an EYG program, it is recommended to perform type checking to ensure the absence of runtime errors. The type inference system is sound, meaning that any program passing type checking will not encounter runtime errors. The guide explains that an effect context is passed to the type checking process, guaranteeing that the program is error-free, including attempts to call unavailable effects.\n\nTo enhance the EYG scripting environment, the guide suggests adding effect handlers and their corresponding types to the inference context. This allows for greater flexibility and control over the application's behavior. By following the steps outlined in the guide, developers can create an EYG scripting environment that checks programs before execution and leverages the full power of Erlang for implementing effects.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}