当我用//
Java 编写注释时,按Enter键,vim有助于//
在下一行的开头添加一个.
// This is the first line of my comment <CR>
// <-- these were added automatically by auto-comment.
Run Code Online (Sandbox Code Playgroud)
正如我所说,这是有用的行为(我//
用于多行注释,以便很容易注释掉大块代码/*...*/
,并/**...*/
仅用于Javadoc注释).但是当我到达评论结束时,我必须按三次退格键才能摆脱//
我现在不再需要的行的开头.
是否有插入模式的键盘快捷键可以告诉Vim我不再写评论?或者我必须自己写?
我在STM32F107VC上使用FreeRTOS V6.1.1并且经常出现malloc错误.堆区域在链接器脚本中定义,但在几次分配后它仍然卡在pvPortMalloc()的这个循环中:
while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
pxBlock: 0x20002300
pxPreviousBlock: 0x20002300
pxNewBlockLink: 0x00
xHeapHasBeenInitialised: 0x01
Run Code Online (Sandbox Code Playgroud)
链接器脚本:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20010000; /* end of 64K RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = …
Run Code Online (Sandbox Code Playgroud) 当Checker Framework的Nullness Checker遇到未初始化的字段时,将生成错误。
[ERROR] /home/glts/src/example/src/main/java/BookRepositoryImpl.java:[39,7]
error: [initialization.fields.uninitialized] the constructor does not initialize fields: em
Run Code Online (Sandbox Code Playgroud)
现在,通过依赖注入注入一些字段是一种常见的模式:
@Repository
public class BookRepositoryImpl implements BookRepository {
@PersistenceContext
private EntityManager em;
@Override
@Nullable
public Book findById(int id) {
return em.find(Book.class, id);
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
在这里,@javax.persistence.PersistenceContext
注释确保在构建存储库em
后将保留对EntityManager
实例的引用。
更一般地,在这些情况下,应用程序框架保证字段被初始化并且在使用时不为空–但是Checker框架不知道这一点。
到目前为止,我发现一种解决方法是将字段注入转换为构造函数注入(@Inject
)。但是,在上面的示例中,这不是选项。
有没有一种方法可以告诉Checker Framework注入了一个字段,因此正确地初始化了该字段并且该字段为非null,而没有简单地抑制这些错误?
如果我有以下列表:
List<String> list = Arrays.asList("hello", "world", "hello");
Run Code Online (Sandbox Code Playgroud)
我应用以下(Java8):
list.stream().distinct().collect(Collectors.toString());
Run Code Online (Sandbox Code Playgroud)
然后我会得到一个包含“hello”和“world”的列表。
但是,就我而言,我有一个类型列表(来自外部 api),我想在其中“绕过”equals 方法,最好使用比较器,因为它没有涵盖我需要的内容。
假设这个类看起来像这样:
public class Point {
float x;
float y;
//getters and setters omitted
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我希望将涵盖特定标准的两点定义为相等,例如 (30, 20) 和 (30.0001, 19.999)。
自定义比较器可以做到这一点,但我发现没有 API 可以执行 Java8 Stream 中的 distinct() 功能,而是使用比较器(或类似模式)。
有什么想法吗?我知道我可以编写这样的函数,但我更喜欢使用现有 apis 的优雅方式......我对外部库没有限制(番石榴、apache-commons 等,如果他们有一种舒适的方式,欢迎使用)我需要的)。
reduce
使用reducers引入了略微修改的版本,clojure.core.reducers/reduce
(简称r/reduce
):
(defn reduce
([f coll]
(reduce f (f) coll))
([f init coll]
(if (instance? java.util.Map coll)
(clojure.core.protocols/kv-reduce coll f init)
(clojure.core.protocols/coll-reduce coll f init))))
Run Code Online (Sandbox Code Playgroud)
r/reduce
不同于它的核心兄弟只是因为它(f)
在没有提供时用作初始值,并且它代表核心reduce-kv
用于映射.
我不明白这种奇怪的特殊用途reduce
可能是什么用途以及为什么值得包含在redurs库中.
奇怪的是,r/reduce
据我所知,在两篇介绍性博客文章中没有提及(第一,第二).官方文档说明
一般来说,大多数用户不会直接调用r/reduce,而应该更喜欢r/fold(...)但是,使用较少的中间结果执行急切减少可能很有用.
我不确定最后一句话暗示的是什么.
什么情况可以r/reduce
处理核心减少不能?我r/reduce
什么时候可以定罪?
用一个例子更容易解释:
my $o = SpecialEffects->new( "config" => 'a' );
my $p = SpecialEffects->new( "config" => 'b' );
$o->sound(); # aliased to fizz(); same as $o->fizz()
$p->sound(); # aliased to clonk(); same as $p->clonk()
Run Code Online (Sandbox Code Playgroud)
是否可以在Perl中执行此操作?也许使用一些typeglob或coderef技巧?
我试图保持SpecialEffects
界面简单.我不想开始构建对象层次结构.该sound()
方法是暴露的,只能稍微配置其行为.
我已经知道你可以使用别名,*sound = \&fizz;
但据我所知,这是一个全局的东西,我希望它封装在对象中.
可以使用行完成Ctrl+ X Ctrl+ L来显示来自特定外部文件的行完成,而不是来自当前缓冲区的"仅"吗?像词典,但线条.
更新:
测试我做了以下:
tt.txt
用一些测试行创建了一个文件:set path+=D:\\t1\\tt.txt
:set complete ?
回报 complete =.,w,b,u,t,i
:set path ?
回报 path=.,,,D:\t1\tt.txt
checkpath
返回:找到所有包含的文件我错过了什么?
我正在尝试计算一行中正则表达式匹配的数量,我需要在 vim 函数中使用结果。例如,计算左大括号的数量。
function! numberOfMatchesExample(lnum)
let line_text = getline(a:lnum)
" This next line is wrong and is the part I'm looking for help with
let match_list = matchlist(line_text, '{')
return len(match_list)
endfunction
Run Code Online (Sandbox Code Playgroud)
所以我想在 vim 函数中找到一种方法来将一行的正则表达式匹配数捕获到一个变量中。
有很多示例说明如何执行此操作并在状态栏上显示结果,请参阅
:h count-items
,但我需要将数字捕获到变量中以便在函数中使用。
我似乎无法在Vim中使用这种模式:( \d{4}
但只能使用\d\d\d\d
)搜索时; 有什么想法吗?
注意:
/
在Normal Mode
和类型化的模式.OrangeBlock
是一个橙色的块,里面有文字.它实现为StackPane
包含矩形顶部的文本.(这种方法在StackPane的文档中得到了证明.)
我已经放置了一个OrangeBlock
坐标(100,80),现在我正试图让它平稳地移动到一些目标坐标.不幸的是,我在路上遇到了一个令人讨厌的问题:
由于某种原因,PathElement
s中的坐标相对于橙色块进行解释.
为什么是这样?我怎样才能OrangeBlock
沿着绝对坐标的路径前行?下面的最小工作示例.
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class PathTransitionExample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
OrangeBlock block = new OrangeBlock(60, 40);
block.relocate(100, 80);
root.getChildren().add(block);
PathTransition transition = newPathTransitionTo(block, 460, 320);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
transition.play();
}
private static PathTransition newPathTransitionTo(OrangeBlock …
Run Code Online (Sandbox Code Playgroud)