Re: [sage-devel] Re: Preparsing madness...

2011-03-05 Thread Robert Bradshaw
On Sat, Mar 5, 2011 at 12:26 AM, Simon King wrote: > Hi Robert, > > On 4 Mrz., 22:18, Robert Bradshaw > wrote: >> ... >> See the PyUnicode_IsIdentifier function. > > ... which soon refers to two other functions (_PyUnicode_IsXidStart > and _PyUnicode_IsXidContinue) that test whether a character i

[sage-devel] Re: Preparsing madness...

2011-03-05 Thread Simon King
Hi Robert, On 4 Mrz., 22:18, Robert Bradshaw wrote: > ... > See the PyUnicode_IsIdentifier function. ... which soon refers to two other functions (_PyUnicode_IsXidStart and _PyUnicode_IsXidContinue) that test whether a character is acceptible at the beginning resp. in everything but the beginnin

Re: [sage-devel] Re: Preparsing madness...

2011-03-04 Thread Robert Bradshaw
On Fri, Mar 4, 2011 at 12:33 PM, Simon King wrote: > Hi Robert, > > On 4 Mrz., 19:39, Robert Bradshaw > wrote: >> > How to test whether something is a valid identifier in Python3? I >> > don't know. >> >> Fortunately, Python is open source :) I can't imagine it would be that >> hard to figure out

[sage-devel] Re: Preparsing madness...

