我试图保持我的Prolog代码模块化,我想知道是否有人对如何做到这一点有任何建议.我用简单consult
的方式做这个的方式,但随着我的文件数量的增加而变得越来越麻烦,并且因为命名冲突而屈服.是否存在类似于"典型"导入的构造,例如
%-------------------------------------------------------------------- compiler.pl
[ scanner, parser, codegen ] .
%-------------------------------------------------------------------- compile
% compile( S, I ) :- Compiling the source string S gives the list of instructions
% I
compile( S, I ) :- scan( S, T ), parse( T, A ), codegen( A, I ) .
%-------------------------------------------------------------------------------%
Run Code Online (Sandbox Code Playgroud)
在源文件的顶部?如果它是特定于程序的,我正在使用gprolog
.在此先感谢您的帮助.
我有一个相当简单的haskell项目设置,我只想让框架在我开始编码之前使用测试等等.我有一个/src
目录中可执行文件的源文件(/
项目的根目录)和我在/testsuite
目录中的测试./testsuite
包含称为一个简单的测试文件,TestSuite.hs
以main = Test.Framework.defautMain tests
作为主要的执行.问题是,当我跑步时
cabal clean && cabal configure --enable-tests && cabal build
Run Code Online (Sandbox Code Playgroud)
我收到了警告
output was redirected with -o, but no output will be generated because there is no main module.
Run Code Online (Sandbox Code Playgroud)
我没有指定时,构建工作正常--enable-tests
.我的cabal文件是:
Name: Example
Version: 0.1
Synopsis: Synopsis
Description:
Long description.
License: GPL
License-File: LICENSE
Author: SeanK
Maintainer: email@example.com
Category: Development
Build-Type: Simple
Cabal-Version: >= 1.8
Test-Suite test
Type: exitcode-stdio-1.0
Main-Is: TestSuite.hs
Build-Depends: base >= 3 …
Run Code Online (Sandbox Code Playgroud) 嘿所有,对于我的一些大学作业,我发现需要检查二维阵列(网格)中的相邻单元格.我使用的解决方案是使用异常的一些黑客攻击,我正在寻找一种方法来清理它,而不需要if
像我的一些同学一样的大量语句.我目前的解决方案是
for ( int row = 0; row < grid.length; row++ ) {
for ( int col = 0; col < grid.length; col++ ) {
// this section will usually be in a function
// checks neighbours of the current "cell"
try {
for ( int rowMod = -1; rowMod <= 1; rowMod++ ) {
for ( int colMod = -1; colMod <= 1; colMod++ ) {
if ( someVar == grid[row+rowMod][col+colMod] ) {
// do something
} …
Run Code Online (Sandbox Code Playgroud) 虽然我只有一个github存储库,我正在推动(单独),我经常忘记运行测试,或忘记提交所有相关文件,或依赖驻留在我的本地计算机上的对象.这会导致构建中断,但只有在错误提交后才会被Travis-CI检测到.我知道TeamCity有一个预提交测试工具(它依赖于使用的IDE),但我的问题是关于当前使用持续集成而不是任何一个实现.我的问题是
为什么在提交更改之前,未在干净的构建计算机上测试更改(例如Travis-CI用于提交后测试的更改)?
这样的过程意味着永远不会有构建中断,这意味着新环境可以从存储库中提取任何提交并确保其成功; 因此,我不明白为什么CI没有使用提交后测试实现.
testing teamcity continuous-integration repository travis-ci
我已经用Scala中的每个项目之一写了一个有界背包问题的答案,并尝试将其转换为Haskell,结果如下:
knapsack :: [ ( Int, Int ) ] -> [ ( Int, Int ) ] -> Int -> [ ( Int, Int ) ]
knapsack xs [] _ = xs
knapsack xs ys max =
foldr (maxOf) [ ] [ knapsack ( y : xs ) ( filter (y /=) ys ) max | y <- ys
, weightOf( y : xs ) <= max ]
maxOf :: [ ( Int, Int ) ] -> [ ( Int, Int …
Run Code Online (Sandbox Code Playgroud) 我想通过侦听端口,运行子命令(连接到该端口),然后通过连接转发数据来通过连接隧道子命令:
package main
import (
"fmt"
"net"
"os"
"os/exec"
)
func main() {
ln, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: localhost})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer ln.Close()
port := ln.Addr().(*net.TCPAddr).Port
cmd := exec.Command(
"git",
"clone",
fmt.Sprintf("git://127.0.0.1:%d/project.git", port),
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer cmd.Process.Kill()
errs := make(chan error, 1)
go func() {
errs <- cmd.Wait()
}()
conns := make(chan net.Conn, 1)
go func() …
Run Code Online (Sandbox Code Playgroud) 我想测试bash脚本的输出,当它依赖的其中一个可执行文件丢失时,所以我想运行该脚本的依赖项"隐藏"而不是其他.PATH= ./script
不是一个选项,因为脚本在到达我想要测试的语句之前需要运行其他可执行文件.有没有一种方法可以在不改变文件系统的情况下从脚本中"隐藏"可执行文件?
举个具体的例子,我想运行这个脚本,但是要隐藏git
可执行文件(这是它的主要依赖项),以便我可以在这些条件下测试它的输出.
嘿所有,每当我尝试ImageInputStream
使用ImageIO.createImageInputStream
它来获取一个对象时,只返回null
没有异常,警告或错误.我已经尝试将不同的数据类型传递给函数,一个简单的File
,一个InputStream
,但两者都返回null
.文档说如果没有ImageInputStreamSpi
找到合适的,那么该函数将返回null
,但该文件是一个标准的JPEG标准,并且Java肯定会带有一个开箱即用的格式的服务提供商?谢谢你的时间.
/**
* Reads in an image from a file and returns the image in a
* {@code BufferedImage} object.
*
* @param source the file to create the {@code BufferedImage}
* from.
* @return the {@code BufferedImage} object representing the image
* in {@code source}.
*/
private BufferedImage readImage( File source ) {
// There is only one image in this file
final …
Run Code Online (Sandbox Code Playgroud) 我在<td>
s 里面有链接,但我也有一个点击事件<td>
.代码如下所示:
$( document ).ready( function() {
$( 'td.event' ).click( function() {
var eventName = prompt( 'Enter event:' );
if ( eventName != null && eventName.length > 0 ) {
window.location = '?event=' + eventName;
}
} );
} );
Run Code Online (Sandbox Code Playgroud)
我想简单地按照链接而不显示弹出窗口,如果用户点击链接,但是如果用户点击其中的任何其他位置则显示弹出窗口<td>
.这可能在JQuery中吗?
在Haskell中,我有一个部分订单类型的模块:
data PartialOrder a = PartialOrder [a] [(a, a)]
Run Code Online (Sandbox Code Playgroud)
我不导出值构造函数,因为这不是我想要使用的类型,但我仍然希望能够在模块外部模式匹配PartialOrder类型; 这可能吗?特别是,我希望能够模式匹配不是类型构造函数的东西,而是模式匹配如下所示的东西:
f (PartialOrder xs le) = ...
Run Code Online (Sandbox Code Playgroud)
其中le
一个函数隐式定义值构造函数中定义的显式排序.我知道Scala中有这样的工具,有没有办法在Haskell中做同样的事情?
提前致谢.
haskell ×3
java ×2
testing ×2
bash ×1
build ×1
cabal ×1
exception ×1
gnu-prolog ×1
jquery ×1
modularity ×1
module ×1
performance ×1
prolog ×1
repository ×1
scala ×1
scalability ×1
security ×1
shell ×1
sockets ×1
teamcity ×1
travis-ci ×1
tunnel ×1