Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
343 stars 230 forks source link

location of ideal(String) #1485

Closed mahrud closed 4 years ago

mahrud commented 4 years ago

ideal(String) is defined in Classic.m2, but:

i25 : locate (ideal, String)

o25 = (../../Macaulay2/packages/Parsing.m2, 41, 34, 51, 5, 42, 12)

Strangely, this is not the case for matrix(String), perhaps because that one takes options?

mahrud commented 4 years ago

Speaking of Classic.m2, the code for it is messy and kind of hard to parse. If the point of its main documentation point is to demonstrate its simplicity, it could use a reorganization.

DanGrayson commented 4 years ago

That location is correct, because this code has no function body:

ideal String := Ideal => ideal % listPolyP : nonspaceAnalyzer

Rather, it uses the Parsing package to make a parser.

I like the code in Classic the way it is: it's super simple and not messy at all.

mahrud commented 4 years ago

Isn't ideal % listPolyP : nonspaceAnalyzer a function?

I'm not suggesting changing the code, just putting some extra tabs and new lines maybe, or adding inline comments perhaps.

DanGrayson commented 4 years ago

Isn't ideal % listPolyP : nonspaceAnalyzer a function?

No, it's code that creates a function. The location of the function will be the location of the function body in the source code of Parsing.

I'm not suggesting changing the code, just putting some extra tabs and new lines maybe, or adding inline comments perhaps.

I'm super proud of the small size.

mahrud commented 4 years ago

No, it's code that creates a function. The location of the function will be the location of the function body in the source code of Parsing.

And my point is that this makes it almost impossible to understand what ideal(String) does. Can you make sense of this?

i1 : code (ideal, String)

o1 = -- code for method: ideal(String)
     ../../Macaulay2/packages/Parsing.m2:41:35-51:6: --source code:
     Parser : Analyzer := (p0,a0) -> s -> (
          p := p0;
          a := a0 s;
          while null =!= (k := a())
          do (
               (pos,t) := k;
               if t === null then error("unrecognized lexical item at position ", toString pos) 
               else if null === (p = p t) then error("syntax error at token '",toString t,"', position ",toString pos)
               );
          if null === (r := p null) then error "parser unfinished, at end of input";
          r)
     | symbol   class       value            location of symbol
     | ------   -----       -----            ------------------                             
     | a0     : Analyzer -- nonspaceAnalyzer ../../Macaulay2/packages/Parsing.m2:41:26-41:28
     | p0     : Parser   -- ...              ../../Macaulay2/packages/Parsing.m2:41:23-41:25

There's no reference whatsoever to Classic.m2. How would one know the value of p0 and a0 here?

mahrud commented 4 years ago

I'm super proud of the small size.

Okay. I'm just making an observation that it's short but nearly incomprehensible.

DanGrayson commented 4 years ago

No, it's code that creates a function. The location of the function will be the location of the function body in the source code of Parsing.

And my point is that this makes it almost impossible to understand what ideal(String) does. Can you make sense of this?

i1 : code (ideal, String)

o1 = -- code for method: ideal(String)
     ../../Macaulay2/packages/Parsing.m2:41:35-51:6: --source code:
     Parser : Analyzer := (p0,a0) -> s -> (
          p := p0;
          a := a0 s;
          while null =!= (k := a())
          do (
               (pos,t) := k;
               if t === null then error("unrecognized lexical item at position ", toString pos) 
               else if null === (p = p t) then error("syntax error at token '",toString t,"', position ",toString pos)
               );
          if null === (r := p null) then error "parser unfinished, at end of input";
          r)
     | symbol   class       value            location of symbol
     | ------   -----       -----            ------------------                             
     | a0     : Analyzer -- nonspaceAnalyzer ../../Macaulay2/packages/Parsing.m2:41:26-41:28
     | p0     : Parser   -- ...              ../../Macaulay2/packages/Parsing.m2:41:23-41:25

There's no reference whatsoever to Classic.m2. How would one know the value of p0 and a0 here?

Okay, that's a good point. I'll fix it.

DanGrayson commented 4 years ago

Fixed in commit 40623278b2c266466fa2b845ab3a642b548e478c

mahrud commented 4 years ago

It's also more readable now. Thank you!