Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better printing and syntax for strange symbols #7188

Closed
StefanKarpinski opened this issue Jun 9, 2014 · 9 comments
Closed

better printing and syntax for strange symbols #7188

StefanKarpinski opened this issue Jun 9, 2014 · 9 comments
Milestone

Comments

@StefanKarpinski
Copy link
Sponsor Member

We do a lousy job of printing symbols that aren't valid identifiers:

julia> symbol("foo bar ")
:foo bar

This is relatively easy to fix by printing symbols that aren't valid identifiers like this:

julia> symbol("foo bar ")
symbol("foo bar ")

Speaking of which, do we have an easy function for checking if a symbol is a valid identifier? That's become and increasingly tricky thing to decide.

We could also support a better input/output syntax for weird symbols: :"foo bar ". Using this syntax is ok since there's no point in quoting a string literal like that – it has the same effect as just writing "foo bar " currently, so is effectively wasted syntax.

This issue was spawned by these conversations:

@StefanKarpinski StefanKarpinski changed the title better symbol printing and input syntax for strange symbols better printing and syntax for strange symbols Jun 9, 2014
@johnmyleswhite
Copy link
Member

My failed attempt at writing code to identify identifiers is here: https://github.com/JuliaStats/DataFrames.jl/blob/master/src/other/utils.jl#L17

@jakebolewski
Copy link
Member

All the code to do this should be part of the Lexer / Tokenizer in JuliaParser.jl.

@StefanKarpinski
Copy link
Sponsor Member Author

This is remarkably hard to even figure out how to change. The display code is such a tangled web these days; it really needs some serious cleaning.

@StefanKarpinski
Copy link
Sponsor Member Author

cc: @JeffBezanson, @johnmyleswhite

@JeffBezanson
Copy link
Sponsor Member

The lisp approach would be to make :"a" proper lexical syntax for a symbol, so that

   :"#" = 0

would actually initialize a variable called # in your program. However I'm not sure we want that. In particular, such symbols are hard to quote. You'd have to write :(:"#"), and I suspect most real uses of this would want quoted symbols.

Therefore I'd propose a custom string literal, s"#" or sym"#", short for symbol("#"). This has the advantage of not needing parser changes and not further overloading colon.

@JeffBezanson JeffBezanson added this to the 0.3 milestone Jul 3, 2014
@jakebolewski
Copy link
Member

I like the s"#" string literal syntax, seems nice and compact.

@StefanKarpinski
Copy link
Sponsor Member Author

I think I'd prefer sym"#" since this strikes me as rare in everyday usage, but I guess the brevity in printing ASTs might be good. But this issue is not really about having syntax for strange identifiers but for strange symbol literals. I.e. we don't need to be allowed to write :"foo bar" = 1 any more than we can write :foo = 1 – i.e. these should both result in "syntax: invalid assignment location".

@johnmyleswhite
Copy link
Member

I agree: I don't think one should allow crazy identifiers, just allow construction of symbols that are not valid identifiers.

vtjnash added a commit that referenced this issue Jul 7, 2014
@vtjnash vtjnash mentioned this issue Jul 7, 2014
@stevengj
Copy link
Member

stevengj commented Jul 7, 2014

In general, we need to export a number of things from the Scheme parser: a predicate for testing whether a string is a valid identifier, the list of binary operators and their precedence, and probably some other things.

That said, I'm extremely skeptical that this should block 0.3.

stevengj added a commit to stevengj/julia that referenced this issue Jul 7, 2014
StefanKarpinski added a commit that referenced this issue Jul 9, 2014
print invalid-identifier symbols as symbol("..."); fixes #7188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants