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.

A cursory look at meta-programming in Nim

97 pointsby ldleworkabout 10 years ago

4 comments

hzhou321about 10 years ago
Or, with a text based meta-layer (MyDef):<p><pre><code> import macros $(for:A in A,B,C) proc $(A)() = echo &quot;$(A)&quot; proc execute(order: seq[int], callbacks: seq[proc]) = for i in items(order): callbacks[i]() execute(@[0,0,1,2,1,2], @[A, B, C])</code></pre>
评论 #9495657 未加载
评论 #9495673 未加载
kazinatorabout 10 years ago
Way too cumbersome, sorry.<p>TXR Lisp:<p><pre><code> @(do (macro-time (defun abc-proc (n) ^(defun ,n () (pprinl &#x27;,n)))) (defmacro abc-procs (. n) ^(progn ,*[mapcar abc-proc n])) (abc-procs a b c) (defun exec (order callbacks) (each ((i order)) [[callbacks i]])) (exec &#x27;(0 0 1 2 1 2) &#x27;(a b c))) $ txr test.txr a a b c b c </code></pre> Variation on exec:<p><pre><code> (defun exec (order callbacks) (mapdo (op [callbacks @1]) order))</code></pre>
评论 #9495274 未加载
评论 #9495253 未加载
shastaabout 10 years ago
I think the author should post a follow-up after he&#x27;s tried to do substantial work with this style meta-programming. My guess is that you want to keep templated code to an absolute minimum.
评论 #9495320 未加载
kbdabout 10 years ago
It&#x27;s a small thing, but I&#x27;m so glad they renamed it to &quot;Nim&quot;. Its prior name carries such a negative connotation, while just shortening that gave a name that&#x27;s cute and simple.
评论 #9494879 未加载
评论 #9494700 未加载
评论 #9494979 未加载