TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Cakelisp: A Programming Language for Games

178 pointsby makutoover 4 years ago

16 comments

makutoover 4 years ago
See also on &#x2F;r&#x2F;gamedev [0].<p>After years of dealing with points of frustration in C++ land, I&#x27;ve created my own programming language. It emphasizes compile-time code generation, seamless C&#x2F;C++ interoperability, and easier 3rd-party dependency integration. It&#x27;s like &quot;C in S-expressions&quot;, but offers much more than just that.<p>I had a hard time trimming this article down because of how excited I am about the language. Feel free to skim and read more in the sections that pique your interest.<p>I don&#x27;t expect everyone to love it and adopt it. I do hope that some of the ideas are interesting to fellow programmers. I found it eye-opening to realize how much better my development environment could become once I opened this door.<p>[0] <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;gamedev&#x2F;comments&#x2F;kh1p0a&#x2F;cakelisp_a_programming_language_for_games&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;gamedev&#x2F;comments&#x2F;kh1p0a&#x2F;cakelisp_a_...</a>
tinesover 4 years ago
Nice! I&#x27;ve always been a proponent of thinking about C++ as &quot;C with templates&quot; rather than &quot;C with classes,&quot; and once you realize that templates are just AST expanders, it becomes apparent that C++ is just a bad lisp :)<p>I made the same thing a while back, and one of the neat simple things you can do is implement function-overloading a la C++. All you need is to define a way to serialize types to strings that are valid identifiers; then you (1) append the string-forms of the types of each function parameter to the name of the function at the definition site, along with a normal function that will do the dispatching in the second part, and (2) do the same thing for the type of the arguments at each call site. Et voila! Function overloading! Not quite as powerful as C++, which takes conversions and stuff into account, but it&#x27;s an interesting experiment nonetheless. You can see how I did it here: <a href="https:&#x2F;&#x2F;github.com&#x2F;zc1036&#x2F;ivy&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib&#x2F;std&#x2F;overload.icl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zc1036&#x2F;ivy&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib&#x2F;std&#x2F;overlo...</a> (DEFUN2 is the version of DEFUN in my language that supports overloading.)
评论 #25492285 未加载
kloudover 4 years ago
Very cool project, great to see more s-expression based languages. I maintain a list of lisp-flavored languages [0], so I will add Cakelisp there.<p>How did you implement the macro expansion? Are you translating the macros to C&#x2F;C++, then compile it with C&#x2F;C++ compiler and execute the temporary binary or do you have an interpreter for that?<p>I work on a somewhat similar project called Liz, which is basically a lisp-flavored dialect of Zig [1]. I did not implement user-defined macros yet, planning to learn more about comptime and its limitations first. But the compiler itself uses macro-expansion to implement many features.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;dundalek&#x2F;awesome-lisp-languages" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dundalek&#x2F;awesome-lisp-languages</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;dundalek&#x2F;liz" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dundalek&#x2F;liz</a>
评论 #25494765 未加载
评论 #25496376 未加载
elgatonegroover 4 years ago
&gt; Lisp has extremely powerful code generation, but makes serious performance compromises<p>This is a serious exaggeration.<p>Common Lisp has extremely good compilers that can meet C performance.<p>There are plenty of Scheme implementations (I use Chez) with very good performance characteristics too.
评论 #25492196 未加载
评论 #25494291 未加载
评论 #25493609 未加载
评论 #25492366 未加载
kazinatorover 4 years ago
Some well-known existing work in this exact area:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;kiselgra&#x2F;c-mera" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kiselgra&#x2F;c-mera</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;eudoxia0&#x2F;cmacro" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;eudoxia0&#x2F;cmacro</a> (Written in Common Lisp, doesn&#x27;t use S-exp syntax)<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tomhrr&#x2F;dale" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tomhrr&#x2F;dale</a> (Prev disc: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14079573" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14079573</a>)<p>Newer stuff:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;saman-pasha&#x2F;lcc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;saman-pasha&#x2F;lcc</a> (No mention of meta-programming)<p>Lesser known:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;deplinenoise&#x2F;c-amplify" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;deplinenoise&#x2F;c-amplify</a> (No docs, no update since 2010)
评论 #25496490 未加载
qw3rty01over 4 years ago
&gt; While languages like Rust offer benefits in terms of security and stability, they cost programmers in terms of productivity. It makes sense to value safety so highly if your code is safety-critical (operating systems, aerospace, automotive, etc.), but it&#x27;s much less valuable when safety isn&#x27;t as important (e.g. in games).<p>Just want to note that there is a large benefit to this kind of safety even if you&#x27;re not writing safety-critical code: lack of bugs! The biggest benefit I&#x27;ve seen from rust is that entire classes of bugs, some of which can be extremely difficult to root cause and fix, are removed by design. So you spend significantly less time on the later half of the project tracking down bugs, which is more than enough to offset the productivity loss at the beginning.
评论 #25499531 未加载
erlend_shover 4 years ago
Would love to see a comparison with <a href="https:&#x2F;&#x2F;gamelisp.rs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gamelisp.rs&#x2F;</a>
评论 #25492402 未加载
steinuilover 4 years ago
This reminds me a lot of c-amplify. I didn&#x27;t see it in the author&#x27;s list of languages they tried so I thought I&#x27;d mention it, it has a lot of neat ideas for building a lispy C.<p><a href="https:&#x2F;&#x2F;voodoo-slide.blogspot.com&#x2F;2010&#x2F;01&#x2F;amplifying-c.html" rel="nofollow">https:&#x2F;&#x2F;voodoo-slide.blogspot.com&#x2F;2010&#x2F;01&#x2F;amplifying-c.html</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;deplinenoise&#x2F;c-amplify" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;deplinenoise&#x2F;c-amplify</a>
kodoque2over 4 years ago
Those projects really need more game examples. The best poster child for lisp based gamedev is crash bandicoot and it is almost 20 years old now.
macjohnmccover 4 years ago
So many articles on Lisps on the front page. Did I miss something? It is Lispmas?
didibusover 4 years ago
This looks great. The S-expr syntax is my favourite, though I&#x27;d have preferred a Clojure-like one personally, a CL inspired one is still fine.<p>Some of the downsides mentioned can easily be taken care of by a macro I believe. Like the path traversal can be flattened with a macro most likely. Same thing for the type definitions.
azhenleyover 4 years ago
It looks like an interesting project. The syntax for pointers is what grabbed my attention at first. Would really need to spend some time with this to know how it would work in practice.<p><pre><code> const char* myString = &quot;Blah&quot;; (var my-string (* (const char)) &quot;Blah&quot;)</code></pre>
评论 #25491841 未加载
fmakunboundover 4 years ago
It looks how I’d code Lisp if I was C programmer.
评论 #25496551 未加载
schemescapeover 4 years ago
Is there any reason this couldn&#x27;t&#x2F;shouldn&#x27;t be used for applications besides than games? Other than your motivation&#x2F;goals coming from solving game development problems, I didn&#x27;t see anything that makes this useful for _only_ games.<p>Edit: The GitHub repository implies that this could be used for purposes other than games:<p>&gt; The goal is a metaprogrammable, hot-reloadable, non-garbage-collected language ideal for high performance, iteratively-developed programs (especially games).
评论 #25498106 未加载
billfruitover 4 years ago
How does it compare with Carp, another lisp with C interop?<p>Why did the creator create this, wont Carp have served the purpose.?
评论 #25492229 未加载
评论 #25494591 未加载
akhilcacharyaover 4 years ago
I’m interested in this “comptime” aspect. Zig has it too, but are there any other languages that use this? I’m under the impression that there’s a distinction between comptime evaluation and typical lisp macros.
评论 #25492394 未加载
评论 #25492583 未加载