3 ms·
I think the main difference is that macros statically evaluate their inputs ie. at compile-time. fexprs can selectively eval their inputs at runtime ie. dynamic
by alexisread 4y ago
I think the main difference is that macros statically evaluate their inputs ie. at compile-time. fexprs can selectively eval their inputs at runtime ie. dynamically.
This has given the impression of slowness and difficulty to grok with fexprs, as dynamic eval foregoes certain optimisations, and scoping the fexpr bindings is hard (variable capture is a problem).
https://web.wpi.edu/Pubs/ETD/Available/etd-090110-124904/unrestricted/jshutt.pdf https://web.wpi.edu/Pubs/ETD/Available/etd-090110-124904/unr... is a good paper on this stuff (see p41/42 for a discussion).
Another version of fexprs/vau is open composition https://www.piumarta.com/freeco11/freeco11-piumarta-oecm.pdf https://www.piumarta.com/freeco11/freeco11-piumarta-oecm.pdf
I guess the main issue is handling dynamic binding cleanly. Koka https://koka-lang.github.io/koka/doc/book.html#why-handlers https://koka-lang.github.io/koka/doc/book.html#why-handlers handles this well with static (HM) type inferrence.
Shen and Maude (https://shenlanguage.org/TBOS/tbos_255.html https://shenlanguage.org/TBOS/tbos_255.html, https://maude.lcc.uma.es/maude321-manual-html/maude-manual.html https://maude.lcc.uma.es/maude321-manual-html/maude-manual.h...) are the only languages that I know that can do dynamic type checking, and thus a full handling of dynamic binding, the Shen calculus syntax is a bit clunky though.
- bsder 4y ago> This has given the impression of slowness and difficulty to grok with fexprs, as dynamic eval foregoes certain optimisations, and scoping the fexpr bindings is hard (variable capture is a problem). And yet, Javascript, possibly the most widespread language on the planet, does exactly this and has been optimized for speed to hell and back several times. The problem wasn't unsolvable. The problem was that there wasn't enough money behind solving it.
- lispm 4y agoJavaScript has Fexprs?
- bsder 4y agoJavaScript has highly dynamic eval with lots of scoping issues very similar to the issues that everybody thought were dealbreakers with fexprs. And, yet, somehow a lot of very clever people made Javascript one of the fastest languages around.
- lispm 4y agoand that "fast" JavaScript code is using eval? OTOH, typically Lisp code uses zillions of macros, incl. most of control flow constructs.
- lispm 4y ago> macros statically evaluate their inputs ie. at compile-time Unless one uses an interpreter. CL-USER 1 > (defmacro my-if (test a b) (print "Hi, I'm the executing MY-IF macro") `(if ,test ,a , b)) MY-IF CL-USER 2 > (defun foo (a) (my-if (> a 10) 'big 'small)) FOO CL-USER 3 > (foo 11) "Hi, I'm the executing MY-IF macro" "Hi, I'm the executing MY-IF macro" BIG CL-USER 4 > (foo 2) "Hi, I'm the executing MY-IF macro" "Hi, I'm the executing MY-IF macro" SMALL In this Lisp implementation, the macro even runs twice on each runtime invocations.
- tempodox 4y agoSBCL to the rescue. It compiles everything you enter in the REPL.
- lispm 4y agoUnless one uses an interpreter: $ /usr/local/bin/sbcl This is SBCL 2.2.1, an implementation of ANSI Common Lisp. More information about SBCL is available at <http://www.sbcl.org/>. SBCL is free software, provided as is, with absolutely no warranty. It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. * *evaluator-mode* :COMPILE * (setf *evaluator-mode* :interpret) :INTERPRET * (defmacro my-if (test a b) (print "Hi, I'm the executing MY-IF macro") `(if ,test ,a , b)) MY-IF * (defun foo (a) (my-if (> a 10) 'big 'small)) FOO * (foo 11) (foo 11) "Hi, I'm the executing MY-IF macro" BIG