Skip to content

Upcoming language and library changes in the Clay in Clay implementation

jckarter edited this page Dec 24, 2010 · 8 revisions

This is a list of language changes very likely to be implemented in the next iteration of the Clay compiler:

Unification of identifiers and static string constants; new static value syntax

Identifiers will become equivalent to static StringConstant values. The # operator will be promoted to a general static value operator, replacing the static keyword in that role:

  // Old clay
  foo(#bar, static 17, static (a + b))
  // New clay
  foo(#"bar", #17, #(a + b))

Implicit pattern variables and new pattern syntax

Taking a cue from OCaml, pattern variables will be implicitly introduced by 'T syntax, instead of needing to be declared in a pattern constraint:

  // Current clay
  [T] size(v: Vector[T]) = v.size;
  // New clay
  size(v: Vector['T]) = v.size;

Pattern constraints also have a more streamlined syntax, appearing after a | just before the function body:

  // Current clay
  [S | Sequence?(S) and Number?(SequenceElementType(S))]
  sum(s: S) = reduce(add, 0, s);
  // New clay
  sum(s: 'S) | Sequence?('S) and Number?(SequenceElementType('S))
      = reduce(add, 0, s);

Const arguments

Arguments will be immutable by default:

  // Old clay
  foo(x, y) {
      x += y; // mutates x in current clay, an error in new clay
  }

Mutable references must be explicitly declared ref (for lvalues) or rvalue (for temporaries):

  // New clay
  foo(ref x, y) {
      x += y;
  }

  overload foo(ref x, rvalue y) {
      x += move(y);
  }

Functions can also return const references:

  // New clay
  index(x: Array['T], n: 'I) | Integer?('I) = const (begin(x) + n)^;
  index(ref x: Array['T], n: 'I) | Integer?('I) = ref (begin(x) + n)^;

The forward keyword now forwards any of the three reference kinds (const, ref, or rvalue), so the two definitions above can be folded into one:

  // New clay
  index(forward x: Pointer['T], n: 'I) = forward (x + n)^;

Const reference binding

const references will also be bindable to a local variable:

  // New clay
  const x = xs[0];

Variable binding expressions

var, ref, and const bindings will be bindable in an expression context using the in keyword:

  // New clay
  distance(x, y) = var x2, y2 = x*x, y*y in sqrt(x2 + y2);

New by-reference lambda syntax

The ref=> syntax for constructing reference-capturing lambdas will be replaced with ->:

  // Old clay
  var y = 0;
  return map(x ref=> { y += x; return x+1; }, [1, 2, 3]);
  // New clay
  var y = 0;
  return map(x -> { y += x; return x+1; }, [1, 2, 3]);

=> will remain as copy-capturing lambda syntax.

Clone this wiki locally