Nice TWiki > Doc > CodeExamples (r1.39) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
This section is a repository for code fragments and programs, for illustration purposes. Please create a specific page for each example. Its WikiWord should end with the word Example.

Examples for novices

HelloWorldNoviceExample: Setup, compile and run Hello World.

AckermannNoviceExample: Setup, compile and run Ackermann's function.

FiboNoviceExample: Setup, compile and run Fibonnaci function.

Download Language Shootout Examples 25 simple example programs (See The Great Win32 Computer Language Shootout )

Multimethod Examples

VisitorPatternMultiMethodExample: We'd like to reuse and extend software without modification. There are two aspects: adding a new datatype, usable with existing operations; and adding new operations for existing datatypes. This example follows the discussion in "Synthesizing Object-Oriented and Functional Design to Promote Reuse" from Functional and OO (Composite Pattern) approaches, to the Visitor Pattern and Extensible Visitor Pattern; with the addition of a straightforward implementation using multimethods and open classes.

BinaryMethodsMultiMethodExample: Multimethods provide a straightforward solution to the problem of binary methods.

FiniteStateMachineMultiMethodExample: A simple Finite State Machine encoded directly with multimethods.

BuilderPatternMultiMethodExample: For performance testing, the Runabout project generates various styles of test code - Visitor, Test Case, Multi Java, Runabout etc. In Java, this kind of generator code is often written using the BuilderPattern; in Nice, multimethods provide a straightforward solution.

Type Parameter Examples

NumberFiveTypeParameterExample?: Subtype constraints on type parameters < T | T <: double, int <: T >

GenericProgrammingIntermediateExample?: Generic implementations of graph algorithms from the Boost Graph Library - Breadth First Search, Dijkstra Shortest Paths, Prim's Minimum Spanning Tree, Bellman Ford Shortest Paths, Johnson All-Pairs Shortest Paths. Compare with C++, ML, Haskell, Eiffel, Java Generics, Generic C# implementations in "A Comparative Study of Language Support for Generic Programming".


MethcallIntermediateExample: Define a Java class JavaToggleExample and subclass it in Nice, compile Nice using classes in a Java jar, setup a Nice executable archive classpath to find a Java jar - compare with MethcallBeginnerExample.

MethcallIntermediateTwoExample: Define a Nice class NiceToggleExample and subclass it in Java - compare with MethcallBeginnerExample.


TreeVisitorIntermediateExample: Benchmark comparison between the Java Extensible Visitor pattern and modular extension in Nice. Simple generic binary tree TreeVisitorClassesIntermediateExample extended with a subclass representing n-ary trees, and with 3 different external methods.

DispatchIntermediateExample: Benchmark comparison between typecase and double-dispatch in Java, and multiple dispatch in Nice.

BenchIntermediateExample: Martin Richards systems language benchmark Bench, written in an ordinary OO style. PacketBenchExample declares enums, TcbBenchExample uses a class initializer, SchedulerBenchExample misuses enum.hashCode, TaskBenchExample declares an interface. "Benchmarking Java with the Richards benchmark" provides some background information.

Other examples

HelloSwingWorld : shows how to write (a little more complex :-) helloworld program.

SwingLibraryExample : shows how to write a GUI program using the Swing Library.

HaskellPreludeExample: Selected parts of the Haskell prelude, lots of functions which are useful when programming in functional style.

LazyVectorExample: A Vector subclass which computes its elements as they are they requested.

Topic CodeExamples . { Edit | Attach | Ref-By | Printable | Diffs | r1.57 | > | r1.56 | > | r1.55 | More }
Revision r1.39 - 07 Feb 2004 - 02:24 GMT - IsaacGouy
Parents: WebHome
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.