本文介绍了在逻辑编程中,无用的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理性计划者"描述了如何使用miniKanren,它类似于Prolog,但是是类似Lisp的语言的库.这本书的第一条诫命"是这样的:

The Reasoned Schemer describes how to use miniKanren, which resembles Prolog but is a library for Lisp-like languages. The book's "First Commandment" is this:

除非通过几个大致等效的示例,否则它们实际上并没有定义嵌套.最清楚的是:取消嵌套会将您从(list? (cdr l))转到

They don't really define unnesting, except through a few roughly equivalent example. The clearest is this: unnesting takes you from (list? (cdr l)) to

(fresh (d)
       (cdro l d)
       (listo d))

我不明白为什么需要嵌套.例如,对于上述目标,为什么tp write (listo (cdr l))还不够?

I don't understand why unnesting is needed. For instance, for the above goal, why is it not sufficient tp write (listo (cdr l))?

此处所述,我运行了然后定义了一些缺失的部分.

As described here, I ran raco pkg install minikanren and then defined a few missing pieces.

以下是listo的定义及其使用的所有内容,除了minikanren库或Racket的前奏中定义的内容.

Here are the definitions of listo and everything it uses it, except for things defined in the minikanren library or in Racket's prelude.

(define listo
  (lambda (l)
    (conde
     ((nullo l) #s)
     ((pairo l)
      (fresh (d)
             (cdro l d)
             (listo d)))
     (else #u))))

(define nullo
  (lambda (x)
    (== x '())))

(define pairo
  (lambda (p)
    (fresh (a d)
           (conso a d p))))

(define cdro
  (lambda (p d)
    (fresh (a)
           (== (cons a d) p))))

(define conso
  (lambda (head tail result)
    (== (cons head tail) result)))

推荐答案

术语un-nesting表示修改结构的层次结构或删除方括号.

the term un-nesting means to modify the hierarchy of the structure - or to remove brackets.

刚发现这本书 The Reasoned Schemer 和相关的GitHub 页面,该页面也对此进行了定义:

just found the book The Reasoned Schemer and the associated GitHub page, which also defines it:

这篇关于在逻辑编程中,无用的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:50