Implement a find() macro

This macro looks at each cell along some stride through the sheet,
  returning the location of the first cell encountered at which a given
  expression evaluates to true, or boolean false otherwise.

  To make this more useful, this change also revamps the handling of
  boolean values, making them much more permissive and coercing to boolean type
  in fewer circumstances. It adds the bool() type conversion for explicitly
  coercing to boolean type, and fixes a small issue with reading hex-formatted
  floating-point values ('p' can be used as an exponent indicator).

  Closes #64.
This commit is contained in:
Glen Whitney 2019-08-28 12:40:50 -07:00
parent 6534aec2fd
commit 06938ec494
8 changed files with 318 additions and 100 deletions

View file

@ -4960,7 +4960,7 @@ and
\series default
\emph default
y evaluates to the logical conjunction of boolean values
y evaluates to the logical conjunction of values
\emph on
x
\emph default
@ -4979,6 +4979,32 @@ y
\emph default
is never evaluated, and so does not affect the value even if it is an error,
for example.
In determining the value, the boolean conversions of
\emph on
x
\emph default
and
\emph on
y
\emph default
are used (see the description of the bool() function below), but the actual
value returned is either that of
\emph on
x
\emph default
or
\emph on
y
\emph default
, namely,
\emph on
x
\emph default
if it corresponds to a boolean false value or
\emph on
y
\emph default
otherwise.
\end_layout
\begin_layout Description
@ -5024,6 +5050,15 @@ and
x
\emph default
is true.
Also in similar fashion, the value is
\emph on
x
\emph default
if it corresponds to a boolean true value and
\emph on
y
\emph default
otherwise.
\end_layout
\begin_layout Description
@ -6442,24 +6477,41 @@ or
\end_layout
\begin_layout Description
bool currently only acts as a keyword to
\series medium
bool
\begin_inset space ~
\end_inset
\series default
bool
\series medium
[([
\emph on
x
\emph default
])]
\series default
Converts
\emph on
x
\emph default
to a boolean value.
This is very permissive; error values are unaffected; empty, integer 0,
float 0.0, and boolean false values are false, and everything else is true.
If
\emph on
x
\emph default
is omitted, defaults to the value of the current cell.
If the parentheses are omitted as well, acts as a keyword, for example
for testing types with
\family sans
\series bold
is
\series default
();
\family default
there are not currently any conversions to boolean type.
Use e.g.
\family sans
\shape italic
expr
\shape default
!= 0
\family default
to obtain a boolean value from a numerical expression.
().
\end_layout
\begin_layout Description
@ -6755,6 +6807,69 @@ function identifier,
There is probably little practical call for this type.
\end_layout
\begin_layout Description
find
\series medium
(
\emph on
expr
\emph default
,
\emph on
\begin_inset space ~
\end_inset
\emph default
location
\emph on
\begin_inset space ~
\end_inset
stride
\emph default
[,location
\emph on
\begin_inset space ~
\end_inset
start
\emph default
]) examines cells in turn, returning the location of the first one at which
\series default
\emph on
expr
\emph default
evaluates to true, or boolean false if the boundary of the sheet is encountered.
The second argument
\emph on
stride
\emph default
must not have all zero components, and is added to the location being examined
at each iteration.
Often it is useful to use a direction constant like
\family sans
\series bold
up
\family default
\series default
for the stride.
The search begins at location
\emph on
start
\emph default
, which defaults to the current location plus the
\emph on
stride
\emph default
if it is not specified.
\end_layout
\begin_layout Description
\series medium