The following examples correctly appends to
List elements
and runtime results are maintained between the conversion between the Jacl
to Jython syntax:
JACL: lappend $x $y
JACL: lappend $x [list "aa" bb $cc]
JACL: lappend $x "aa" #automatically converted to list element
==>
JYTHON: x.append(y)
JYTHON: x.append(["aa", "bb", cc])
JYTHON: x.append("aa") #automatically converted to list element
The Jacl2Jython program detects and marks the incorrect use of
multiple parameters in the Jacl
lappend method during
the conversion. The Jython
append method supports only
a single parameter:
JACL: lappend $x $y extra
JACL: lappend $x "aa" bb extra
==>
JYTHON: x.append(y, "extra") #?PROBLEM? NUM_ARGS!=2
JYTHON: x.append("aa", "bb", "extra") #?PROBLEM? NUM_ARGS!=2?
Note: If your Jacl script is using the
+= operator
to append a
String to a
List,
although converted Jython is syntactically valid, it appends the list of
character strings to the end of the list. The following variations all work
as expected:
JYTHON: list += moreLists
JYTHON: list = list + string
JYTHON: list.append(string)
JYTHON: list += [string]
The following script which is syntactically correct, but behaves
incorrectly at Jython runtime:
JYTHON: list += string # INCORRECT. This statement appends a list of characters.
In
summary, scan your converted Jython script to check for all the
+= operator
used. If you intend to add a
String to a
List,
change the statement to
list += [string]