AST from Julia source code?

While browsing the devdocs for ast, the first table shows a transformation from f(x) to (call f x).

Was there a function in Julia that performs this transformation, or was the documentation merely showing how an AST might be represented as such?

From the paragraph above the table

For example (call f x) corresponds to Expr(:call, :f, :x) in Julia.

You can use Meta.parse to convert a string to an Expr.

Ok, but there is no way to turn Julia into S-expressions then?

I don’t know of any builtin function in Base that does this.
But it should not be too difficult to cook up one, given that Expr contains all relevant data already.
IIUC then Expr is just a different representation/just differently printed than a s-expression.

I don’t really understand the distinction that you’re trying to draw. Expr is an s-expression representation. Are you just looking for printing that doesn’t explicitly print out Expr? In that case

julia> Meta.show_sexpr(Meta.parse("f(x)"))
(:call, :f, :x)
4 Likes

Thanks!