小编Ele*_*fee的帖子

为什么`def hello [T](f:=> T)= f; hello(()=> 12)`是可编译的但是`def hello(f:=> Int)= f; 你好(()=> 12)`不是吗?

以下代码可以编译:

def hello[T](f: => T) = f
hello(() => 12)
Run Code Online (Sandbox Code Playgroud)

但不是:

def hello(f: => Int) = f
hello(() => 12)
Run Code Online (Sandbox Code Playgroud)

哪个报告错误:

<console>:9: error: type mismatch;
 found   : () => Int
 required: Int
                  hello(() => 12)
Run Code Online (Sandbox Code Playgroud)

为什么?

scala callbyname

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

如何编写将重复命令的宏?

我正在尝试编写一个宏,让我简化一个表达式中多个顶级变量的定义.

这个想法是让它的工作方式类似于let:

(defparameters ((*foo* 42)
                (*bar* 31)
                (*baz* 99)))
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下内容,但似乎没有做任何事情.

(defmacro defparameters (exprs)
  (dolist (expr exprs)
    (let ((name (car  expr))
          (exp  (cadr expr)))
      `(defparameter ,name ,exp))))
Run Code Online (Sandbox Code Playgroud)

我尝试过使用macroexpand它但似乎根本没有扩展.

我究竟做错了什么?我该如何解决?

macros common-lisp

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

Erlang有地图吗?

似乎Erlang在版本R17A中引入了地图.

但是,如果我进入下载页面,我只看到版本17.5,没有版本R17A.

那么,它是否已经发布且稳定了吗?最新稳定的Erlang是否有地图支持?

erlang

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

Haskell +输出String作为String类型

我写了一个基本的递归函数:

bibliography_rec :: [(String, String, Int)] -> String
bibliography_rec [] = ""
bibliography_rec (x:xs) = (citeBook x) ++ "\n" ++ (bibliography_rec xs)
Run Code Online (Sandbox Code Playgroud)

citeBook 只需将元组重新格式化为String.

使用此输入运行时:

ghci> bibliography_rec [("Herman Melville", "Moby Dick", 1851),("Georgy Poo", "Alex Janakos", 1666)]
Run Code Online (Sandbox Code Playgroud)

它产生:

"Moby Dick (Herman Melville, 1851)\nAlex Janakos (Georgy Poo, 1666)\n"
Run Code Online (Sandbox Code Playgroud)

我需要逐行打印,所以我使用了这个:

bibliography_rec (x:xs) = putStr ((citeBook x) ++ "\n" ++ (bibliography_rec xs))
Run Code Online (Sandbox Code Playgroud)

我的问题是我的输出需要是StringNOT 类型IO ()

我一直坚持这个问题太久了,所以任何帮助都很棒!

string io haskell

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

PhpWord 输出在 LibreOffice 中不起作用,但在 MS Word 中工作正常

这与 GitHub 页面 [链接]上列出的一个半已知问题有关,其中 PhpWord 生成表格的方式导致它将单元格宽度设置为“”,这在 LibreOffice 中无效,但在 Word 中很好。

GitHub 上的问题专门列出了 html-to-word 转换,但我在使用常规的面向对象界面时也遇到了这个问题。

我试过手动设置单元格宽度,但它似乎没有做任何事情。

我在这里询问是否有人对此问题有任何解决方法,因为它几乎不可能在不访问 MS Word 的情况下在 Linux 机器上调试我的输出。我需要为客户导出 .docx。

为什么不直接导出到 .odt 来测试它呢?如果我这样做,它也不会呈现我在页面上的列表......

这是我正在处理的文档的粗略概述(由于保密协议,我不能随意分享确切的代码):

$document = new PhpWord\PhpWord();
$section = $document->addSection();

// This list doesn't get rendered in the ODT file
$section->addListItem('Employee ID: 98765');
$section->addListItem('First Name: John');
$section->addListItem('Last Name: Doe');
$section->addListItem('SSN: 12345');

// This table has errors in LibreOffice when exported to .docx
if ($show_adv_details) {
    $table = $section->addTable();
    $table->addRow();
    $table->addCell()->addText('SSN');
    $table->addCell()->addText('Email');
    $table->addCell()->addText('Phone No');
    
    $table->addRow();
    $table->addCell()->addText('12345'); …
Run Code Online (Sandbox Code Playgroud)

php ms-word libreoffice phpword

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

Objective-C(Mac)try-catch没有捕获异常

这是我的方法:

- (IBAction)calculateButton:(id)sender {
    NSInteger dividend = 0;
    NSInteger divisor = 0;

    @try {
        dividend = [dividendField integerValue];
        divisor = [divisorField integerValue];
        [quotientField setIntegerValue: dividend / divisor]; //program crashes here
        [remainderField setIntegerValue: dividend % divisor];
    }

    @catch (NSException *exception) {
        NSAlert* alert = [[NSAlert alloc] init];
        [alert setMessageText: @"Error"];
        [alert setInformativeText: @"Invalid input!"];
        [alert runModal];
    }

}
Run Code Online (Sandbox Code Playgroud)

我理解它的方式NSException是一个通用异常处理程序,所有其他异常都继承自; 所以问题是,为什么程序崩溃而不是进入@catch块?EXC_ARITHMETIC根据我的理解,我得到了一个例外......那么为什么不@catch赶上它呢?

macos cocoa objective-c

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

简单的Java整数和长算术

简单的代码没问题

long x =  Integer.MAX_VALUE;
System.out.println(x * 2 + "...." + Long.MAX_VALUE);

= 4294967294....9223372036854775807
Run Code Online (Sandbox Code Playgroud)

但这里发生了什么?为什么-2

System.out.println(2 * Integer.MAX_VALUE + "...." + Long.MAX_VALUE);
=   -2....9223372036854775807
Run Code Online (Sandbox Code Playgroud)

为什么元素是149998,编译器不会将这些转换为long?

    long elements = 2 * Integer.MAX_VALUE + 150000;
System.out.println(elements + "...." + Long.MAX_VALUE);
149998....9223372036854775807
Run Code Online (Sandbox Code Playgroud)

-谢谢

java int long-integer

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