我正在使用官方指南试用 Clojure 。这是我对该链接问题 8 的解决方案,即编写一个opposite应该模仿该complement函数的函数:
(defn opposite [f] (fn [& args] (not (apply f args))))
Run Code Online (Sandbox Code Playgroud)
为了比较,这里是 的源代码complement:
(defn complement
"Takes a fn f and returns a fn that takes the same arguments as f,
has the same effects, if any, and returns the opposite truth value."
{:added "1.0"
:static true}
[f]
(fn
([] (not (f)))
([x] (not (f x)))
([x y] (not (f x y)))
([x y & zs] (not (apply f …Run Code Online (Sandbox Code Playgroud) 这是我正在使用Formik和react-bootstrap编写的表单的模板。我发现一个非常奇怪的错误:如果我在构造函数中用伪数据初始化状态,那么它将正常工作;但是,如果我使用完全相同的数据调用setState componentDidMount来模拟API调用,则它将严重中断。
具体来说,我发现状态变量alertVehicles数组的长度可以为非零,但相应的Formik values.alertVehicles变量可以为空。现在,所写的表单未显示任何复选框。如果我在guard子句中使用alertVehicles而不是values.alertVehicles,则它会因error爆炸Cannot read property 'selected' of undefined。
import React, {Component} from 'react';
import Form from 'react-bootstrap/Form';
import { Formik } from 'formik';
import Button from 'react-bootstrap/Button';
class Alerts extends Component {
constructor(props) {
super(props);
this.loadAlertData = this.loadAlertData.bind(this);
this.state = {
alertRecipient: {},
alertId: '',
alertVehicles: []
}
}
componentDidMount(){
this.loadAlertData();
}
loadAlertData(){
// this will be an API call eventually, obviously.
// if this is initialised in the …Run Code Online (Sandbox Code Playgroud) 我正在尝试(重新)使用rvm 1.29.1在运行OS X Sierra的全新MBP上安装ruby 1.8.7.我HAVE完成这件事的工作,我不是在一个位置切换到更新版本或任何不幸.
我有一个功能安装,但在一个项目中得到一些奇怪的错误后决定尝试完全干净的重新安装rvm(并最终自制!)(长篇故事 - 从名称中删除不需要的空间后,文件结构已损坏我的主目录!).我小心地从.bashrc,.profile等删除了旧安装的所有痕迹,跟随此处的其他帖子.2.4.0安装并运行正常.但是,在尝试安装1.8.7时:
9bxbniv1:~ Rob$ rvm install ruby-1.8.7
Warning! Requested ruby installation which requires another ruby available - installing ruby-1.8.7-p374 first.
ruby-1.8.7-p374 - #removing src/ruby-1.8.7-p374..
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl@1.1/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/Rob/.rvm/rubies/ruby-1.8.7-p374, this may take a while depending on your cpu(s)...
ruby-1.8.7-p374 - #downloading ruby-1.8.7-p374, this may take a while depending on your connection...
ruby-1.8.7-p374 - #extracting ruby-1.8.7-p374 to …Run Code Online (Sandbox Code Playgroud)