DevTrends开发者趋势
主题色

产品

I implemented LINQ in my own programming language

I've been working on my own scripting language for my game engine, whose interpreter I wrote in C#. So, for quite a long time now, the only languages I use are C# and my custom language. Apparently, it's really…

DT生活与娱乐DT软件开发DT库 / SDKDTSkill / 插件

关于

I&#x27;ve been working on my own scripting language for my game engine, whose interpreter I wrote in C#. So, for quite a long time now, the only languages I use are C# and my custom language. Apparently, it&#x27;s really hard to work without LINQ after you got used to it, so I decided to add it to my language! [Note: I&#x27;m talking about in-memory queries, I didn&#x27;t re-implement the whole EF core...] Here&#x27;s a few examples: const dangerousEnemies = q(room.objects) .ofType(<obj_enemy>) .where(func(e) => distanceToObject(e) < 100) .groupBy(func(e) => e.specialPower) .toArr() foreach product in q(products) .orderBy(func(p) => p.price) .select(func(p) => p.name) { println(product) } func getFileExtension(filePath) { const i = q(filePath).reverse().indexOf(&#x27;.&#x27;) return filePath.substr(i, filePath.length() - i) } I did my best to make the design as close to .NET LINQ as possible. You can query anything that you can use in a foreach loop, and it uses deferred execution, meaning the query doesn&#x27;t actually run until you iterate over it or call .toArr(), .toList(), or one of the other methods that execute it. It also performs just one iteration per query. You can do where().select(), and instead of iterating once for the where operator and then again for the select operator, it processes both in a single iteration. This post links to the code of this little LINQ library, so you can check it if it sounds interesting to you. Would love to hear what u think about it!

收录记录

  1. Show HN

    2026年11月25日 · 1 次收录

讨论这个产品