News and Updates for Synergy/DE Developers
SYNERGY-E-NEWS
News and Updates for Synergy/DE Developers

April 29, 2011

 
SPC 2011: See two Synergy/DE-based customer applications in action at the SPC in Chicago
Learn how two completely different companies are using the latest features in Synergy/DE to advance their applications.

At the SPC in Chicago next month, two companies will show how they are using today's Synergy/DE to enhance their applications and improve productivity. First, a Synergy developer from a one-man shop will demonstrate how he quickly got up to speed with Visual Studio 2010 and was able to breathe new life into an aging application. Next, you'll get an update from a large end user who previously demonstrated at an SPC how they updated their UI Toolkit application with a .NET interface. You'll see what they are doing now with their application, including how they are accessing it remotely using hand-held devices.

These are just two of the many informative technical sessions at the SPC. Visit the conference website for a complete agenda and to register.


Synergy/DE Tech Tip
Exceeding buffer size for command string argument in SPAWN routine

Question: How do you pass a large command to the SPAWN routine?

Quiz
Synergy/DE pros, see if you can answer this question!

At the end of the following code snippet, what is the value of r?

Spotlight on Synergy/DE 9.5: FOREACH with a twist
By Sudeep Sabnis, Synergy/DE Compiler Engineer

The FOREACH statement is a well-known modern programming construct that allows you to iterate sequentially over the elements in an array or collection. The advent of generics in Synergy .NET (released in Synergy/DE 9.5) adds icing to the cake, as the FOREACH statement in Synergy .NET can now be used to iterate over the elements in a generic collection.


Free code for Synergy/DE customers
Display a splash screen in a Synergy .NET Windows Presentation Foundation application… and more

The Synergy CodeExchange is a diverse collection of shared applications and examples, available for free to supported Synergy/DE developers. Need to send an SMTP e-mail message, create an XML file from Repository, or use the DLL API to retrieve file information? Check CodeExchange first, and you may be able to borrow code or learn from the examples to get a start.

Beginning today, every issue of Synergy-e-News will highlight at least one CodeExchange entry, to help you stay abreast of what's available for your use.


Platform News
Read a selection of recent articles from around the web
 


Spotlight on Synergy/DE 9.5: FOREACH with a twist
By Sudeep Sabnis, Synergy/DE Compiler Engineer

The FOREACH statement is a well-known modern programming construct that allows you to iterate sequentially over the elements in an array or collection. The advent of generics in Synergy .NET (released in Synergy/DE 9.5) adds icing to the cake, as the FOREACH statement in Synergy .NET can now be used to iterate over the elements in a generic collection. Consider the following example:

import System.Collections.Generic

main
record
    vals, @list	;list is a generic collection
    ivar, int
proc
    vals = new list()
    vals.Add(2)
    vals.Add(4)
    foreach ivar in vals	;Iterating over a generic collection
      Console.WriteLine(ivar)
end

I will be using the term “non-CLS” quite a bit in this article. In a nutshell, types that conform to the .NET Common Language Specification (CLS) are CLS compliant, and those that don’t are referred to as non-CLS types. CLS compliance is beyond the scope of this article, and I recommend that you browse through the MSDN pages on this topic if you are interested in more information. For the purpose of this article, just keep in mind that a structure containing Synergy types (a, d, d., etc.) is a non-CLS structure.

In the above example, the type of the ivar loop variable and the type of the element in the collection are both int. While other .NET languages, such as C# and VB, enforce type equality between the loop variable and the element in the collection in a FOREACH statement, Synergy relaxes this requirement (with a twist, to be explained shortly), primarily because of the way it treats alpha types and non-CLS structure types. A non-CLS structure field can be used wherever an alpha field is expected, and vice versa, in Synergy. In other words, from a Synergy programmer’s perspective, it is perfectly acceptable to use a loop variable of type alpha to iterate over elements of a non-CLS structure type in a collection (for example, an ArrayList).

We ensured that this functionality was available in Synergy .NET by introducing a novel feature to the FOREACH construct: the AS clause. Consider another example where a loop variable is of type alpha and the collection contains elements of a non-CLS structure type:

import System.Collections;

structure fred
    afld, a50, "Synergy .NET is so cool"
endstructure

main      
record
    alist, @ArrayList
    sfld, fred
    svar, fred
    avar, a50
