Skip to content

Conversation

@toivoh
Copy link
Contributor

@toivoh toivoh commented Oct 27, 2012

Currently, symbols show without a colon:

julia> :x
x

This patch changes it to

julia> :x
:x

print still produces the raw name when you need it, and thus string does as well.

I think this change would improve clarity. I put an RFC in the title because I wasn't sure if there's a reason that this hasn't been implemented already. Thoughts?

Btw, I built this patch on top of #1458, since I thought that one would be less controversial. If there's interest for a patch only changes show for symbols, I could fix that easily.

@johnmyleswhite
Copy link
Member

I am also unaware of any problems this would cause, but, barring that, I think this change would make symbols more clear to newcomers. This style of showing is what Ruby does, for example.

@ghost ghost assigned JeffBezanson Oct 27, 2012
@StefanKarpinski
Copy link
Member

I've wanted this for a long time but @JeffBezanson had some objection, possibly the stringification business which t seems you've addressed here. So if he's cool with it, I'm all for. Thanks for doing this, btw.

@JeffBezanson
Copy link
Member

My objection is this:

julia> quote f(:x,:y) end
quote   #  line 1:
    :f(:x, :y)
end

julia> quote f(x,y) end
quote   #  line 1:
    :f(:x, :y)
end

The syntax for calling f on x and y prints the same as the syntax for calling f on the symbols :x and :y.

@toivoh
Copy link
Contributor Author

toivoh commented Oct 27, 2012

Is that a constructed julia output? Because with the code in this pull request I get

julia> quote f(:x,:y) end
quote   #  line 1:
    f(:x, :y)
end

julia> quote f(x,y) end
quote   #  line 1:
    f(x, y)
end

which seems pretty much ideal to me.

The reason that this works is that when passing an Expr to show, it will (already) put in appropriate quote markings
(like :( ... ) or turn begin ... end into quote ... end), and then invoke show_unquoted on the Expr. All printing of normal AST constructs will then be handled by recursive calls to show_unquoted. When it gets to the :x in f(:x, :y), on the other hand, that's represented with an expr(:quote, :x). show_unquoted shows the quote expr using the normal (quoted) entry point, and the quoted symbols print as quoted.

So, if it weren't for the distinction between show and show_unquoted, I would agree with you. I've really tried to be faithful to julia syntax in the AST printing code.

@JeffBezanson
Copy link
Member

Ah, I got that output by applying only the change to show(io, s::Symbol).

JeffBezanson added a commit that referenced this pull request Oct 27, 2012
@JeffBezanson JeffBezanson merged commit 1c14374 into JuliaLang:master Oct 27, 2012
jishnub pushed a commit that referenced this pull request Oct 19, 2025
)

Stdlib: LinearAlgebra
URL: https://github.com/JuliaLang/LinearAlgebra.jl.git
Stdlib branch: master
Julia branch: master
Old commit: d568106
New commit: 7e11b5e
Julia version: 1.13.0-DEV
LinearAlgebra version: 1.13.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/LinearAlgebra.jl@d568106...7e11b5e

```
$ git log --oneline d568106..7e11b5e
7e11b5e Add `AbstractArray` conversions for `AbstractQ` (#1470)
52c41f7 Add missing methods to `diagind` documentation (#1473)
28ee87e Overload array constructors for BunchKaufman (#1461) (#1466)
6f73f65 Add 'eigmin'/'eigmax' methods for 'Eigen' (#1468)
7b21cab Use `Iterators.rest` within `generic_norm` to simplify code (#1459)
57ac0eb Make `parentof_applytri` fully type-stable (#1243)
880a9fe Add `_sym_uplo` to skip validation (#1441)
8d6ca14 Public function to access the `uplo` for `Symmetric`/`Hermitian` (#1440)
7a4b27e Make `dot` with Bool-arrays type-stable (#1456)
6fe77f8 Make `dot` with Bool-arrays type-stable
5af75df Remove zeroing in `similar` for `Hermitian` (#1455)
5685390 Index into diag in `Tridigaonal` * `Diagonal` (#1454)
51923a5 Forward structure-preserving broadcasting to diag for `Diagonal` (#1423)
35a4427 Iterator norm in `isapprox` for `Array`s (#1378)
98723df Structured broadcasting for UpperHessenberg (#1325)
```

Co-authored-by: IanButterworth <1694067+IanButterworth@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

4 participants