May 19, 2005 Re: Value-based function overloading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthias Becker | In article <d6hopi$1geo$1@digitaldaemon.com>, Matthias Becker says... > >>>int positive (int[] array) { >>> int count (int[] a, int t) { >>> match (array) { >>> []: return t; // end of array >>> >>> e::next : // e = first element of a, next = array.ptr +1 >>> if (e > 0) count (next, t+1); >>> else count (next, t); >>> } >>> } >>> return count (array, 0); >>>} >>> >>> >> >> >>The match statement looks scary though :) > >:: would be an operator to create an array: >1 :: [5, 9, 42] would create the array [1, 5, 9, 42]. > >This operator would have a backward-mode to deconstruct an array into it's first array and the other elements. This is used in this match statement here. > > >In ML :: is a constructor to construct lists. Each constructor can be used to deconstruct an object. > > Yeah. Now it's all crystal clear. :) -Nod- |
Copyright © 1999-2021 by the D Language Foundation