Please explain this unexpected syntax

I have encountered some TCL code (well, Jacl code really), that has the statements shown below.

I understand that #1 creates a new java Object, having a value of 1.  So far, so good.

What I don't understand is the 2nd statement.  I'm used to seeing

set variableName value

So what is this doing?

set 0 value

and why is this after a dereferenced variable?

If you could explain this, and provide equivalent Jython, it would be greatly appreciated.

Thanks
set params [java::new {java.lang.Object[]} {1}]
$params set 0 [java::field com.ibm.websphere.scheduler.BeanTaskInfo class]

Open in new window

LVL 41
HonorGodSoftware EngineerAsked:
Who is Participating?
 
mish33Connect With a Mentor Commented:
It'a special JACL syntax to manipulate Java arrays:

From http://tcljava.sourceforge.net/docs/TclJava/JavaNewCmd.html:

In this example, we see how to allocate an array of java.lang.String objects. This example also demonstrates Java array object commands and their equivalent Java statements, see the javaArrayObj section for more information.
# This is equivalent to the Java statement.
# String[] arr = new String[2];
set arr [java::new {String[]} {2}]

# Set the values of the array elements.
# This is equivalent to the following Java statements.
# arr[0] = "Hello";
# arr[1] = "World";
$arr set 0 "Hello"
$arr set 1 "World"
0
 
HonorGodSoftware EngineerAuthor Commented:
Here's the "equivalent" Jython code...


import com.ibm.websphere.scheduler as sch
 
params = [ sch.BeanTaskInfo ];    # class reference
sigs   = [ 'java.lang.Class' ];   # "Signature" identifying "params" type

Open in new window

0
 
objectsConnect With a Mentor Commented:
its setting an element in the array isn't it

0
 
HonorGodSoftware EngineerAuthor Commented:
According to the Tcl documentation, one would use the "array" keyword to define an array.

So, I'm still confused.
array set colorcount {
    red   1
    green 5
    blue  4
    white 9
}

Open in new window

0
 
HonorGodSoftware EngineerAuthor Commented:
mish33 was completely correct, so gets most of the points.
objects was first, and partially correct, so get some of the points.

Thanks again folks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.