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.

On Fexprs and Defmacro

42 pointsby sea6earover 4 years ago

3 comments

thelazydogsbackover 4 years ago
I wrote a Lisp in F# last year, and I started with Fexprs and used them as the basis to write quasiquote and defmacro, which are then used to write things like defun and let:<p><pre><code> &quot;backtick char ` is expanded to quasiquote by the reader&quot; (defmacro! quasiquote (flambda (form) (_qq-expand form))) (defmacro! define-macro (flambda (sig :rest body) `(defmacro! ~(car sig) (flambda ~(cdr sig) ~@body)) )) (define-macro (defun name vars :rest forms) `(def! ~name (lambda ~vars ~@forms)) (define-macro (lisp&#x2F;let bindings :rest forms) `( (lambda ~(map first bindings) ~@forms) ~@(map second bindings) )) (define-macro (let :rest forms) (if (contains? forms :in) `(~&#x27;clj&#x2F;let ~@forms) `(~&#x27;lisp&#x2F;let ~(car forms) ~@(cdr forms)) )) </code></pre> There is a certain amount of brain-warping required understanding it all, and getting the nested quasi- and regular- quotes right takes some getting used to, even for me going back and trying to grok it -- but it&#x27;s bootstrapping code, so once your primitives are defined, you can move on.
评论 #24935708 未加载
ACow_Adonisover 4 years ago
I am not too proud of a man to say that I read that all the way through, and by the end, still didn&#x27;t understand one bit: and I&#x27;m a lisp person who at least knows a little bit about the history of the language.<p>Can ANYONE here actually translate that into English?
评论 #24934990 未加载
评论 #24934653 未加载
评论 #24935640 未加载
andrewflnrover 4 years ago
I think I got lost on how exactly SUBRs and FSUBRs are different. Is it that SUBRs still get evaluated forms of the arguments in an assembly-accessible form, while FSUBRs get reader output as linked lists?
评论 #24943977 未加载