# HG changeset patch
# User Volker Braun <vbraun@stp.dias.ie>
# Date 1325529323 0
# Node ID 7e65391cb752cc9e4cc28f7c5f65b831583f63c5
# Parent  92c93226b64f933e0af00bbcbd1a8a79c444f43f
Trac #12247: Make var(['x','y']) work

diff --git a/sage/calculus/var.pyx b/sage/calculus/var.pyx
--- a/sage/calculus/var.pyx
+++ b/sage/calculus/var.pyx
@@ -1,14 +1,19 @@
 from sage.symbolic.function_factory import function as new_function
 from sage.symbolic.ring import SR
 
-def var(s, **kwds):
+def var(*args, **kwds):
     r"""
     Create a symbolic variable with the name *s*.
 
     INPUT:
 
-    - ``s`` - a string, either a single variable name, or a space or
-      comma separated list of variable names.
+    - ``args`` - A single string ``var('x y')``, a list of strings
+      ``var(['x','y'])``, or multiple strings ``var('x', 'y')``. A
+      single string can be either a single variable name, or a space
+      or comma separated list of variable names. In a list or tuple of
+      strings, each entry is one variable. If multiple arguments are
+      specified, each argument is taken to be one variable. Spaces
+      before or after variable names are ignored.
 
     - ``kwds`` - keyword arguments can be given to specify domain and
       custom latex_name for variables. See EXAMPLES for usage.
@@ -18,9 +23,30 @@
        The new variable is both returned and automatically injected
        into the global namespace. If you need symbolic variable in
        library code, it is better to use either SR.var() or SR.symbol().
+       
+    OUTPUT:
+
+    If a single symbolic variable was created, the variable
+    itself. Otherwise, a tuple of symbolic variables. The variable
+    names are checked to be valid Python identifiers and a
+    ``ValueError`` is raised otherwise.
 
     EXAMPLES:
     
+    Here are the different ways to define tree variables ``x``, ``y``,
+    and ``z`` in a single line::
+
+        sage: var('x y z')
+        (x, y, z)
+        sage: var('x, y, z')
+        (x, y, z)
+        sage: var(['x', 'y', 'z'])
+        (x, y, z)
+        sage: var('x', 'y', 'z')
+        (x, y, z)
+        sage: var('x'), var('y'), var(z)
+        (x, y, z)
+
     We define some symbolic variables::
     
         sage: var('n xx yy zz')
@@ -97,6 +123,10 @@
         doctest:...: DeprecationWarning: The new (Pynac) symbolics are now the only symbolics; please do not use keyword 'ns' any longer.
         q
     """
+    if len(args)==1:
+        name = args[0]
+    else:
+        name = args
     G = globals()  # this is the reason the code must be in Cython.
     if kwds.has_key('ns'):
         if kwds['ns']:
@@ -105,7 +135,7 @@
         else:
             raise NotImplementedError, "The new (Pynac) symbolics are now the only symbolics; please do not use keyword `ns` any longer."
         kwds.pop('ns')
-    v = SR.var(s, **kwds)
+    v = SR.var(name, **kwds)
     if isinstance(v, tuple):
         for x in v:
             G[repr(x)] = x
diff --git a/sage/symbolic/ring.pyx b/sage/symbolic/ring.pyx
--- a/sage/symbolic/ring.pyx
+++ b/sage/symbolic/ring.pyx
@@ -542,13 +542,22 @@
             Traceback (most recent call last):
             ...
             ValueError: You need to specify the name of the new variable.
+           
+            var(['x', 'y ', ' z '])
+            (x, y, z)
+            var(['x,y'])
+            Traceback (most recent call last):
+            ...
+            ValueError: The name "x,y" is not a valid Python identifier.
         """
         if is_Expression(name):
             return name
-        if not isinstance(name, str):
+        if not isinstance(name, (basestring,list,tuple)):
             name = repr(name)
 
-        if ',' in name:
+        if isinstance(name, (list,tuple)):
+            names_list = [s.strip() for s in name]
+        elif ',' in name:
             names_list = [s.strip() for s in name.split(',' )]
         elif ' ' in name:
             names_list = [s.strip() for s in name.split()]
