3

I have the following two functions:

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)$

In other languages I would return null or nil here, if the element that is searched can't be found. But I think this keyword doesn't exist in maxima. What is the common convention in maxima for what to return in this case? Maybe false?

Kasper
  • 12,594
  • 12
  • 41
  • 63

2 Answers2

3

false is indeed the most commonly used value to represent "not there". It is not required, but there is a pretty consistent convention for it.

Note that if foo then bar evaluates to false if foo evaluates to false. Therefore if foo then bar else false is equivalent to if foo then bar, which is a little shorter.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
2

From the manual:

-- Constant: false

 'false' represents the Boolean constant of the same name.  Maxima
 implements 'false' by the value 'NIL' in Lisp.

So the lisp equivalent of an empty result is false.

Eelvex
  • 8,975
  • 26
  • 42