NetRexx 3.07 BETA released - 2018/08/03

NetRexx moves - 2016-10-22

Examples

The most straightforward way to learn a programming language is, for
most people, to look at an example, modify it and see what
happens. For NetRexx, a large number of examples is shipped in the
distribution package. Here we list some of these, for easy browsing. A large
number of NetRexx examples is on the rosettacode.org
site; these are
also listed below.

Another corpus of example code is from the NetRexx Redbook. These
examples are all working.

Write a program that prints the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". FizzBuzz was presented as the lowest level of comprehension required to illustrate adequacy.

Show how to iterate over the key-value pairs of an associative array, and print each pair out. Also show how to iterate just over the keys, or the values, if there is a separate way to do that in your language.

You have 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.

In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. The purpose of this task is to create a basic class with a method, a constructor, an instance variable and how to instantiate it.

You have 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.

An O(n2) sorting algorithm which moves elements one at a time into the correct position. The algorithm consists of inserting one element at a time into the previously sorted part of the array, moving higher ranked elements up as necessary.

Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling. For quotient, indicate how it rounds (e.g. towards 0, towards negative infinity, etc.). For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.

You have 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.

A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers. Display an example of your output here.

The task is to create a function that strips a set of characters from a string. The function should take two arguments: the first argument being a string to stripped and the second, a string containing the set of characters to be stripped.

Output the system time (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance.

The task is to write a program where the program chooses a number between 1 and 10. A player is then prompted to enter a guess. If the player guess wrong then the prompt appears again until the guess is correct.

In this task, the goal is to show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element. (if available, show both fixed-length arrays and dynamic arrays, pushing a value into it.)

Original IBM Examples for NetRexx

Scribble.nrx: the 'Scribble' applet, using an Adapter class. This sample also shows the usage of the *implements* phrase in the *class* instruction, as well as the necessary *methods* doing the implementation.

This is a sample file input and output program, showing how to open, check, and process text files, and handle exceptions. Note the use of the Java Reader and Writer classes, which convert your local computer's 'code page' (character encoding) to Unicode during reading and back again during writing. The program *linecomment* does convert appropriate Netexx block-comments (indicated by '/*' and '*/') to NetRexx line comments (at the end of a line, indicated by a leading '--'!

This simple NetRexx program demonstrates that a simple output (saying 'Hello world!') does not require a lot of preceding declarations. Note that *say* is a so called NetRexx instruction, introduced by a verb (in this case *say*).

WordClock: an applet that shows the time in English. This example is functionally equivalent to the 'gtime' sample, but is implemented here as an applet, with the ability to define the font face and size as parameters.

Spectrum: A sample graphics stand-alone application for the Java platform. This draws a spectrum in a frame window on the screen, using an off-screen image to hold the current picture. The Java 1.1 event model is used to handle the windowClosing event.

Windows example for NetRexx

Examples for NetRexx 3.01

In NetRexx version 3.01, the 'LOOP over' variation of the 'LOOP' statement has been added. This loops over a Rexx Indexed String (formerly called a Rexx Stem), or any variation of an Array, Vector or a Collection, including Hashtables ,etc. This sample gives evidence.

Class RexxComparator is a Comparator that gives us the opportunity to use Rexx Strings in Collection classes without encountering exceptions when using Collections.sort(). It implements the compare method of the Comparator interface.

This sample shows how the NetRexx Interpreter (NetRexxA) may be used to interpret a NetRexx program or program part directly from a single string containing all program statements at once. This does allow other utilities to perform a very quick interpretation of the task in question.