Earlier quoted context omitted.
> There is also a secret option to get into a lisp repl in Julia "julia --lisp". Wtf....... what? I just tried it, it's true. Is this some easter egg?
Julia's parser is written in Scheme using femtolisp. Look for *.scm files and the 'flisp' directory in the repo[1]. [1] https://github.com/JuliaLang/julia/tree/master/src
Julia Macros for Beginners
11–20 of 36 posts
Re: Julia Macros for Beginners
#12Re: Julia Macros for Beginners
#13There are R meta programming techniques called non standard evaluation. It has many similarities to the macro system in Julia
While NSE enables the dplyr syntax that many people enjoy, for me it's too magic and I have trouble reasoning about variable names in other people's code.
Re: Julia Macros for Beginners
#14Re: Julia Macros for Beginners
#15There are R meta programming techniques called non standard evaluation. It has many similarities to the macro system in Julia
That's true. However, I believe that many R programmers don't know when non-standard evaluation happens or what it is exactly. Functions with or without it cannot be told apart just by looking at the syntax. While NSE enables the dplyr syntax that many people enjoy, for me it's too magic and I have trouble reasoning about variable names in other people's code.
Re: Julia Macros for Beginners
#16never understood why this was better/ how it was different from regular functions. just seems like bugs/vulns waiting to happen
Re: Julia Macros for Beginners
#17Earlier quoted context omitted.
That's true. However, I believe that many R programmers don't know when non-standard evaluation happens or what it is exactly. Functions with or without it cannot be told apart just by looking at the syntax. While NSE enables the dplyr syntax that many people enjoy, for me it's too magic and I have trouble reasoning about variable names in other people's code.
What does dplyr syntax look like?
df = tibble(a = c(1, 2))
and you want to use a dplyr verb to modify it mutate(df, b = a + 1)
the `a` in the above expression refers to the column in `df`, but this means it's hard to reference a variable in the outer scope named `a`. Furthermore, if you have a string referring to the column name `"a"`, you can't simply write mutate(df, b = a_var + 1)
Contrast this with DataFramesMeta.jl, which is a dply-like library for Julia, written with macros. df = DataFrame(a = [1, 2])
@transform df :b = :a .+ 1
Because of the use of Symbols, there is no ambiguity about scopes. To work with a variable referring to column `a` you can write a_str = "a"
@transform df :b = $a_str .+ 1
I won't pretend this isn't more complicated or harder to learn. Some of the complexity is due to Julia's high performance limiting non-standard evaluation in subtle ways. But a core strength of Julia's macros is that it's easy to inspect these expressions and understand exactly what's going on, with `@macroexpand` as shown in the blog post.DataFramesMeta.jl repo: https://github.com/JuliaData/DataFramesMeta.jl
Re: Julia Macros for Beginners
#18After that, I realized that macros aren't always something that needs to be avoided; in the right hands they're immensely powerful.
I've only played a little with Julia macros, but it seems like they learned a lot of Lisps lessons, so I support it wholly.
[1] I wasn't aware of how Objective C was built at the time.
Re: Julia Macros for Beginners
#19never understood why this was better/ how it was different from regular functions. just seems like bugs/vulns waiting to happen
However, it is useful to provide a nicer syntax and DSLs.
Some examples: https://stackoverflow.com/questions/58137512/why-use-macros-... https://www.juliafordatascience.com/animations-with-plots-jl... https://gist.github.com/MikeInnes/8299575
Re: Julia Macros for Beginners
#20never understood why this was better/ how it was different from regular functions. just seems like bugs/vulns waiting to happen
Consider how ergonomic testing is thanks to macros: https://docs.julialang.org/en/v1/stdlib/Test/
Here's an example of passing quasi-json to a plotting function: https://www.queryverse.org/VegaLite.jl/stable/userguide/vlpl... . This lets you essentially transliterate a VegaLite spec into Julia without needing to translate it into Julia.
Finally, macros that operator on dataframes let you write code that looks kind of like SQL, and is much more pleasant than working with functions: https://dataframes.juliadata.org/stable/man/querying_framewo...