小编Har*_*hna的帖子

23
推荐指数
2
解决办法
2603
查看次数

使用say函数时,为什么要指定use语句?

这个问题可能很愚蠢.但我刚开始探索Perl.我使用的是Perl v5.16.2.我知道该say声明已在5.10中引入.

#!/usr/bin/perl

say "Hello World!";
Run Code Online (Sandbox Code Playgroud)

当我尝试运行上面的程序时,我收到以下错误:

$ ./helloPerl 
String found where operator expected at ./helloPerl line 3, near "say "Hello World!""
    (Do you need to predeclare say?)
syntax error at ./helloPerl line 3, near "say "Hello World!""
Execution of ./helloPerl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

但是当我添加声明时use 5.016;,它正在给我正确的输出.

#!/usr/bin/perl

use 5.016;
say "Hello World!";
Run Code Online (Sandbox Code Playgroud)

我怀疑的是,我使用的是perl v5.16.2,它高于5.010.我为什么要use在这里使用语句提到Perl版本?

perl

15
推荐指数
2
解决办法
2617
查看次数

什么是'proxy.mycompany1.local'

我刚开始使用Java网络协议.我正在尝试使用我的代理服务器连接到互联网.当我在" https://www.tutorialspoint.com/javaexamples/net_poxy.htm "上看到帖子时,他们将http.proxyHost属性设置为"proxy.mycompany1.local".我知道我可以将它设置为我的代理服务器IP,但我很想知道为什么我的程序仍然有效,即使我将它设置为一些随机字符串,如"abcd".

A.'proxy.mycompany1.local'代表什么?

B.为什么我的程序工作,即使我将http.proxyHost设置为"abcd"?

以下是我的工作计划:

import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URL;

public class TestProxy {
    public static void main(String s[]) throws Exception {
        try {

            System.setProperty("http.proxyHost", "abcd");
            System.setProperty("http.proxyPort", "8080");

            URL u = new URL("http://www.google.com");
            HttpURLConnection con = (HttpURLConnection) u.openConnection();
            System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(false);
        }
        Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("http://www.google.com")).iterator().next();
        System.out.println("proxy Type : " + proxy.type());
        InetSocketAddress addr = (InetSocketAddress) proxy.address();
        if (addr …
Run Code Online (Sandbox Code Playgroud)

java proxy

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

如何在中缀形式中使用类型构造函数

我正在阅读一些Haskell文档,并找到了声明

您可以将构造函数(对于类型和数据)声明为中缀运算符,这可以使您的代码更具可读性.

我可以使用中缀形式的数据构造函数,如下所示:

Prelude> data List a = Empty | a :-> (List a) deriving Show
Prelude> 
Prelude> let var1 = 10 :-> Empty
Prelude> let var2 = 20 :-> var1
Prelude> let var3 = 30 :-> var2
Prelude> 
Prelude> var1
10 :-> Empty
Prelude> 
Prelude> var2
20 :-> (10 :-> Empty)
Prelude> 
Prelude> var3
30 :-> (20 :-> (10 :-> Empty))
Run Code Online (Sandbox Code Playgroud)

我的问题是如何在中缀形式中使用类型构造函数,有人能给我一个例子来理解这个吗?

syntax haskell

6
推荐指数
2
解决办法
140
查看次数

无法解析 swt 库

我正在使用下面的 maven 依赖来开发 swt 应用程序。

<dependency>
  <groupId>org.eclipse.platform</groupId>
  <artifactId>org.eclipse.swt</artifactId>
  <version>3.108.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试导入以下包时,

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
Run Code Online (Sandbox Code Playgroud)

我收到类似“无法解析导入 org.eclipse”的错误消息

使用 swt 桌面应用程序的正确 maven 依赖项是什么?

swt maven

5
推荐指数
2
解决办法
1489
查看次数

Haskell:不在范围内:'listDirectory'

我使用的是GHC版本7.10.2.当我尝试使用listDirectory函数时,我收到以下错误.

Prelude System.Directory> :t listDirectory

<interactive>:1:1: Not in scope: ‘listDirectory’
Run Code Online (Sandbox Code Playgroud)

我也使用'cabal update'更新了我的包.

参考 https://hackage.haskell.org/package/directory-1.2.5.1/docs/System-Directory.html

haskell

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

meanbean:无法使用数组测试 bean

我正在使用 mean bean ' http://meanbean.sourceforge.net ' 来验证/测试我的 bean。它适用于大多数豆类。但是当一个 bean 中有数组时,它会因以下错误而失败。

SEVERE: getFactory: Failed to find suitable Factory for property=[hostNames] of type=[class [I]. Please register a custom Factory. Throw NoSuchFactoryException.
org.meanbean.factories.ObjectCreationException: Failed to instantiate object of type [[I] due to NoSuchMethodException.
Run Code Online (Sandbox Code Playgroud)

以下是我的示例代码。

public class Machine {
private String[] hostNames;

public String[] getHostNames() {
    return hostNames;
}

public void setHostNames(String[] hostNames) {
    this.hostNames = hostNames;
}
Run Code Online (Sandbox Code Playgroud)

}

import org.junit.Test;
import org.meanbean.test.BeanTester;

public class TestBeanUtil {
    @Test
     public void test1(){
        new BeanTester().testBean(Machine.class);
    } …
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
2
解决办法
5562
查看次数

Haskell:类型类:多继承示例

我开始知道我们可以使用类型类实现多重继承.我写过小的haskell代码,但无法弄清楚问题.

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StandaloneDeriving #-}

class (Eq a, Show a) => C a where
    getHashCode :: a -> Integer
    getHashCode obj = 123


type Id = Int
type Name = String

data Employee = Employee Id Name deriving C
Run Code Online (Sandbox Code Playgroud)

当我试图加载上面的代码时,我收到以下错误.对此有任何帮助.

 No instance for (Eq Employee)
      arising from the 'deriving' clause of a data type declaration
   Possible fix:
      use a standalone 'deriving instance' declaration,
        so you can specify the instance context yourself
    When …
Run Code Online (Sandbox Code Playgroud)

inheritance haskell

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

为什么gcc打印"Segmentation fault:11"?

当我使用gcc编译器在程序下面运行时,我最终出现在"Segmentation fault:11"中,但是当我在" https://www.onlinegdb.com/online_c_compiler "运行时,它执行得非常好.我想知道,为什么gcc在这里抛出分段错误?

#include <stdio.h>

int main(){

    typedef int myArray[10];

    myArray x = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};//Equivalant to x[10]
    myArray y[2]; //equivalant to y[10][2]

    int counter = 0;

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 2; j++){
            //printf("%i %i\n", i, j);
            y[i][j] = counter++;
        }
    }

    printf("\n\nElements in array x are\n");
    for(int i = 0; i < 10; i++){
        printf("x[%i] = %i\n", i, x[i]);
    }

    printf("\n\nElements …
Run Code Online (Sandbox Code Playgroud)

c gcc

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

Haskell:需要了解Functor的签名

有些人可以向我解释Functor的签名.

Prelude> :info Functor
class Functor (f :: * -> *) where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a
Run Code Online (Sandbox Code Playgroud)

我不明白是什么*意思.

haskell

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

标签 统计

haskell ×4

java ×3

c ×1

gcc ×1

inheritance ×1

java-8 ×1

maven ×1

parameters ×1

perl ×1

proxy ×1

swt ×1

syntax ×1

this ×1