我在理解Prolog中的列表递归和修改时遇到了一些问题。我尝试获取一个列表列表,然后对每个列表,将列表中的每个元素乘以最后一个元素。
下面是我的代码片段:
/*Find the last element of a list*/
lastelement(X,[X]).
lastelement(X,[_|L]) :- lastelement(X,L).
/*Multiply two lists together*/
multiplication(M1,M2,M1*M2).
/*Take a list, find the last element
我正在研究如何使用FreeMarker编写电子数据交换文件。这些基本上是大量格式化(和验证)的电子发票。我决定从写一个简单的例子开始,然后把它放到一个“嵌套pojo”模板中。这里我指的是包含POJO的POJO,其中这两个POJO都包含我想要在输出中使用的数据。我写了一个单元测试(自包含的),由于未知的原因而失败了。当我运行测试时,我得到了以下异常:
Expression user.getSub is undefined on line 1, column 24 in simple.
The problematic instruction:
----------
==> ${user.ge
我使用Freemarker 2.3.23,并希望打印XML的字符串表示形式。所以,我找到了指令。但是当我尝试使用它时,我有以下ParseException:
Unknown directive: #outputformat. Help (latest version): http://freemarker.org/docs/ref_directive_alphaidx.html; you're using FreeMarker 2.3.23.
at freemarker.core.TokenMgrError.toParseException(TokenMgrError.java:247
可以调用一个从Freemarker模板获取参数的方法吗?
我有一个对象模型,我正试着用Freemarker把它渲染成一个网页。其中一个对象有一个方法来获取其内容的子列表-接受一个用于过滤列表的参数:
public List getunits(final String type);
我知道在JSP中您不能直接做到这一点,但是您可以编写自定义函数来实现您想要的结果。你如何在Freemarker中解决这个问题?这和编写自定义函数一样吗?或者,是否有某种方法可以实际调用这种函数?
我有一个java.lang.Iterable (实际上是一个com.google.gson.JsonArray实例)。
我想使用freemarker (2.3.16)枚举列表中的项目。
[#assign sports = controller.sports]
[#-- At this point, sports is bound to a com.google.gson.JsonArray instance. --]
[#list sports as sport]
${sport_index}
[/#list]
我希望避免编写定制的bean和Gson反序列化程序来获得一个显式的项集合。使
我在计算嵌套列表中的列表数量时遇到了问题。
count_lists([H|T],R):-
atomic(H),!,
count_lists(T,NR),
R is NR+1.
count_lists([[H|T]|Rest],R):-
!,
count_lists([H|T],R1),
count_lists(Rest,R2),
R is R1+R2.
count_lists([],0).
首先,我尝试基本的情况,列表中的元素是原子的,因此,我应该将计数器递增1。(另外,我尝试删除原子谓词,因为我认为由于它,我的代码将计算嵌套列表中的元素数量,但它仍然
我试图弄清楚如何使用FreeMarker生成如下所示的文件:
The contents of /home/myuser/somedir are:
blah.txt
fizz.gif
buzz.jpg
widget.log
...from如下所示的模板:
The contents of <%dir%> are:
<%contents%>
我阅读了关于FreeMarker的非常优秀的Vogella教程,但不太确定如何将它们放在一起:一旦我查询目录中的内容,如何将每一项添加到这个<%contents%>列表中?提前感谢!
我以前没有使用Freemarker,并且继承了一些不会编译的模板。我已把造成下列问题的范围收窄:
${text('Text and {0}', 'More Text')}
这个text()函数从何而来?据我所知,它试图返回第二个字符串注入第一个类似:“文本和更多的文本”。
以下是错误:
FreeMarker template error:
For "...(...)" callee: Expected a method, but this has evaluated to an extended_hash (wrapper: f.t.Simple