在这个例子中,我无法弄清楚如何将可选参数c设置为空List(Of thing):
Sub abcd(a as something, b as something, optional c as List(Of thing) = ?? )
' *stuff*
End Sub
Run Code Online (Sandbox Code Playgroud)
我认为设置c到null,但是这似乎是一个坏事情.
I'm trying to iterate a list, wherein each iteration I'm doing one of the below:
What I need is that after I'm iterating through all the items, it will continue to iterate until the list is empty (the logic ensures all elements will be removed).
Problem is that after the iterator iterates all the list elements, it didn't continue to run on the elements I didn't remove:
List<Integer> lst …Run Code Online (Sandbox Code Playgroud) 假设我有一个具有以下签名的函数:
Foo[] getSomeFoos()
{
//return null --- option A
or
//return new Foo[0]; --- option B
}
Run Code Online (Sandbox Code Playgroud)
返回值的建议做法是什么,表示没有返回元素?每个选项的优缺点是什么?
我想弄清楚数组是否为空.我试过这个并没有用.
a = []
if a == []
alert "empty"
Run Code Online (Sandbox Code Playgroud)
我知道我可以检查数组的长度,但我很好奇为什么这不起作用.
对于像我这样的Prolog初学者来说空列表是......很奇怪.我会说,不可能将空列表写[]为差异列表T1-T2,因为不可能将原子写为差异列表.但是,我猜想要使用递归,必须有一种方法可以[]在差异列表设置中使用.我已经谷歌了,但我找不到答案,Bratko(人工智能的Prolog编程)只是简单地触及了这个主题.
那么,是否可以在Prolog中将空列表作为差异列表编写,如果是这样,它将如何以及何时有用?
考虑以下代码片段,它定义了一个函数foo,该函数接受一个列表并对列表执行一些操作(如排序)。我尝试将片段加载到ghci:
-- a function which consumes lists and produces lists
foo :: Ord a => [a] -> [a]
foo [] = []
foo (x:xs) = xs
test1 = foo [1, 2, 3] == [2, 3]
test2 = null $ foo []
Run Code Online (Sandbox Code Playgroud)
但出现以下错误:
No instance for (Ord a0) arising from a use of ‘foo’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance (Ord a, Ord b) => Ord (Either a b)
-- …Run Code Online (Sandbox Code Playgroud) 我正在使用这个Lisp 编译器进行测试
有一件事情我不明白:如果一个空列表()评估自身:
(format t "~:a" ())
;; => ()
Run Code Online (Sandbox Code Playgroud)
为什么评估几个嵌套的空列表()不会评估为空列表?
(format t "~:a" (()))
;; => EVAL: undefined function NIL
;; why not () ?
(format t "~:a" ((())))
;; => EVAL: (NIL) is not a function name; try using a symbol instead
;; why not () ?
Run Code Online (Sandbox Code Playgroud)
从我的角度来看,()和NIL是相同的,所以内部空列表应该首先评估自身,然后外部列表应该“调用”新的内部评估空列表
我的头脑,我认为在进行计算时应该发生这样的情况:(粗体+斜体=当前评估的内容)
(()) => ( () ) => ( () ) => ()
似乎计划也不允许嵌套空列表调用
感谢您的阅读
我有一个列表列表,我想从中删除所有空列表.
我的名单是(("O") ("O") ()).
如果我做
(remove '() '(("O") ("O") ()))
Run Code Online (Sandbox Code Playgroud)
我得到了正确的输出 (("O") ("O"))
但是remove*(从文档中删除所有出现的)我得到相同的输入列表,即:
(remove* '() '(("O") ("O") ()))
Run Code Online (Sandbox Code Playgroud)
让我回来
(("O") ("O") ())
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我想使用sed命令清空文件.我搜索了很多论坛和教程.没有可删除文件的所有内容.如何使用sed命令删除文件的所有内容.
在Delphi XE7(我使用RAD Studio)中,我尝试调试包内的代码.我遇到了一个我无法解释的奇怪情况.例如,我有一个类似于下面的功能(注意我知道,这个功能没有任何智能,请不要纠正它,因为我不在现实世界中使用它.它只是一个虚拟函数来说明问题我面对.)
procedure TMyClass.DemoFunc();
var
pTest: TObjectList<TObject>;
pProperty: TObject;
begin
pTest := TObjectList<TObject>.Create;
for pProperty in pTest do
pProperty.ToString;
pTest.Free;
end;
Run Code Online (Sandbox Code Playgroud)
当我调试上面的代码时,我注意到调试器进入了该行
pProperty.ToString;
Run Code Online (Sandbox Code Playgroud)
如果我试着追踪上面的那一行,我会跳到
destructor TObject.Destroy;
Run Code Online (Sandbox Code Playgroud)
但是从我的观点来看,这是完全不合逻辑的,因为pTest显然是空的,所以不应该调用上面的行.
有人可以向我解释这种奇怪的行为吗?
注意我尝试调试的代码是在Delphi包中,但是该函数是从c ++项目调用的.
问候