有没有办法将复合术语作为参数从 swi-prolog 中的表单传递

Is there a way to pass a compound term as a parameter from a form in swi-prolog

我正在使用 swi-prolog 7.3.31。

我有一个复合词question,其形式为:

question(q_(Question),y_(Yes),n_(No))

其中 YesNo 可以是 atom 或其他复合词 question 等等。

我正在使用带有 reply_html_page 的表单,其中我显示问题的文本 Question 并且我有两个提交按钮,一个用于 'yes',一个用于 'no'.

这是 'yes' 按钮的表单示例:

form([class = 'form-inline ',
      action = '/choice_handler',
      method = 'POST'], [
      input([name = choice,
             id = choice,
             type = hidden,
             class = 'form-control',
             value = 'yes']),
      input([name = question,
             type = hidden,
             value = Yes ]),
      button([class = 'btn btn-default yes',
              type = submit], ['yes']) ])

这是我的问题,我想传递 Yes 的值以递归显示新问题或最终结果,但是我没有这样做,因为 value输入形式必须是原子而不是化合物。

因此问题来了:有没有办法将复合词传递给 handler

请注意,在交换数据时,一个原子通常足够,因为您可以使用atom_to_term/3将一个原子转换为复合词:

atom_to_term(+Atom, -Term, -Bindings)

Use Atom as input to read_term/2 using the option variable_names and return the read term in Term and the variable bindings in Bindings. Bindings is a list of Name = Var couples, thus providing access to the actual variable names. See also read_term/2. If Atom has no valid syntax, a syntax_error exception is raised. New code should use read_term_from_atom/3.

示例:

?- atom_to_term('the(f(X,Y),Z)', Term, Bindings).
Term = the(f(_1596, _1598), _1604),
Bindings = ['X'=_1596, 'Y'=_1598, 'Z'=_1604].

因此,在适当的一般假设下,您可以简单地取原子并恢复复合项。