编辑:我在第一个答案后更改了示例代码,因为我提出了一个简单的版本,提出相同的问题.
我目前正在学习Common Lisp的范围属性.在我认为我有一个扎实的理解后,我决定编写一些我可以预测结果的例子,但显然我错了.我有三个问题,每个问题都与下面的例子有关:
例1:
(defmethod fun1 (x)
(print x)
(fun2))
(defmethod fun2 ()
(print x))
(fun1 5)
Run Code Online (Sandbox Code Playgroud)
输出:
5
*** - EVAL: variable X has no value
Run Code Online (Sandbox Code Playgroud)
问题:这是有道理的.x是静态范围的,fun2无法在没有显式传递的情况下找到x的值.
例2:
(defvar x 100)
(defmethod fun1 (x)
(print x)
(fun2))
(defmethod fun2 ()
(print x))
(fun1 5)
Run Code Online (Sandbox Code Playgroud)
输出:
5
5
Run Code Online (Sandbox Code Playgroud)
问题:我不明白为什么x对fun2突然可见,其值为fun1,而不是值为100 ...
例3:
(setf x 100)
(defmethod fun1 (x)
(print x)
(fun2))
(defmethod fun2 ()
(print x))
(fun1 5)
Run Code Online (Sandbox Code Playgroud)
输出:
5
100
Run Code Online (Sandbox Code Playgroud)
问题:我是否应该忽略这些结果,因为在未声明的变量上调用setf显然是未定义的?这恰好是我在第二个例子中所期望的......
任何见解将不胜感激......
git add -p以交互方式暂存变更非常方便.在每次更改时,它会提示用户按一个键以确定Git应对所涉及的更改执行的操作:
Stage this hunk [y,n,q,a,d,/,K,j,J,g,s,e,?]?
Run Code Online (Sandbox Code Playgroud)
无论如何,让git移动到下一个大块而不必击中Enter?
我有一个问题,IntelliJ(终极)自动在JSX中插入双引号.以下面的例子为例.从a开始div,
<div className />
Run Code Online (Sandbox Code Playgroud)
一旦我输入=,IntelliJ将div更新为以下内容:
<div className="" />
Run Code Online (Sandbox Code Playgroud)
现在,如果我要提供一个字符串并且我想使用双引号,那本来会很好,但我总是喜欢单引号,我最需要引用变量之类的this.props.有没有办法告诉IntelliJ停止自动完成JSX语法?我想禁用此功能并保留其他功能,例如在我编辑标签的一端时自动更新标签名称,但这很烦人,我会接受禁用它.
我有一个TypeScript无法推断其泛型的类型。
interface Foo<A> {
[name: string] : {
foo : A
}
}
function makeFoo<A>(foo: Foo<A>) : Foo<A>{
return foo
}
// Works fine when manually specifying the types
const manuallyTyped : Foo<string | number> = {
a: {
foo: '1'
},
b: {
foo: 3
}
}
// ERROR, Can't infer type as Foo<string | number>
makeFoo({
a: {
foo: '1'
},
b: {
foo: 3
}
})
Run Code Online (Sandbox Code Playgroud)
最初,我使用下面的类型,但是我想自己创建对象对象的值。当索引签名是平坦的时,推理就可以正常工作。
interface FlatFoo<B> {
[name: string] : B
}
function makeFlatFoo<B>(bar: …Run Code Online (Sandbox Code Playgroud) 我将今天遇到的问题简化为这个最小的示例。(游乐场链接)
function test() {
interface Foo<T> {
type: 'Bar'
}
function nextFoo<T>(it: Foo<T>): Foo<T> {
return it
}
let foo: Foo<string> | undefined = { type: 'Bar' }
while (foo !== undefined) {
// Type inference error here but TS has the correct inference when hovering over nextFoo
const next = nextFoo(foo)
foo = next // commenting this out masks the issue
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是 TypeScript 应该能够处理的事情。当我将鼠标悬停nextFoo在 vscode 中时,它看起来确实正确地推断出那里的类型。设置foo为nextwhile 它可能会undefined导致这种情况。 …
mypy 新手,在从集合中过滤选项时,我无法找到使类型正常工作的正确方法。
from typing import Optional, List
list1: List[Optional[int]] = [1, None, 3]
# This type is an error, filter can't even handle a list with optionals
list2: List[int] = list(filter(lambda n: n is not None, list1))
Run Code Online (Sandbox Code Playgroud)
我应该铸造这个吗?mypy 是否应该能够推断出 None 现在被过滤掉了?
我肯定需要根据反馈进行更新,所以我提前道歉。
我要解决的问题大致是这样的。
该图显示 Windows 任务管理器中的磁盘利用率。我的 sqlite 应用程序是一个网络服务器,它接收带有时间戳的 json 请求,在 2 列键/值表中查找现有条目,将请求合并到现有项目中(它们不会随着时间的推移而增长),然后将其写回到数据库。
数据库创建如下。我已经尝试过使用和不使用 WAL,没有任何区别。
createStatement().use { it.executeUpdate("CREATE TABLE IF NOT EXISTS items ( key TEXT NOT NULL PRIMARY KEY, value BLOB );") }
Run Code Online (Sandbox Code Playgroud)
写入/设置如下完成
try {
val insertStatement = "INSERT OR REPLACE INTO items (key, value) VALUES (?, ?)"
prepareStatement(insertStatement).use {
it.setBytes(1, keySerializer.serialize(key))
it.setBytes(2, valueSerializer.serialize(value))
it.executeUpdate()
}
commit()
} catch (t: Throwable) {
rollback()
throw t
}
Run Code Online (Sandbox Code Playgroud)
我始终使用单个数据库连接,这对于我的用例来说似乎没问题,并且相对于为每个操作获取新连接而言,大大提高了性能。
val databaseUrl = "jdbc:sqlite:${System.getProperty("java.io.tmpdir")}/$name-map-v2.sqlite"
if (connection?.isClosed == true || connection == null) { …Run Code Online (Sandbox Code Playgroud) 我正在查看标准库中包含的一些较酷的类型函数,我开始玩了.在TypeScript中实际上是否可以这样?
interface OriginalType {
A: { a : string }
B: { b1 : string, b2: number }
C: {}
D: {c: string}
}
const r : {a: string, b1: string, b2: string} = pickAndFlatten<OriginalType>(['A', 'B'])
Run Code Online (Sandbox Code Playgroud) 尝试创建一个带有单个参数对象的函数,该对象必须没有一组键,而无需使人们手动指定类型。我试图以never某种方式加以利用,但是却陷入了试图理解对具有通用参数类型的函数参数进行推论的过程。
interface ReservedAttributes {
someKey: string
}
// evaluates to never if the type has a key that intersects
// with the keys in ReservedAttributes
type ValidAttributes<T> = keyof T extends Exclude<keyof T, keyof ReservedAttributes> ? T : never
// This is correctly a never, but it doesn't address this problem
type Test = ValidAttributes<{someKey : string}>
// This doesn't work because the function argument ends
// up being inferred as { [name: string] : string}
function foo1<K …Run Code Online (Sandbox Code Playgroud) 我正在使用 Docker 在容器中运行 java REST 服务。如果我在容器之外,那么我可能会使用进程管理器/主管来确保 java 服务在遇到奇怪的一次性错误时重新启动。我看到一些关于在容器内使用supervisord 的帖子,但似乎它们主要专注于运行多个服务,而不是仅仅保持一个服务的运行。
管理容器中运行的服务的常用方法是什么?我应该只在容器本身上使用一些内置的 Docker 东西,而不是尝试包含进程管理器吗?