<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Some functionality of my script is conditional based on the contents of an array, so I need to determine the array length. The path described by the documentation leads to an exception. How should I determine array length? Or, a lesser requirement: how can I determine if an array is empty?<div><br></div><div>The user guide (<a href="http://www.ci.uchicago.edu/swift/guides/trunk/userguide/userguide.html">http://www.ci.uchicago.edu/swift/guides/trunk/userguide/userguide.html</a>) says:<div><br></div><div><meta charset="utf-8"><span style="color: rgb(0, 0, 0); font-family: Georgia, serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none; ">@length(array) will return the length of an array in Swift. This function will wait for all elements in the array to be written before returning the length.</span></div><div><span style="color: rgb(0, 0, 0); font-family: Georgia, serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none; "><br></span></div><div><span style="color: rgb(0, 0, 0); font-family: Georgia, serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none; ">But the following Swift script:</span></div><div style="text-align: left;"><font class="Apple-style-span" face="Georgia, serif"><br></font></div><div><span style="color: rgb(0, 0, 0); font-family: Georgia, serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none; "><div>type file;</div><div>file input_files[] <filesys_mapper; suffix=".log">;</div><div>trace( @length( input_files ) ) ;</div><div><br></div><div>Produces this output:</div><div><br></div><div><div>Swift 0.93 swift-r5483 cog-r3339</div><div><br></div><div>RunID: 20120802-1218-5dfj571d</div><div> (input): found 255 files</div><div>Progress: time: Thu, 02 Aug 2012 12:18:51 -0400</div><div>Execution failed:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>java.lang.ClassCastException: org.griphyn.vdl.mapping.RootArrayDataNode cannot be cast to java.util.Map</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.griphyn.vdl.karajan.lib.swiftscript.Misc.swiftscript_length(Misc.java:399)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.lang.reflect.Method.invoke(Method.java:597)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.functions.FunctionsCollection.function(FunctionsCollection.java:82)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.functions.AbstractFunction.post(AbstractFunction.java:27)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.AbstractSequentialWithArguments.completed(AbstractSequentialWithArguments.java:194)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.FlowNode.complete(FlowNode.java:214)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.FlowContainer.post(FlowContainer.java:58)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.functions.AbstractFunction.post(AbstractFunction.java:28)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.Sequential.startNext(Sequential.java:29)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.Sequential.executeChildren(Sequential.java:20)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.FlowContainer.execute(FlowContainer.java:63)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.FlowNode.restart(FlowNode.java:139)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.nodes.FlowNode.start(FlowNode.java:197)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.FlowElementWrapper.start(FlowElementWrapper.java:227)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.events.EventBus.start(EventBus.java:104)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at org.globus.cog.karajan.workflow.events.EventTargetPair.run(EventTargetPair.java:40)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.FutureTask.run(FutureTask.java:138)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at java.lang.Thread.run(Thread.java:619)</div></div><div><br></div></span></div></div></body></html>