小编Sho*_*hon的帖子

为什么在SWI-Prolog版本6.4.1中,current_functor/2对于0-arity谓词是假的?

我在OS X 7上使用SWI-Prolog版本6.4.1,并且遇到谓词的以下意外行为current_functor/2:

鉴于事实

p(a).
q.
Run Code Online (Sandbox Code Playgroud)

我得到了这些查询的答案:

?- current_functor(p, Y).
Y = 1 

?- current_functor(q, Y).
false.

?- current_functor(q, 0).
true.
Run Code Online (Sandbox Code Playgroud)

第二个和第三个查询不仅看起来公然不一致,而且第二个查询的失败似乎与SWI-Prolog参考手册不一致,后者描述current_functor/2如下:

current_functor(?Name,?Arity)连续使用名称和Arity统一Name,并使用系统已知的仿函数.

任何人都可以帮助我理解为什么谓词以这种方式运作?

编辑:

在解决我测试谓词是否已被定义的特定问题方面,包括某些0-arity,我最终遵循了错误的建议并编写了以下内容:

current_pred(P) :-
    current_predicate(P/_).
Run Code Online (Sandbox Code Playgroud)

prolog swi-prolog

5
推荐指数
1
解决办法
245
查看次数

使用CM.make的SML/NJ:"错误:非法字符"

我正在尝试使用标准ML的 Shipman的Unix系统编程编译以下程序:

structure Main=
struct

    fun main(arg0, argv) =
    (
        case argv of
          [] => ()
        | (first::rest) =>
        (
            print first;
            app (fn arg => (print " "; print arg)) rest;
            print "\n"
        );

        OS.Process.success
    )

    val _ = SMLofNJ.exportFn("echo", main)
end
Run Code Online (Sandbox Code Playgroud)

我的.cm文件看起来像:

group is
    $/basis.cm
    echo.sml
Run Code Online (Sandbox Code Playgroud)

当我运行时,CM.make "echo.sml";我收到以下错误消息:

gotchops@gotchops-vm:~/Documents/USPwSML/Ch2/echo$ CM_ROOT=echo.cm sml
Standard ML of New Jersey v110.80 [built: Fri Sep 16 22:36:30 2016]
- CM.make "echo.sml";
[autoloading]
[library $smlnj/cm/cm.cm is stable]
[library $smlnj/internal/cm-sig-lib.cm …
Run Code Online (Sandbox Code Playgroud)

sml smlnj cm

5
推荐指数
1
解决办法
204
查看次数

AspectJ @Before 注解问题

我在 AspectJ 实现方面遇到一些问题!
我想为带有 @MyAnnotation 注释的方法创建一个日志方法。

MyAnnotation.java:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation{ }
Run Code Online (Sandbox Code Playgroud)

MyAspect.java:

@Aspect
public class MyAspect {
    private static Logger logger = Logger.getLogger(MyAspect.class.getName());

    @Pointcut("@annotation(com.utils.aop.annotations.MyAnnotation)")
    public void logMyAspect() {
    }
    @Before("logMyAspect()")
    public void logMethod(JoinPoint jp) {
        String methodName = jp.getSignature().getName();
        logger.info("Executing method: " + methodName);
    }
}
Run Code Online (Sandbox Code Playgroud)

我在项目的一些服务方法之前使用我的@MyAnnotation:

    @RolesAllowed({ "DEV", "GUI", "API" })
    @POST
    @Path("/getList")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @MyAnnotation
    public Response getList(@Context final ContainerRequestContext requestContext,  
            FilterAndSortObject filterAndSortObject, 
            @QueryParam("offset") final int offset,
            @QueryParam("limit") final int limit)
    {
             ...
    } …
Run Code Online (Sandbox Code Playgroud)

java spring aspectj spring-aop

5
推荐指数
1
解决办法
7486
查看次数

SWI-Prolog:使用消息队列进行线程安全的数据库读/写与`library(persistency)`

SWI-Prolog 宣称自己是LAMP堆栈的单一语言替代品.在更换M(ySQL)时,文档列举了几种方法,其中library(persistency)似乎是最简单的方法,能够提供持久的,可更新的数据库.

该文档library(persistency)提供了以下示例,该示例演示了如何在从数据库读取和更新数据时使用互斥锁来避免无效状态:

:- module(user_db,
          [ attach_user_db/1,       % +File
            current_user_role/2,    % ?User, ?Role
            add_user/2,         % +User, +Role
            set_user_role/2     % +User, +Role
          ]).
:- use_module(library(persistency)).

:- persistent
        user_role(name:atom, role:oneof([user,administrator])).

attach_user_db(File) :-
        db_attach(File, []).

%%  current_user_role(+Name, -Role) is semidet.

current_user_role(Name, Role) :-
        with_mutex(user_db, user_role(Name, Role)).

add_user(Name, Role) :-
        assert_user_role(Name, Role).

set_user_role(Name, Role) :-
        user_role(Name, Role), !.
set_user_role(Name, Role) :-
        with_mutex(user_db,
                   (  retractall_user_role(Name, _),
                      assert_user_role(Name, Role))).
Run Code Online (Sandbox Code Playgroud)

但是,在有关线程同步的文档中mutex,它指出了这一点

谓词的with_mutex/2 …

multithreading message-queue prolog swi-prolog

4
推荐指数
1
解决办法
204
查看次数

编写Prolog谓词以向另一个谓词提供默认参数

我正在学习Prolog,我在本教程中学习 了图表.这是我的代码:

path(X, Y, Length, [X,Y], _) :- 
   connect(X, Y, Length).   
path(X, Y, Length, [X|P], V) :- 
   \+ member(X, V),
   connect(X, Z, Length1),
   path(Z, Y, Length2, P, [X|V]),
   Length is Length1 + Length2.
Run Code Online (Sandbox Code Playgroud)

为了使用它,我打电话

?- path(a, f, Length, Path, []).
Run Code Online (Sandbox Code Playgroud)

但是,我想将其缩短为:

?- path(a, f, Length, Path).
Run Code Online (Sandbox Code Playgroud)

但是我无法获得默认参数.

prolog optional-parameters default-parameters

1
推荐指数
1
解决办法
1047
查看次数

OCaml:运行“dune init exec”后出现沙丘构建错误

我是 OCaml 新手,我按照教程搭建了开发环境。然后我尝试使用沙丘和 OCaml 的helloworld示例,但遇到以下错误:

\n
$ dune init exe helloworld\nSuccess: initialized executable component named helloworld\n$ dune build\nError: I cannot find the root of the current workspace/project.\nIf you would like to create a new dune project, you can type:\n\n    dune init project NAME\n\nOtherwise, please make sure to run dune inside an existing project or\nworkspace. For more information about how dune identifies the root of the\ncurrent workspace/project, please refer to\nhttps://dune.readthedocs.io/en/stable/usage.html#finding-the-root\n
Run Code Online (Sandbox Code Playgroud)\n

目录结构:

\n
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _build\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 log\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 …
Run Code Online (Sandbox Code Playgroud)

ocaml dune

0
推荐指数
1
解决办法
1820
查看次数