我需要为 Prolog 创建一个笛卡尔积计算器。它应该像这样工作:
输入: product([1,2,3], [a,b], X).
输出: X = [[1,a],[2,a],[3,a],[1,b],[2,b],[3,b]].
我知道网上有例子,但我想自己写点东西。
这是我的代码,我认为它非常接近,但由于某种原因,它并不完全有效。有什么想法吗,伙计们?
% call new with 4 parameters (so we can keep List1 in memory)
product(L1,L2,L3):- product(L1,L2,L3,L1).
% stop when both List1 and List2 are empty
product([], [], [], []).
% first list is empty, recreate it and work it again with the next element of second list (and shorten memory)
product([], [_|T2], List3, [H4|T4]):-
product([H4|T4], T2, List3, T4).
%go through first list and always first element of second …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个带有嵌入式数据库(H2)的 Spring Boot 应用程序,并在应用程序启动时使用 liquibase 创建数据,但绝对没有任何效果。
当我转到 http://localhost:8080/h2-console/ 并尝试登录 jdbc:h2:mem:testdb 时,我得到
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help).
Run Code Online (Sandbox Code Playgroud)
这是我的资源/application.properties:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml
logging.level.liquibase = INFO
Run Code Online (Sandbox Code Playgroud)
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> …Run Code Online (Sandbox Code Playgroud)