Using Print on Parsed strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Print on Parsed strings

Pulkit Agarwal
In most of the source code, for function calls, arguments are separated by a comma followed by a space character. But, the parsed output doesn't use that format:

julia> a = "show(io::IO, x::Prompt)"
"show(io::IO, x::Prompt)"

julia> parse(a)
:(show(io::IO,x::Prompt))

julia> print(parse(a))
show(io::IO,x::Prompt) # Notice the lack of a space character here

Is this due to an earlier style guide?
Reply | Threaded
Open this post in threaded view
|

Re: Using Print on Parsed strings

Jeffrey Sarnoff
More likely, the placing of that spacing comes from the recency of algorithmic parsing relative to longer evolutionary arc of eyesight.
In source code, it is good style to interpose a space after a comma to visually separate parameters that are separate entities -- then its easier to see the function's signature.

When source code is processed as a sequence of symbols through the act of parsing that symbol sequence, this parser is designed to treat
f(a, b) and f(a,b) and f(a,  b) identically (in this case by dropping any spaces that immediately follow a comma).

So asking print to show what the parser has parsed is asking print to show what remains after  f(a, b)  has been slightly simplified without altering meaning, into  f(a,b) .

julia> a = "show(io::IO, x::Prompt)"  # the space after the comma assists human visual processing
"show(io::IO, x::Prompt)"             # it is easy to see that x is name of the second parameter

julia> parse(a)                       # the parser scans the string to assist Julia's translational processing
:(show(io::IO,x::Prompt))             # the presence of a comma following a type name in a function signature
                                      # makes it easy to find and store the parameter name which is expected to follow

julia> print(parse(a)) # you ask Julia to collapse away that space character (parse(a))
show(io::IO,x::Prompt) # and that is why you notice the lack of a space character here


On Monday, March 21, 2016 at 9:27:29 AM UTC-4, Pulkit Agarwal wrote:
In most of the source code, for function calls, arguments are separated by a comma followed by a space character. But, the parsed output doesn't use that format:

julia> a = "show(io::IO, x::Prompt)"
"show(io::IO, x::Prompt)"

julia> parse(a)
:(show(io::IO,x::Prompt))

julia> print(parse(a))
show(io::IO,x::Prompt) # Notice the lack of a space character here

Is this due to an earlier style guide?