3 ms·
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
by thelazydogsback 6y 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:
"backtick char ` is expanded to quasiquote by the reader"
(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/let bindings :rest forms)
`( (lambda
~(map first bindings) ~@forms)
~@(map second bindings) ))
(define-macro (let :rest forms)
(if (contains? forms :in)
`(~'clj/let ~@forms)
`(~'lisp/let ~(car forms) ~@(cdr forms)) ))
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's bootstrapping code, so once your primitives are defined, you can move on.
- abeppu 6y agoThe post describes how Fexprs were designed in a way that was tightly coupled to implementation choices around eval, in ways which were later limiting. Did you experience this? Were there things you might have wanted to change about your lisp which were inhibited by the use of Fexprs? > FEXPRs and FSUBRs were ... meta-implementation operators that relied on the meta-circular definition of EVAL > The problem with FEXPRs is that they are far too powerful and place too many constraints on the implementation. > FEXPRs were designed around the fact that the language had a meta-circular definition that was implemented via recursive descent of list structure. > A FEXPR, on the other hand, is a program that is deliberately not abstracted away from the concrete representation. > A FEXPR manipulates objects on both sides of the isomorphism (yuck), so Big-P and Big-P^-1 cannot be factored out of the semantics.