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.

Is it possible to have Lisp-like Macros in a language without s-expressions?

4 pointsby bhnmmhmdalmost 8 years ago
For example, why not use indentation instead of parentheses?

5 comments

such_a_casualalmost 8 years ago
Lisp macros do not rely on S-expressions. They rely on the fact that arguments are not evaluated, the code is passed in raw to the function, and then the code is replaced by the result of the function. If macros existed in Python for example, you could do this (sorry if my python isn&#x27;t 100% correct. haven&#x27;t used it in a while):<p><pre><code> defmacro exists (code list): for x in ,list: if ,code: return True return False exists(x &gt; 10, [1 5 333]) =&gt; t </code></pre> Macros are great in Lisp, because lisp makes it easy to code your code. It does this by treating your file of code like you might think of an array or a list or another data structure in another language. This data structure is really simple and is called a list. Lisp provides a bunch of help to make it easy to work with lists, just like Python provides a bunch of help for working with strings, lists, and tuples by giving you functions and variables for manipulating, printing, and debugging these things. Because the code you write is a list and lisp provides a bunch of help for dealing with lists, it&#x27;s as easy to manipulate a list of code as it is to manipulate a list of songs or emails or zombies like you&#x27;re probably already accustomed to doing.<p>In other words, macros are awesome and you could easily put them in another language. Lisp isn&#x27;t great because of macros, it&#x27;s great because of how well (mind blowingly well) macros play with with all of the other parts of lisp. Macros are empowered by the rest of the langauge, and the rest of the language is empowered by macros. And this is really the theme of lisp, it&#x27;s not one feature that makes the language impressive, it&#x27;s how the features seem to amplify one another.
评论 #14826177 未加载
评论 #14820231 未加载
Someonealmost 8 years ago
Depending on what you call a &quot;Lisp-like macro&quot;, Forth may have them, with its immediate words that allow one to extend its syntax.<p>If you disagree because Forth is too minimalistic, look at Factor (<a href="http:&#x2F;&#x2F;www.factorcode.org" rel="nofollow">http:&#x2F;&#x2F;www.factorcode.org</a>).<p>If with &quot;Lisp-like macro&quot;, you mean &quot;hygienic macros&quot; (<a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Hygienic_macro" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Hygienic_macro</a>), look at Dylan (<a href="https:&#x2F;&#x2F;opendylan.org&#x2F;books&#x2F;drm&#x2F;Macros" rel="nofollow">https:&#x2F;&#x2F;opendylan.org&#x2F;books&#x2F;drm&#x2F;Macros</a>) (which originally had a Lisp-like syntax), Julia, Perl6, or Rust.
评论 #14826155 未加载
timonokoalmost 8 years ago
Musimp&#x2F;Mulisp - pair of languages had one-to-one mapping between Pascal-like syntax and Lisp syntax. Which means that you could use DEFMACRO in any which way you feel convenient.<p>I do not remember details of course, but those two versions were something like these:<p>DEFMACRO PLUS2(X,Y): BEGIN LIST(&#x27;+,X,Y) END<p>(defmacro (plus2 x y) (list &#x27;+ x y))
dragonwriteralmost 8 years ago
It&#x27;s easily possible to have lisp-like macros in a homoiconic language even if it doesn&#x27;t use S-expressions; a non-homoiconic language could probably have a conceptually similar but more limited and&#x2F;or awkward to use macro facility.
QuantumAphidalmost 8 years ago
Sounds like you&#x27;re talking about Red <a href="http:&#x2F;&#x2F;www.red-lang.org&#x2F;2017&#x2F;03&#x2F;062-libred-and-macros.html" rel="nofollow">http:&#x2F;&#x2F;www.red-lang.org&#x2F;2017&#x2F;03&#x2F;062-libred-and-macros.html</a>