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.

set params [java::new {java.lang.Object[]} {1}]
$params set 0 [java::field 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:


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"
HonorGodSoftware EngineerAuthor Commented:
Here's the "equivalent" Jython code...

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

Open in new window

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

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

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!
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.