我已经构建了一些玩具C++库来快速创建一个来自Lisp的Qt窗口.我知道common-qt存在,我只是想学习如何使用cffi.
现在,我有4个绑定功能:
这是一个完美运行的lisp代码:
(defctype t-app :pointer)
(defctype t-window :pointer)
(defcfun (create-application "create_application" ) t-app)
(defcfun (exec "exec") :void (app t-app))
(defcfun (create-window-aalt "create_window_aalt") t-window)
(defcfun (show "show") :void (o t-window))
(defparameter a (create-application))
(defparameter w (create-window-aalt))
(show w)
(exec a)
Run Code Online (Sandbox Code Playgroud)
但如果我使用LET或LET*......我有内存故障!
(let* ((a (create-application)) (w (create-window-aalt)))
(show w)
(exec a))
CORRUPTION WARNING in SBCL pid 1312(tid 140737353860992):
Memory fault at a556508 (pc=0x7ffff659b7f1, sp=0x7ffff2bbe688)
The integrity of this image is possibly compromised.
Exiting.
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?
我正在使用SBCL:
env …Run Code Online (Sandbox Code Playgroud) 有这个问题的解决方案吗?
class ViewController : UIViewController {
let collectionFlowLayout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: collectionFlowLayout)
}
Run Code Online (Sandbox Code Playgroud)
xcode给我以下错误
ViewController.swift: 'ViewController.Type' does not have a member named 'collectionFlowLayout'
Run Code Online (Sandbox Code Playgroud)
我可以使它成为一个可选项并在init方法中初始化它,但我正在寻找一种方法来使collectionview成为let而不是var
我最近开始使用 rspec 进行测试,所以我可能会犯错误,如果有更好的方法请纠正我
我创建了两个相关模型
let(:user) {FactoryGirl.create :user}
let!(:participation) {FactoryGirl.create :participation, user: user}
Run Code Online (Sandbox Code Playgroud)
在其中一项测试更改相关对象之一之前
context "when" do
before {participation.prize = 100}
it "" do
binding.pry
end
end
Run Code Online (Sandbox Code Playgroud)
但里面
participation.prize => 100
user.participatons.select(:prize) => nil
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 ?以及如何解决它?
应该使用什么来在 Swift 中创建类的实例,为什么?
请解释在 Swift 中创建实例过程中 let 和 var 的用法
以下是代码:-
class ConstantTest{
let constant: String
init(constant: String) {
self.constant = constant
}
func printConstant() {
print(constant)
}
}
let constanttest = ConstantTest(constant: "Hello")
constanttest.printConstant()
var test = ConstantTest(constant: "Hie")
test.printConstant()
Run Code Online (Sandbox Code Playgroud) 是否可以let取消定义一个定义的变量,以便我可以重新定义它?使用var,我可以一遍又一遍地重新定义同一个变量。使用let,再次尝试定义变量时遇到错误。
(你可能想知道我为什么要这样做,原因是我经常从我的浏览器控制台运行和重新运行小的单行和多行脚本,从别处复制粘贴或作为书签。如果那些小脚本使用 定义了一个变量let,然后重新运行脚本失败。var在这些情况下我可以继续使用,但我正在尝试接受新订单。无论您认为我的用例是否有效,问题成立。)
我已经尝试delete从window对象和其他一些黑客攻击,但无济于事。
出于性能目的,我想知道 ES6 JavaScript 之间的区别:
var list = [...];
let item; //let outside the loop
for (let i = 0; i < list.length; i++) {
item = list[i];
}
Run Code Online (Sandbox Code Playgroud)
和
var list = [...];
for (let i = 0; i < list.length; i++) {
const item = list[i]; //const inside the loop
}
Run Code Online (Sandbox Code Playgroud)
假设该item变量旨在在循环内保持不变。
有推荐吗?相对于性能而言,每种方法的优缺点是什么?GC 处理它们的方式不同吗?
请注意,这是微优化。此外,性能取决于所使用的 JS 引擎。(见答案)
我正在尝试做一些应该很简单的事情:我想在 *ngFor 中执行一个函数。该函数返回一个对象。我想在一种“let”语句中设置该对象,这样我就可以在 HTML 中使用它的属性:
<div *ngFor="let productGroup of getproductGroupBySomeVariable(variable)">
<!-- This is where I need to set a variable with the output of
the getProductBySomeProperty function-->
<div *ngLet="'{{getProductBySomeProperty(productGroup.someproperty)}}'
as myVar" class="ui-g">
<!-- Here I want to use and display the properties of the
object created by the function above-->
<span>{{myVar.property1}} </span>
<span>{{myVar.property2}} </span> etc....
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我想了解以下 TypeScript 行为:
下面的代码
let a: number
if (a === undefined) {
console.log("how?")
}
Run Code Online (Sandbox Code Playgroud)
抛出错误:“变量'a'在分配之前被使用。”。
但是下面的代码
let a: number
const f = (): void => {
if (a === undefined) {
console.log("how?")
}
}
f()
Run Code Online (Sandbox Code Playgroud)
工作正常并记录“如何?”。
这是为什么?而且,a === undefined如果它的类型是 ,那又如何呢number?
在下面的代码中,我不确定我是否理解为什么_nested2.
这是否意味着只有顶级定义才能概括其推断类型以匹配显式多态签名?
let toplevel1 : 'a. 'a -> int = (fun _ -> 0)
let toplevel2 : 'a. 'a -> int = (fun (_ : 'a) -> 0)
let nest1 =
let _nested1 : 'a. 'a -> int = (fun _ -> 0) in 0
let nest2 =
let _nested2 : 'a. 'a -> int = (fun (_ : 'a) -> 0) in 0
(* ^^^^^^^^^^^^^^^^^^^
Error: This definition has type 'a -> int which is less general …Run Code Online (Sandbox Code Playgroud) 回顾这个问题,我希望在数组中创建一个运行总计,但在数组的每一行中重新开始
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
导致
| 1 | 3 | 6 | 10 |
| 5 | 11 | 18 | 26 |
一种解决方案是使用 Makearray,效果很好:
=MAKEARRAY(
2,
4,
LAMBDA(r, c,
SUM(
INDEX(sheet1!A1:D2, r, 1) : INDEX(sheet1!A1:D2, r, c)
)
)
)
Run Code Online (Sandbox Code Playgroud)
不过,我现在希望使用 Let 语句更普遍地编写此内容:
=LET(
range, Sheet1!A1:D2,
MAKEARRAY(
rows(range),
Columns(range),
LAMBDA(r, c,
SUM(INDEX(range, r, 1) : INDEX(range, r, c))
)
)
)
Run Code Online (Sandbox Code Playgroud)
但这会导致
这个非常相似的公式可以正常工作(它不应该解决原始问题,而只是测试是否可以将范围传递到 Let 语句内的 lambda):
=LET(
range, Sheet1!A1:D2,
SCAN(0, range, LAMBDA(a, c, a + c + INDEX(range, 1, 1)))
)
Run Code Online (Sandbox Code Playgroud)
相同的代码还可以将范围作为参数传递到 …