proc
    alist = new ArrayList();
    alist.Add((object)sfld)
    sfld.afld = "I must try it out to see how cool it is"
    alist.Add((object)sfld)

    foreach svar in alist 
      Console.WriteLine(svar.afld)

    foreach avar in alist as @fred
      Console.WriteLine(avar)
end

In the above example, the first FOREACH loop is straightforward, because the loop variable and the elements in the ArrayList (after they are unboxed) are of the same type (in this case, “fred”). In the second FOREACH, however, we have a loop variable of type alpha, and the items added to the ArrayList are of the type structure fred. By specifying “as @fred”, we indicate that the elements in the ArrayList are either of that type or of a type that can be cast to the type indicated in the AS clause. Note that if the “as @fred” part is omitted, you will get a runtime exception as you execute the code. Also note that the AS clause is ignored in traditional Synergy.

A question that comes to mind is whether we then use the AS clause every time we use FOREACH in Synergy .NET. The answer is a resounding “No.” Doing so would generate compile-time errors. Recall that the AS clause is needed only when the type of the variable is different from the type of the items added to the collection. Moreover, note that FOREACH is only allowed on a collection that implements the IEnumerable or the generic IEnumerable<T> interface. The interface provides a method, GetEnumerator(), that returns the Enumerator (or Enumerator<T>) object, which in turn is used to iterate over the elements in the collection. In the case of a collection such as ArrayList, where the compiler is clueless about the type of the items added to the collection, the Enumerator returned by the GetEnumerator() call is an untyped one, whereas the one returned in the case of List<int> is a typed one. Using the AS clause with the FOREACH statement to iterate over a collection whose Enumerator is typed generates a compile-time error. For example:

import System.Collections.Generic

main
record
    vals, @list
    var, d10
proc
    vals = new list()
    vals.Add(2)
    vals.Add(4)
    foreach var in vals as @int
      Console.WriteLine(var)
end

The code above generates a NOTALLOWED error (“AS clause not allowed in FOREACH over a collection with typed enumerator”) during compilation.

So now you know how to use this novel feature of Synergy .NET, and you can apply this twist to your own code where necessary. When used appropriately, the AS clause helps tie up the loose ends when a loop variable in a FOREACH statement is one type, the elements in the collection are a different type, and a conversion exists between the types.

For more information about the AS clause, refer to FOREACH in the Synergy Language Reference Manual.

For more information about Synergy/DE 9.5, see our website.




Free code for Synergy/DE customers
Display a splash screen in a Synergy .NET Windows Presentation Foundation application… and more

The Synergy CodeExchange is a diverse collection of shared applications and examples, available for free to supported Synergy/DE developers. Need to send an SMTP e-mail message, create an XML file from Repository, or use the DLL API to retrieve file information? Check CodeExchange first, and you may be able to borrow code or learn from the examples to get a start. 

Beginning today, every issue of Synergy-e-News will highlight at least one CodeExchange entry, to help you stay abreast of what’s available for your use.

Splash screen for WPF (WpfSplashScreen.zip)
Download WpfSplashScreen.zip. Resource Center access required

One recent submission provides an example of how to display a splash screen in a Synergy .NET Windows Presentation Foundation application. Written by PSG consultant Steve Ives, WpfSplashScreen includes a Synergy .NET class library containing utility classes for use in a WPF application, as well as the WPF application itself, which displays a splash screen while performing simulated startup processing. Even if you’re an experienced .NET developer, this code sample will save you lots of time, and if you’re new to .NET, it just might be invaluable.

Let others see some of your cool code. Don’t forget to submit your own CodeExchange entries.  



Synergy/DE Tech Tip
Exceeding buffer size for command string argument in SPAWN routine

Question:

How do you pass a large command to the SPAWN routine?

Answer:

The buffer size when passing the command string argument XCALL SPAWN is limited to 1024 characters (or 256 on OpenVMS). Anything beyond that will be ignored and not passed, as the command will be truncated. This is a limitation of the runtime and helps to avoid memory overwrite issues.

If you need to pass a large command to the SPAWN routine, you should put it in a script, batch file, or DCL command file and invoke that with SPAWN to work around this limitation.



Quiz
Synergy/DE pros, see if you can answer this question!

At the end of the following code snippet, what is the value of r?

record rec
	r	,i4
	n	,@i
proc
	n = 1
	init rec
	r = 2 + (i)n

a. 3
b. 2
c.  This does not compile
d. A runtime error results