In imperative programming, the Domain-Driven Design methodology helps in coping with the complexity of software development by materializing in code the invariants of a domain of interest. Code is cleaner and more secure because any implicit assumption is removed in favor of invariants, thus enabling a fail fast mindset and the immediate reporting of unexpected conditions. This article introduces a notion of template for Answer Set Programming that, in addition to the don't repeat yourself principle, enforces locality of some predicates by means of a simple naming convention. Local predicates are mapped to the usual global namespace adopted by mainstream engines, using universally unique identifiers to avoid name clashes. This way, local predicates can be used to enforce invariants on the expected outcome of a template in a possibly empty context of application, independently by other rules that can be added to such a context. Template applications transpiled this way can be processed by mainstream engines and safely shared with other knowledge designers, even when they have zero knowledge of templates.
翻译:在命令式编程中,领域驱动设计方法论通过将感兴趣领域的恒常性具体化到代码中,帮助应对软件开发的复杂性。代码更简洁、更安全,因为去除了所有隐性假设而代之以恒常性,从而实现了快速失败思维模式,并能够即时报告意外状况。本文为答案集编程引入了一种模板概念,它除了遵循"不重复自己"原则外,还通过简单的命名约定强制某些谓词的局部性。局部谓词被映射到主流引擎采用的常规全局命名空间,使用通用唯一标识符避免名称冲突。通过这种方式,局部谓词可用于在可能为空的应用上下文中强制模板预期结果的恒常性,且独立于可能添加到该上下文的其他规则。以这种方式转译的模板应用可由主流引擎处理,并可安全地与其他知识设计者共享,即使他们对模板一无所知。