2011-03-04 Thread Simon King
Hi Robert, On 4 Mrz., 19:39, Robert Bradshaw wrote: > > How to test whether something is a valid identifier in Python3? I > > don't know. > > Fortunately, Python is open source :) I can't imagine it would be that > hard to figure out. I know where to find the Sage sources (although I tend to for

Re: [sage-devel] Re: Preparsing madness...

2011-03-04 Thread Robert Bradshaw
On Fri, Mar 4, 2011 at 12:45 AM, Simon King wrote: > Hi Robert, > > On 4 Mrz., 09:30, Robert Bradshaw > wrote: >> So one would have to do >> >>     alpha=var("α", validate_name=False) >> >> to avoid an error? > > Yes, that was the idea. > >> Also, I'd still like to avoid >> >>     var("[]", ...)

[sage-devel] Re: Preparsing madness...

2011-03-04 Thread Simon King
Hi Robert, On 4 Mrz., 09:30, Robert Bradshaw wrote: > So one would have to do > >     alpha=var("α", validate_name=False) > > to avoid an error? Yes, that was the idea. > Also, I'd still like to avoid > >     var("[]", ...) > > working at all. We could accept all valid Python3 identifiers, and

Re: [sage-devel] Re: Preparsing madness...

2011-03-04 Thread Robert Bradshaw
2011/3/4 Simon King : > PS: > > On 4 Mrz., 09:06, Simon King wrote: >> What about the following idea: >>  1. var(s) only accept strings and lists of strings, and for backwards >> compatibility one could also make it accept objects whose string >> representation does not contain commas or whitespac

[sage-devel] Re: Preparsing madness...

2011-03-04 Thread Simon King
PS: On 4 Mrz., 09:06, Simon King wrote: > What about the following idea: >  1. var(s) only accept strings and lists of strings, and for backwards > compatibility one could also make it accept objects whose string > representation does not contain commas or whitespace. So, > var(QQ['t'].gen()) is

[sage-devel] Re: Preparsing madness...

2011-03-04 Thread Simon King
On 4 Mrz., 08:35, Jason Grout wrote: > But you could do this: > > sage: alpha=var("α") > sage: alpha > α Sure one could. But the point is that var is supposed to insert the variable into the global name space, under the given name. What about the following idea: 1. var(s) only accept strings an

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Jason Grout
On 3/4/11 12:52 AM, Simon King wrote: Hi Robert, On 3 Mrz., 22:48, Robert Bradshaw wrote: I think allowing letters like ç is just fine, what I'm opposed to is letting our definition of valid symbol names vary from platform to platform and local to local. So, a useful definition would be to re

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Simon King
Hi Robert, On 3 Mrz., 22:48, Robert Bradshaw wrote: > I think allowing letters like ç is just fine, what I'm opposed to is > letting our definition of valid symbol names vary from platform to > platform and local to local. So, a useful definition would be to restrict to ASCII identifiers (no uni

Re: [sage-devel] Re: Preparsing madness...

2011-03-03 Thread Robert Bradshaw
On Thu, Mar 3, 2011 at 1:23 PM, Simon King wrote: > Hi Robert, > > On 3 Mrz., 20:02, Robert Bradshaw > wrote: >> On Thu, Mar 3, 2011 at 2:52 AM, Simon King wrote: >> > Hi Burcin and all, >> >> > On 2 Mrz., 17:36, Burcin Erocal wrote: >> >> People might want to use utf-8 strings which won't be v

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Simon King
Hi Robert, On 3 Mrz., 20:02, Robert Bradshaw wrote: > On Thu, Mar 3, 2011 at 2:52 AM, Simon King wrote: > > Hi Burcin and all, > > > On 2 Mrz., 17:36, Burcin Erocal wrote: > >> People might want to use utf-8 strings which won't be valid under that > >> condition. See #7496: > > >>http://trac.sa

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread kcrisman
> > What is needed to do in order to "localize" a regular expression? > > -100 for valid identifiers/sage variable names to be a function of the > users locality. Yeah, that could make sharing worksheets and/or code really tough. -- To post to this group, send an email to sage-devel@googlegroup

Re: [sage-devel] Re: Preparsing madness...

2011-03-03 Thread Robert Bradshaw
On Thu, Mar 3, 2011 at 2:52 AM, Simon King wrote: > Hi Burcin and all, > > On 2 Mrz., 17:36, Burcin Erocal wrote: >> People might want to use utf-8 strings which won't be valid under that >> condition. See #7496: >> >> http://trac.sagemath.org/sage_trac/ticket/7496 > > I was reading in the Python

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Simon King
Hi Burcin and all, On 2 Mrz., 17:36, Burcin Erocal wrote: > People might want to use utf-8 strings which won't be valid under that > condition. See #7496: > > http://trac.sagemath.org/sage_trac/ticket/7496 I was reading in the Python docs of the re module that the meaning of \w depends on the lo

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Simon King
On 3 Mrz., 09:21, Simon King wrote: > If it would work, I think the test above should be implemented as a > function in sage.misc.defaults. In that way, it could also be used by > normalize_variable_names. I meant "used by sage.structure.parent_gens.normalize_names". -- To post to this group, s

[sage-devel] Re: Preparsing madness...

2011-03-03 Thread Simon King
Hi Nils and all, On 3 Mrz., 08:25, Nils Bruin wrote: > A possibly somewhat heavyhanded approach: > > sage: import tokenize,StringIO > sage: S="QQ['t'], a, a_2, for" > sage: list((a[0],a[1]) for a in > tokenize.generate_tokens(StringIO.StringIO(S).readline)) > [(1, 'QQ'), (51, '['), (3, "'t'"), (5

[sage-devel] Re: Preparsing madness...

2011-03-02 Thread Nils Bruin
On Mar 2, 10:36 pm, Simon King wrote: > Is there a standard Python function ("is_identifier" or so) that tests > whether a string in whatever encoding is an identifier? A possibly somewhat heavyhanded approach: sage: import tokenize,StringIO sage: S="QQ['t'], a, a_2, for" sage: list((a[0],a[1])

[sage-devel] Re: Preparsing madness...

2011-03-02 Thread Simon King
Hi Jason and Robert, On 3 Mrz., 00:36, Robert Bradshaw wrote: > ... > > How about just following the Python convention for identifiers, minus the > > keywords: > > >http://docs.python.org/reference/lexical_analysis.html#identifiers > > +1 +1 In fact this is what I meant when I wrote "alphanumer

Re: [sage-devel] Re: Preparsing madness...

2011-03-02 Thread Robert Bradshaw
On Wed, Mar 2, 2011 at 1:57 PM, Jason Grout wrote: > On 3/2/11 2:37 PM, Robert Bradshaw wrote: >> >> On Wed, Mar 2, 2011 at 10:03 AM, D. S. McNeil  wrote: > > For what reason is var(s) not raising an error if not s.isalnum()? People might want to use utf-8 strings which won't be

[sage-devel] Re: Preparsing madness...

2011-03-02 Thread Jason Grout
On 3/2/11 2:37 PM, Robert Bradshaw wrote: On Wed, Mar 2, 2011 at 10:03 AM, D. S. McNeil wrote: For what reason is var(s) not raising an error if not s.isalnum()? People might want to use utf-8 strings which won't be valid under that condition. Even "x_1" fails an alnum check. It would mak

Re: [sage-devel] Re: Preparsing madness...

2011-03-02 Thread Robert Bradshaw
On Wed, Mar 2, 2011 at 10:03 AM, D. S. McNeil wrote: >>> For what reason is var(s) not raising an error if not s.isalnum()? >> >> People might want to use utf-8 strings which won't be valid under that >> condition. > > Even "x_1" fails an alnum check. It would make sense to exclude some punctuati

Re: [sage-devel] Re: Preparsing madness...

2011-03-02 Thread D. S. McNeil
>> For what reason is var(s) not raising an error if not s.isalnum()? > > People might want to use utf-8 strings which won't be valid under that > condition. Even "x_1" fails an alnum check. Another issue with var is that Python allows trailing commas in the definitions of lists, sets, and tuples

Re: [sage-devel] Re: Preparsing madness...

2011-03-02 Thread Burcin Erocal
On Wed, 2 Mar 2011 06:09:30 -0800 (PST) Simon King wrote: > On 2 Mrz., 14:33, Florent Hivert wrote: > > Wouldn't be better to raise an error ? Note that I can also write: > > > >     sage: cos([]) = [] > > The preparser does > sage: preparse("parent([]) = []") > '__tmp__=var("[]"); parent =

[sage-devel] Re: Preparsing madness...

2011-03-02 Thread Simon King
Hi Florent, On 2 Mrz., 14:33, Florent Hivert wrote: > Wouldn't be better to raise an error ? Note that I can also write: > >     sage: cos([]) = [] The preparser does sage: preparse("parent([]) = []") '__tmp__=var("[]"); parent = symbolic_expression([]).function([])' I find it a bit strange