Skip to main content

$LISTVALID (ObjectScript)

Determines if an expression is a list.

Synopsis

$LISTVALID(exp)
$LV(exp)

Argument

Argument Description
exp Any valid expression.

Description

$LISTVALID determines whether exp is a list, and returns a Boolean value: If exp is a list, $LISTVALID returns 1; if exp is not a list, $LISTVALID returns 0.

A list can be created using $LISTBUILD or $LISTFROMSTRING, or extracted from another list using $LIST. A list containing the empty string ("") as its sole element is a valid list. The empty string ("") by itself is also considered a valid list. (Certain $CHAR non-printing character combinations, such as $CHAR(1), $CHAR(2,1), and $CHAR(3,1,asciicode) can also return a valid empty or one-element list.)

Examples

The following examples all return 1, indicating a valid list:

   SET w = $LISTBUILD("Red","Blue","Green")
   SET x = $LISTBUILD("Red")
   SET y = $LISTBUILD(365)
   SET z = $LISTBUILD("")
   WRITE !,$LISTVALID(w)
   WRITE !,$LISTVALID(x)
   WRITE !,$LISTVALID(y)
   WRITE !,$LISTVALID(z)

The following examples all return 0. Numbers and strings (with the exception of the null string) are not valid lists:

   SET x = "Red"
   SET y = 44
   WRITE !,$LISTVALID(x)
   WRITE !,$LISTVALID(y)

The following examples all return 1. Concatenated, nested, and omitted value lists are all valid lists:

   SET w=$LISTBUILD("Apple","Pear")
   SET x=$LISTBUILD("Walnut","Pecan")
   SET y=$LISTBUILD("Apple","Pear",$LISTBUILD("Walnut","Pecan"))
   SET z=$LISTBUILD("Apple","Pear",,"Pecan")
   WRITE !,$LISTVALID(w_x) ; concatenated
   WRITE !,$LISTVALID(y)   ; nested
   WRITE !,$LISTVALID(z)   ; omitted element

The following examples all return 1. $LISTVALID considers all of the following “empty” lists as valid lists. $LISTBUILD can take an undefined variable as a list element without generating an error.

  WRITE $LISTVALID(""),!
  WRITE $LISTVALID($LB()),!
  WRITE $LISTVALID($LB(UndefinedVar)),!
  WRITE $LISTVALID($LB("")),!
  WRITE $LISTVALID($LB($CHAR(0))),!
  WRITE $LISTVALID($LB(,))

See Also

FeedbackOpens in a new tab