VECTOR: Support creating string variables also.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 14 Aug 2016 16:28:23 +0000 (09:28 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 14 Aug 2016 16:28:23 +0000 (09:28 -0700)
Bug #48763.

NEWS
doc/variables.texi
src/language/dictionary/vector.c
tests/language/dictionary/vector.at

diff --git a/NEWS b/NEWS
index 883590541ee61c5a4af4af84d6865a5b95053409..8959f7ec5d545561a426e1a7b33458bfca14bf30 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,9 +6,11 @@ Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
 
 Changes from 0.10.2 to 0.10.4:
 
- *  Gtk+3.14.5 or later must now be used when building.
+ * Gtk+3.14.5 or later must now be used when building.
 
- *  The AUTORECODE command now accepts an optional / before INTO.
+ * The AUTORECODE command now accepts an optional / before INTO.
+
+ * The short form of the VECTOR command can now create string variables.
 
 Changes from 0.10.1 to 0.10.2:
 
index 6a6a77b7febc94186b219b338eddbad7bebf48cc..cc13e784de2e9732d028b4fa03077e2f75096aad 100644 (file)
@@ -782,18 +782,20 @@ were consecutive members of an array with a vector(index) notation.
 
 To make a vector out of a set of existing variables, specify a name
 for the vector followed by an equals sign (@samp{=}) and the variables
-to put in the vector.  All the variables in the vector must be the same
-type.  String variables in a vector must all have the same width.
+to put in the vector.  The variables must be all numeric or all
+string, and string variables must have the same width.
 
 To make a vector and create variables at the same time, specify one or
-more vector names followed by a count in parentheses.  This will cause
-variables named @code{@var{vec}1} through @code{@var{vec}@var{count}}
-to be created as numeric variables.  By default, the new variables
-have print and write format F8.2, but an alternate format may be
-specified inside the parentheses before or after the count and
-separated from it by white space or a comma.  Variable names including
-numeric suffixes may not exceed 64 characters in length, and none of
-the variables may exist prior to @cmd{VECTOR}.
+more vector names followed by a count in parentheses.  This will
+create variables named @code{@var{vec}1} through
+@code{@var{vec}@var{count}}.  By default, the new variables are
+numeric with format F8.2, but an alternate format may be specified
+inside the parentheses before or after the count and separated from it
+by white space or a comma.  With a string format such as A8, the
+variables will be string variables; with a numeric format, they will
+be numeric.  Variable names including the suffixes may not exceed 64
+characters in length, and none of the variables may exist prior to
+@cmd{VECTOR}.
 
 Vectors created with @cmd{VECTOR} disappear after any procedure or
 procedure-like command is executed.  The variables contained in the
index 512ec3c2bfeaf99cde80aae28644b08f55225b1a..6560288c472e1232aed890d6d3e8dde7c4540998 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2010, 2011, 2012, 2016 Free Software Foundation, Inc.
 
    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
@@ -136,8 +136,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds)
                 {
                   seen_format = true;
                   if (!parse_format_specifier (lexer, &format)
-                      || !fmt_check_output (&format)
-                      || !fmt_check_type_compat (&format, VAL_NUMERIC))
+                      || !fmt_check_output (&format))
                     goto fail;
                 }
               else
@@ -184,7 +183,8 @@ cmd_vector (struct lexer *lexer, struct dataset *ds)
              for (j = 0; j < var_cnt; j++)
                {
                   char *name = xasprintf ("%s%d", vectors[i], j + 1);
-                 vars[j] = dict_create_var_assert (dict, name, 0);
+                 vars[j] = dict_create_var_assert (dict, name,
+                                                    fmt_var_width (&format));
                   var_set_both_formats (vars[j], &format);
                   free (name);
                }
index e7a2cdd101c7ae7b861595b456235d01fca9c8cd..36aed7a6cba953786ab48ba6928d8e8726655f0e 100644 (file)
@@ -19,7 +19,8 @@ AT_CLEANUP
 AT_SETUP([VECTOR short form with format specification])
 AT_DATA([vector.sps], [dnl
 data list notable/x 1.
-vector #vec(4, comma10.2).
+vector #vec(4, comma10.2)
+      /#svec(3, a8).
 display vector.
 ])
 AT_CHECK([pspp -o pspp.csv vector.sps])
@@ -29,6 +30,9 @@ Vector,Position,Variable,Print Format
 ,2,#vec2,COMMA10.2
 ,3,#vec3,COMMA10.2
 ,4,#vec4,COMMA10.2
+#svec,1,#svec1,A8
+,2,#svec2,A8
+,3,#svec3,A8
 ])
 AT_CLEANUP