File: functions.nice

package info (click to toggle)
nice 0.9.12-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,220 kB
  • ctags: 6,894
  • sloc: java: 42,767; xml: 3,508; lisp: 1,079; sh: 736; makefile: 673; cpp: 21; awk: 3
file content (52 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**************************************************************************/
/*                                N I C E                                 */
/*             A high-level object-oriented research language             */
/*                        (c) Daniel Bonniot 2000                         */
/*                                                                        */
/*  This program is free software; you can redistribute it and/or modify  */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation; either version 2 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/**************************************************************************/

package regtest.basic;

/**
   Tests toplevel functions.
*/

class FunctionClass
{
  int x;
  int getX() = this.x;
  void setX(int value) { this.x = value; }
}

// Function with an optional parameter
String optFun(String value, String end = ": ") = value + end;

// Function with a parametric type
<T> T identity(T x) = x;

// anonymous argument is ok 
// (it would also be acceptable for this to fail graciously)
int quarantedeux(int) = 42;

// overloading together with default args
void overloaded(int x) {}
void overloaded(String s, int y = 2) {}
void overloaded(boolean b) {}

void test_functions()
{
  println("### Testing functions");
  FunctionClass o = identity(new FunctionClass(x:1));
  o.setX(quarantedeux(1));
  println("x = " + o.getX());

  println(optFun("Functions") + optFun("a Nice feature", end:"!"));

  overloaded("Deuxieme");
}