brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 109 forks source link

parsing issues #363

Closed shriram closed 6 years ago

shriram commented 9 years ago

This program doesn't parse:

f =
  lam(k):
    k((lam(shadow k):
          k(1)
        end)
      (lam(l-v):
          (lam(shadow k):
              k(2)
            end)
          (lam(r-v):
              k(l-v + r-v)
            end)
        end))
  end

I need to make clear to Pyret that I mean a function call:

f =
  lam(k):
    k((lam(shadow k):
          k(1)
        end)(lam(l-v):
          (lam(shadow k):
              k(2)
            end)
          (lam(r-v):
              k(l-v + r-v)
            end)
        end))
  end

But what I don' t understand is why I didn't need to do the same for the (lam (r-v) part.

blerner commented 9 years ago

Do you mean it doesn't parse at all, or it doesn't parse as you expect? I think the former will parse as two statements that each are parenthesized lambda expressions, while the latter (with no space before the paren where you think the application is happening) parses as a function application.

shriram commented 9 years ago

Well, simply trying it out would have confirmed that I meant what I said, which is that it doesn't parse at all:

Pyret didn't understand your program around definitions: line 6, column 6

where line 6, column 6 is the ( of (lam(l-v):.

jpolitz commented 9 years ago

This isn't a parsing bug so much as a criticism of Pyret's syntax, and motivation for a new well-formedness warning.

Both programs have this pattern:

(lam(x): ... end)
(lam(x): ... end)

In the first, it appears in the context of a function argument. That context can't have multiple expressions in a row, so it's a parsing error.

In the second, it appears in the context of a block, which can have multiple (newline-separated per the WF checker) expressions in a row.

A new warning could be "useless lambda expression on its own line, which means it will not be used".

blerner commented 9 years ago

Refining that: "useless lambda expression on its own line, and not the last expression of a block, which means it will not be used"

shriram commented 7 years ago

Now I get a block error. I can't even tell whether this is an improvement. (-:

jpolitz commented 7 years ago

Closing as effectively a duplicate of https://github.com/brownplt/pyret-lang/issues/383

schanzer commented 6 years ago

@jpolitz says he closed it in July...but it's still open?