小编fcr*_*r79的帖子

JavaScript'in'运算符用于Arrays中的`undefined`元素

请考虑以下代码段:

> a = [1, undefined, undefined, undefined, 3]
  [1, undefined, undefined, undefined, 3]
> b = [1,,,,3]
  [1, undefined × 3, 3]
> 1 in a
  true
> 1 in b
  false
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?似乎是,根据我undefined在数组中定义元素的方式,in运算符的行为会有所不同.

javascript arrays

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

Python:列出和复制它们

我无法解释以下行为:

l1 = [1, 2, 3, 4]
l1[:][0] = 888
print(l1) # [1, 2, 3, 4]
l1[:] = [9, 8, 7, 6]
print(l1) # [9, 8, 7, 6]
Run Code Online (Sandbox Code Playgroud)

它似乎是l1[:][0]指副本,而是l1[:]指对象本身.

python list

11
推荐指数
2
解决办法
372
查看次数

AWS API Gateway 和静态 HTML:“由于配置错误而执行失败:statusCode 应该是请求模板中定义的整数”

我正在尝试使用 AWS API Gateway 提供静态内容。当我尝试从测试页面和 调用 URL 时curl,出现错误:

“由于配置错误,执行失败:statusCode 应该是请求模板中定义的整数”。

这是我在 Terraform 上的配置:

resource "aws_api_gateway_rest_api" "raspberry_api" {
  name        = "raspberry_api"
}

resource "aws_acm_certificate" "raspberry_alexa_mirko_io" {
  domain_name       = "raspberry.alexa.mirko.io"
  validation_method = "DNS"

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_route53_record" "raspberry_alexa_mirko_io_cert_validation" {
  name    = aws_acm_certificate.raspberry_alexa_mirko_io.domain_validation_options.0.resource_record_name
  type    = aws_acm_certificate.raspberry_alexa_mirko_io.domain_validation_options.0.resource_record_type
  zone_id = var.route53_zone_id
  records = [aws_acm_certificate.raspberry_alexa_mirko_io.domain_validation_options.0.resource_record_value]
  ttl     = 60
}

resource "aws_route53_record" "raspberry_alexa_mirko_io" {
  zone_id = var.route53_zone_id
  name = aws_acm_certificate.raspberry_alexa_mirko_io.domain_name
  type = "A"
  alias {
    name = aws_api_gateway_domain_name.raspberry_alexa_mirko_io.cloudfront_domain_name
    zone_id = …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform aws-api-gateway terraform-provider-aws

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

所有权、关闭、FnOnce:很多混乱

我有以下代码片段:

fn f<T: FnOnce() -> u32>(c: T) {
    println!("Hello {}", c());
}

fn main() {
    let mut x = 32;
    let g  = move || {
        x = 33;
        x
    };

    g(); // Error: cannot borrow as mutable. Doubt 1
    f(g); // Instead, this would work. Doubt 2
    println!("{}", x); // 32
}
Run Code Online (Sandbox Code Playgroud)

疑问1

我什至无法运行一次。

疑问2

...但我可以根据需要多次调用该闭包,只要我通过f. 有趣的是,如果我声明它FnMut,我会得到与疑问 1 相同的错误。

疑点3

和特征定义self中指的是什么?这就是关闭本身吗?还是环境?例如,来自文档:FnFnMutFnOnce

pub trait FnMut<Args>: FnOnce<Args> {
    extern "rust-call" …
Run Code Online (Sandbox Code Playgroud)

closures move mutable rust borrowing

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

Clojure 函数和线程宏

我对 Clojure 语言还很陌生。

在阅读有关Clojure 函数的内容时,我找到了这个示例#([%])。所以我尝试按如下方式使用它:

(def test1 #([%]))
(test1 5)
Run Code Online (Sandbox Code Playgroud)

结果,我收到以下错误:

ArityException Wrong number of args (0) passed to: PersistentVector  clojure.lang.AFn.throwArity (AFn.java:429)
Run Code Online (Sandbox Code Playgroud)

这似乎是它试图调用我想要返回的数组。

经过一番挖掘,我找到了解决方案,如下:

(def test1 #(-> [%]))
(test1 5)
Run Code Online (Sandbox Code Playgroud)

我有一些问题:

  1. 为什么工作不成#([%])?我对这个表情做了什么#([x])
  2. 在正确的示例中,我使用了线程优先宏。根据其文档,它用于将参数传递给下一个函数,例如(-> x (+ 1))。在这种情况下,我什至没有可以传递的函数;*在此上下文中的下一个功能是什么?我不明白为什么它解决了我的问题

clojure

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