changeset 12313:82f27d725902 octave-forge

Deprecate class @dict in favour of structs. * inst/@dict/dict.m: issue warning about being deprecated and document alternative in the help text with example. * NEWS: mention depreciation of class dict.
author carandraug
date Mon, 13 Jan 2014 17:35:54 +0000
parents 47c84debfa11
children 42aa4b6b9662
files main/general/NEWS main/general/inst/@dict/dict.m
diffstat 2 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main/general/NEWS	Mon Jan 13 13:22:11 2014 +0000
+++ b/main/general/NEWS	Mon Jan 13 17:35:54 2014 +0000
@@ -1,3 +1,11 @@
+Summary of important user-visible changes for general 1.X.X:
+-------------------------------------------------------------------
+
+ ** The dict class has been deprecated in favour of structs which
+    now support arbitrary strings as valid fieldnames.  See the
+    help of @dict for an example.
+
+
 Summary of important user-visible changes for general 1.3.2:
 -------------------------------------------------------------------
 
--- a/main/general/inst/@dict/dict.m	Mon Jan 13 13:22:11 2014 +0000
+++ b/main/general/inst/@dict/dict.m	Mon Jan 13 17:35:54 2014 +0000
@@ -17,7 +17,25 @@
 ## @deftypefn{Function File} {d =} dict (@var{keys}, @var{values})
 ## @deftypefnx{Function File} {d =} dict ()
 ## @deftypefnx{Function File} {d =} dict (@var{str})
-## Creates a dictionary object with given keys and values. @var{keys}
+## Creates a dictionary object with given keys and values.
+##
+## The class @code{dict} has been deprecated in favour of using Octave
+## structs.  The advantage of dict over structs was that dict allowed any
+## string, not only valid Octave identifiers, as fieldnames.  This has
+## since change and any string is now a valid fieldname.
+##
+## @example
+## @group
+## s = struct ("7", "value7", "  ", "just spaces");
+## s.("7")
+##   @result{} "value 7"
+## s.("  ")
+## @result {} just spaces
+##   @result{} "just spaces"
+## @end group
+## @end example
+##
+## @var{keys}
 ## should be a cell array of strings; @var{values} should be a cell array
 ## with matching size. @var{values} can also be a singleton array, in
 ## which case it is expanded to the proper size; or omitted, in which case
@@ -66,6 +84,14 @@
 
 function d = dict (keys, values)
 
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             ["`dict' has been deprecated in favor of structs which in " ...
+              "Octave allows the use of arbitrary strings as fieldnames."]);
+  endif
+
   if (nargin == 0)
     keys = values = cell (0, 1);
   elseif (nargin == 1)