News for hackers. Stuff that matters.
Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by lostmsu on Thursday April 09, 2020 @03:31PM (#22826284)
In C# since 2007. Feature is called LINQ expressions.

Not sure fully grokked it, but the difference appears to be, that in Julia the final Julia code is checked by the compiler at compile time?

Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by ddragon on Thursday April 09, 2020 @03:49PM (#22826442)
It's not really the same. Non-standard string literals in Julia are an adaptation of Common Lisp reader macros (which is much older than LINQ), which is a type of macro that allows to fully ignore the parser of the language for parts of the code (allowing you to create other parsers and therefore you're able to embed completely new languages). For example Julia allows to write sections in R [1] or C++ [2] using this technique. There are LINQ inspired libraries in Julia as well [3], but they are usually based on normal macros and use the standard Julia parser (just like LINQ is directly supported by the C# parser). Both types of macro execute entirely at compile time ultimately converting to normal Julia code at runtime.

[1] https://juliainterop.github.io/RCall.jl/stable/gettingstarte...

[2] https://github.com/JuliaInterop/Cxx.jl

[3] https://www.queryverse.org/Query.jl/stable/linqquerycommands...

Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by uryga on Thursday April 09, 2020 @03:40PM (#22826372)
sorry but did we read the same article? how's compiling brainfuck into Julia via macros related to LINQ?
Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by lostmsu on Thursday April 09, 2020 @06:41PM (#22827955)

  Expression BrainFuck(string code) => Expression.Constant(42); // parser would go there
  var bfFunc = BrainFuck(@"arbritrary code").Compile();
  WriteLine(bfFunc(someArg)); // <- prints 42
As I mentioned later the difference appears to be that Julia does `Compile` call at compile time, thus giving you build-time validation.

P.S. this exact code won't work, but it shows the idea.

Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by uryga on Friday April 10, 2020 @08:36AM (#22832392)
ah sorry, the naming threw me off. TIL you can manipulate/compile ASTs in C#! https://docs.microsoft.com/en-us/dotnet/api/system.linq.expr...

i guess all the macro stuff is under System.Linq.Expressions because LINQ expressions like

  from score in scores
  where score > 80
  select score
aren't just for SQL and can desugar to arbitrary C# code, is that right?
Re:Six Months with Julia: Parse-Time Transpilation in 80 Lin... by lostmsu on Friday April 10, 2020 @10:18AM (#22833254)
I think they are limited quite a bit. E.g. do not support classes, latest C# features, etc.

They were made exactly for SQL among other things. With SQL target your example will use this feature: scores will be IQueryable, and "IQueryable.Where" will take Expression, which C# compiler will generate from "score > 80" during compilation. Then the specific database engine will convert that "Expression" instance to SQL query for execution.

Of course, there are other ways to generate more .NET code at runtime. But not at compile time, which I wish we had.