最大值是否有空值?
Is there a null value in maxima?
我有以下两个功能:
find(list, closure) := block(
filter: sublist(list, closure),
if length(filter) > 0 then filter[1] else null)$
find_index(list, closure) := block(
filter: sublist_indices(list, closure),
if length(filter) > 0 then filter[1] else null)$
在其他语言中,如果找不到要搜索的元素,我会在此处 return null
或 nil
。但是我认为maxima中不存在这个关键字。在这种情况下 return 的最大约定是什么?也许 false
?
false
确实是最常用的值来表示"not there"。这不是必需的,但有一个非常一致的约定。
请注意,如果 foo
的计算结果为 false
,则 if foo then bar
的计算结果为 false
。所以if foo then bar else false
等价于if foo then bar
,稍微短一点。
来自手册:
-- Constant: false
'false' represents the Boolean constant of the same name. Maxima
implements 'false' by the value 'NIL' in Lisp.
所以空结果的 lisp 等价物是 false
.
我有以下两个功能:
find(list, closure) := block(
filter: sublist(list, closure),
if length(filter) > 0 then filter[1] else null)$
find_index(list, closure) := block(
filter: sublist_indices(list, closure),
if length(filter) > 0 then filter[1] else null)$
在其他语言中,如果找不到要搜索的元素,我会在此处 return null
或 nil
。但是我认为maxima中不存在这个关键字。在这种情况下 return 的最大约定是什么?也许 false
?
false
确实是最常用的值来表示"not there"。这不是必需的,但有一个非常一致的约定。
请注意,如果 foo
的计算结果为 false
,则 if foo then bar
的计算结果为 false
。所以if foo then bar else false
等价于if foo then bar
,稍微短一点。
来自手册:
-- Constant: false
'false' represents the Boolean constant of the same name. Maxima implements 'false' by the value 'NIL' in Lisp.
所以空结果的 lisp 等价物是 false
.