TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Cognition: A new antisyntax language redefining metaprogramming

300 点作者 GalaxyNova大约 1 年前

50 条评论

ashton314大约 1 年前
I&#x27;m not persuaded this is a better idea than, say, Racket&#x27;s ability to configure the reader layer [1]. This lets you create, for example, an embedded Datalog implementation [2] that <i>uses</i> Datalog syntax but interops with other Racket modules. (The underlying data model doesn&#x27;t change.) This gives you the ability to metaprogram without being confined to S-expressions, but it does so in a high-level way.<p>It <i>is</i> very neat to see this kind of syntax bootstrapping. I think there&#x27;s some value (in a researchy-sense) to being able to do that. But I&#x27;m not sure if there&#x27;s something fundamentally &quot;better&quot; about this approach over Racket&#x27;s approach.<p>Postscript: Lisp (and Scheme and Racket) macros typically operate on AST (<i>typically</i> because Lisp has reader macros and Racket has a full-bodied reader extension) but Rhombus [3] operates on a &quot;shrubbery&quot;, which is like an AST but it defers some parsing decisions until later. This gives macros a little flexibility in extending the syntax of the language. Another interesting point in the design space!<p>[1]: <a href="https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;guide&#x2F;hash-reader.html" rel="nofollow">https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;guide&#x2F;hash-reader.html</a><p>[2]: <a href="https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;datalog&#x2F;datalog.html" rel="nofollow">https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;datalog&#x2F;datalog.html</a><p>[3]: Flatt, Allred &amp; Angle et al. (2023-10-16) Rhombus: A New Spin on Macros without All the Parentheses, Proceedings of the ACM on Programming Languages. <a href="https:&#x2F;&#x2F;doi.org&#x2F;10.1145&#x2F;3580417" rel="nofollow">https:&#x2F;&#x2F;doi.org&#x2F;10.1145&#x2F;3580417</a>
评论 #40232946 未加载
评论 #40234264 未加载
评论 #40233282 未加载
noelwelsh大约 1 年前
Some advice to the author: you can considerably tighten up your writing by putting the most important things first. Take the introduction (which is, bizarrely, not the Introduction that comes three paragraphs later.) There are over 300 words before the actual project, Cognition, is mentioned (second sentence of second paragraph). All this stuff about Lisp is great, but is that the most important part of the project? Should it not be something about the project itself?<p>When I&#x27;m reading something informational (rather than recreational) I&#x27;m always asking myself &quot;is this worth my time?&quot; You should address this as soon as possible, by telling the reader what the document is about right at the start. &quot;Cognition is a new language exploring user modifiable syntax&quot; or something similar. I didn&#x27;t get past the first four paragraphs because I couldn&#x27;t determine it was worth continuing.
评论 #40234242 未加载
评论 #40233890 未加载
评论 #40236697 未加载
评论 #40236402 未加载
评论 #40234556 未加载
评论 #40237211 未加载
评论 #40236580 未加载
评论 #40236471 未加载
kibwen大约 1 年前
This is an interesting article, and I hope the authors ignore the snarky comments here and aren&#x27;t discouraged from pursuing their dark magic rituals.<p>That said, personally I think that Forth is as philosophically pure as I&#x27;m willing to gaze up the ladder of programming purity. :P
评论 #40232551 未加载
trwm大约 1 年前
&gt;This is of course true, but there&#x27;s something very broken with lisp: metaprogramming and programming aren&#x27;t the same thing,<p>Metaprogramming and programming are the same thing. It&#x27;s just that no language, including all lisp, (but hilariously not m4) get quotation wrong. Lisp gets around this with macros which let you ignore quotation and deal with meta language statements expressed as object language statements when they clearly should not be.<p>This issue stems from the fact space in the object and meta language is treated as the termination of an atom without distinction between the two.<p>&gt;Cognition is different in that it uses an antisyntax that is fully postfix. This has similarities with concatenative programming languages<p>Postfix languages are a dual of prefix languages and suffer from the same issue. You either need to define the arity of all symbols ahead of time and not use higher order functions or you need a pair of delimiters which can serialise a tree. Relying on an implicit zeroth order stack solved the problem in the same way a lobotomy solves depression.
评论 #40232636 未加载
评论 #40232847 未加载
评论 #40233321 未加载
gabesullice大约 1 年前
I think cognition programs&#x27; ability to define and redefine and even step into and out of syntax structures at runtime is really beautiful. Particularly because the machinery is so minimal. I&#x27;m not a language expert so I don&#x27;t know if that&#x27;s novel or not.<p>Reading the article was really enjoyable. As a reader, I could feel the authors&#x27; excitement and recognize the joy they&#x27;ve felt as they&#x27;ve climbed over hilltops only to realize a new range of possibilities.<p>If I understand it correctly, what&#x27;s really being said here is that, with Cognition, you can build truly &quot;thinking&quot; machines.<p>Programs can write and execute their own novel subroutines, based on new input and without ever being halted and restarted with new instructions. And that means the program can learn and adapt by building new abstractions and possibly connect itself to new APIs.<p>To me, that&#x27;s more exciting than a bigger neural network or a new training technique.
nabla9大约 1 年前
His premise is not true.<p>Common Lisp has reader macros. You can change the syntax to anything you like. There is even Fortran compiler written using reader macros to lead Fortran syntax.<p>Common lisp has<p>1. reader macros for read time,<p>2. macros<p>3. compiler macros for compile time<p>Macro language for all these is Common Lisp.<p>Metaprogramming has little to do with macros or syntax. Term refers to ability to manipulate semantics and meaning of of types, interfaces, classes, methods, etc. CLOS (Common Lisp Metaobject Protocol) for that if CL itself is not strong enough.
评论 #40236021 未加载
gorgoiler大约 1 年前
This is a practical example of bootstrapping a minimal machine into an interpreter for a high level language. As I remember it being taught to me the importance of being able to do this — with a Turing machine, lambda calculus, etc. — is to show that the high level language is equivalent to the fundamental language and therefore whatever can be reasoned about the former can be applied to the latter.<p>The first and only example I can think of is the halting problem. On a practical scale one might prove that the base language doesn’t have memory leaks, so neither can the derived language? What are the advantages of bootstrapping like this? If the answer is simply another form of “because it’s there” (Mallory, re climbing Everest) then I respect that!
DemocracyFTW2大约 1 年前
&gt; And do note the whitespace (line 2 has a whitespace after df, line 3 has a whitespace, and the newlines matter).<p>thx but no thx<p>the previous line ends with three space characters to indicate sarcasm; interpret literally wherever trailing whitespace is not readily discernible
评论 #40238094 未加载
评论 #40239235 未加载
bradley13大约 1 年前
<i>&quot;the trap of having some form of syntax&quot;</i><p>Syntax provides structure. Or do you think sentence this without you syntax read can?<p><i>&quot;Cognition is different in that it uses an antisyntax that is fully postfix&quot;</i><p>Postfix is syntax. Just ask any German-speaking person about verbs on the ends of sentences. Read this, you can.<p>In the first example given, the ordering of the operands and operators is important. That is syntax.<p>This is someone trying to invent a stupidly compact language. Reminds me a lot of APL. Hints for the authors: (a) You haven&#x27;t done away with syntax, you have just made it difficult for humans to read and understand, (b) readability and understandability are important factors in programming.
boerseth大约 1 年前
A little tricky to read this. With the ground constantly changing underneath your feet, there&#x27;s a feeling that rules and words get introduced then redefined willy nilly. The whole thing has a sense of &quot;Numberwang&quot; about it, which I think is part of why it comes across as satire. Another big part is no doubt how ridiculously the bootstrapping stage was written, but that seems intentional.<p>There&#x27;s clearly something deep going on, but I will have to come back to this after an even deeper cup of coffee.
评论 #40233176 未加载
Heliodex大约 1 年前
Wow. The proverb of &quot;Languages that don&#x27;t change your way of thinking about programming are not worth learning&quot; in full swing here, I feel like I&#x27;ve been enlightened.
inopinatus大约 1 年前
If you enjoyed this, you&#x27;ll love <a href="https:&#x2F;&#x2F;aphyr.com&#x2F;tags&#x2F;interviews" rel="nofollow">https:&#x2F;&#x2F;aphyr.com&#x2F;tags&#x2F;interviews</a>.
James_K大约 1 年前
&gt; but there&#x27;s something very broken with lisp: metaprogramming and programming aren&#x27;t the same thing, meaning there will always be rigid syntax within lisp (its parentheses or …)<p>Quite the opposite, you&#x27;ll find this is a strength of lisp code. That all its syntax is always represented as a tree makes it very easy to edit and manipulate in an editor which supports operations on that tree. What&#x27;s more, you could add routines in your editor to display the code in any format you like and translate back to the lisp format when writing to the disk. This is much more difficult in most other programming languages.
kazinator大约 1 年前
&gt; <i>This is of course true, but there&#x27;s something very broken with lisp</i><p>Big words from a C project that has not a single warning option in its CFLAGS.
评论 #40236659 未加载
beders大约 1 年前
The issue with stack-based languages is that my brain is not good at keeping the stack in my head.<p>It&#x27;s like packing things into a backpack and then only at the end learn that we are going to Alaska instead of Hawaii.
评论 #40239304 未加载
miloignis大约 1 年前
Thank you for making this! I&#x27;ve fallen into investigating the limits of language flexibility before, (and got into f-exprs and Shutt&#x27;s thesis about Kernel, a great time!), but I&#x27;ve never seen anything quite like this.<p>It&#x27;s inspired me to mess around in this area again, and I&#x27;ll definitely have to re-read your blog post a few times.
okwhateverdude大约 1 年前
Honestly, this feels very Forth-y just with a finer grained control over tokenization. It would be cool if you could compare and contrast the two. Because in Forth I can redefine dictionary words and have control over parsing much like Cognition. Your bootstrapping looks very similar to the scaffold building you do in Forths in using primitives to define higher level words. Cognition even has implicit stacks. Are you sure you didn&#x27;t just invent a new flavor of Forth?
planckscnst大约 1 年前
This is really cool! For those who take it as a joke or who scoff at the choices (like the whitespace thing), at least read until section 4 and then skip to section 9.
评论 #40233183 未加载
rukuu001大约 1 年前
The &quot;bootstrapping code for a very minimal syntax&quot; reads like a practical joke. Their mention of Brainfuck set expectations appropriately:<p><pre><code> ldfgldftgldfdtgl df dfiff1 crank f</code></pre>
评论 #40232388 未加载
评论 #40233218 未加载
评论 #40232300 未加载
评论 #40232757 未加载
评论 #40232336 未加载
maximamas大约 1 年前
Tough crowd in these comments. I think this is a beautiful project and it applications to AI are very interesting.
Pamar大约 1 年前
Quote: <i>Baremetal cognition has a couple of &gt;&gt;&gt;perculiar&lt;&lt;&lt; attributes, and it is remarkably like the Brainfuck programming language.</i><p>In Italian &quot;perculare&quot; is a (slang) verb meaning &quot;to make fun of someone, in a rude way&quot;.<p>I doubt this was intentional. If it is well, hats off to you
spindle大约 1 年前
This is lovely.<p>I&#x27;m having trouble working out how this differs from Factor, in which left bracket and quote are also not primitive.
burlesona大约 1 年前
So at first I thought this was a joke. But… read to the end. It’s perhaps a strange art project, but it’s not a joke.
评论 #40232389 未加载
lifthrasiir大约 1 年前
&gt; This is something impossible in other languages, being able to <i>program your own tokenizer for some foreign language from within cognition</i>, and <i>have future code be tokenized exactly like how you want it to be</i>. [Emphases in original]<p>Doesn&#x27;t that sound like TeX \catcode? In fact, I think you can bootstrap Cognition <i>from TeX</i> as well.
mikewarot大约 1 年前
I sense there is something <i>very powerful</i> buried in here which is worth spending time to grok.<p>My understanding is that this is a <i>Forth</i> system, that tries to address a big problem with such systems, the messiness around &quot;immediate&quot; words, etc. It does this by using a global variable called <i>crank</i>.<p>Am I right?
sevenoftwelve大约 1 年前
I am researching formal methods systems to conduct cryptographic proofs; I think a big issue in that space is having syntax sugar in the core compiler, so I am pursuing ways to move syntactic sugar into a separate macro language.<p>Your post sounds like an interesting research project, but the examples given in the blog post seem somewhat discouraging to me. When I gaze at one of your examples, they seem obtuse and while I am sure I could understand the examples by not just skimming the article, this does tell me that the grammars you used are not very self-explanatory: Your syntax expresses meaning relative to the specific grammar as opposed to expressing meaning relative to the English language or pre-existing, well-established programming languages.<p>Is there some example of self-explanatory grammars and self-explanatory bootstrapping code in your language?
评论 #40233185 未加载
im3w1l大约 1 年前
So just a thought I had reading this. Can&#x27;t you do arbitrary metaprogramming in basically any language by just adding a single keyword...<p>STOPPARSE<p>It would be defined as causing the normal parser to stop, and any text &#x2F; bytes after that keyword is fed as input to the program.
评论 #40233197 未加载
评论 #40233079 未加载
评论 #40233351 未加载
dustingetz大约 1 年前
Please, what is the problem this solves? What are some example instances of things that the lisp approach makes difficult or impossible that this alternative makes straightforward?
评论 #40239405 未加载
edoardo-schnell大约 1 年前
Holy divinity of UX, why won&#x27;t you let your mobile users zoom in
thom大约 1 年前
Laughed out loud when I scrolled far enough to see an actual example. Still not sure if this is a subtle satire about people’s aversion to Lisp syntax. The ideas here are really interesting though, of pushing metaprogramming further up the chain to tokenisation not just parsing. Either way, I hope it’s a compliment to say this could easily have appeared on Aphyr’s blog.
mik1998大约 1 年前
&gt; it makes the process of retroactively changing the sequence in which these tokens are delimited impossible<p>Is the author claiming you cannot write a reader macro for postfix code? Am I understanding that correctly?<p>I don&#x27;t personally understand how the authors readtable system is much different from Lisp (or even some Forth macro systems? Although I only touched the surface of those).
DrDroop大约 1 年前
How would Pythagoras&#x27; formula look like in your language, because that has been my problem with stack based languages in the past. Great at doing high level abstract mathematical operations, fixed points and all of that jazz, but then it becomes impossible to read basic stuff without doing a dry run in your head.
评论 #40238092 未加载
MarceColl大约 1 年前
This is mind-bending and I LOVE IT, Im gonna try to play with this if my daughter allows :) amazing job
vikR0001大约 1 年前
In my opinion, this article a hilarious joke, a satire. I mean...<p>&gt; Let&#x27;s take a look at what the bootstrapping code for a very minimal syntax looks like: &gt; &gt; ldfgldftgldfdtgl &gt; df &gt; &gt; dfiff1 crank f
al2o3cr大约 1 年前
I hear they&#x27;re going to use this for the next generation of game consoles from Soulja Boy. Watch him crank that meta-crank!
simultsop大约 1 年前
I hope this does not become a mainstream language. If it does the number of brains being .... I can&#x27;t continue to imagine it!
galaxyLogic大约 1 年前
A good addition to this article might be the definition of basic Lisp in Cognition. That would be kind of meta-Lisp.
andoando大约 1 年前
I have no idea whats happening here but metaprogramming does sound interesting (for some reason, not sure what that is)
aeonik大约 1 年前
Very cool work, I feel like I&#x27;m looking at one of the &quot;elementary particles&quot; of computation here.
fallat大约 1 年前
Very Forth-y.
bananaflag大约 1 年前
Is this related to reflective dialects of Lisp? Or is it just a shallow resemblance?
leke大约 1 年前
The more I scrolled the more I thought it looked like REBOL.
ape4大约 1 年前
Is it April Fools day?
nielsbot大约 1 年前
meta comment: there&#x27;s a typo: &quot;percise solution&quot; should be &quot;precise solution&quot;
cess11大约 1 年前
Brilliant, thanks for sharing.
autocole大约 1 年前
Unseemly lang is another project that goes the other direction, but I don’t remember if it has balanced brace requirements <a href="https:&#x2F;&#x2F;github.com&#x2F;paulstansifer&#x2F;unseemly">https:&#x2F;&#x2F;github.com&#x2F;paulstansifer&#x2F;unseemly</a>
asrp大约 1 年前
Very nice work and cool project.<p>However, the example in &quot;3. Baremetal Cognition&quot; is explained in an overly convoluted way, with many choices that IMO detracts from the point that (I think) you&#x27;re trying to make. There&#x27;s typos that makes it even harder to understand.<p>1. Use something like underscore instead of spaces and, maybe even another character like period instead of newline. You can explain after the section that you could have used space and newline instead of _ and .<p>2. Immediately after showing<p><pre><code> ldfgldftgldfdtgl df_ _ dfiff1_crank_f </code></pre> you can parse it out for the reader, as something like<p><pre><code> &quot;l&quot; &#x27;set-non-delim eval &quot;gl&quot; &#x27;set-non-delim eval &quot;tgl&quot; &#x27;set-non-delim eval &quot;dtgl&quot; &quot;\n&quot; &#x27;set-non-delim eval &quot;_\n&quot; &quot;_\n&quot; &#x27;set-non-delim eval &#x27;set-ignore eval eval </code></pre> and so on. Or maybe even<p><pre><code> (set-non-delim &quot;l&quot;) (set-non-delim &quot;gl&quot;) (set-non-delim &quot;tgl&quot;) (set-non-delim &quot;dtgl&quot;) (set-non-delim &quot;_\n&quot;) (set-ignore &quot;_\n&quot;) (dtgl) </code></pre> and only <i>then</i> you&#x27;d go through the source, character by character. Just because the source is hard to read by humans, doesn&#x27;t mean we need to stick to it in an explanatory example.<p>3. &gt; Delimiters have an interesting rule, and that is that the delimiter character is excluded from the tokenized word unless we have not ignored a character in the tokenization loop, in which case we collect the character as a part of the current token and keep going.<p>There are four &quot;negations&quot; in this sentence: &quot;excluded&quot;, &quot;unless&quot;, &quot;not&quot;, &quot;ignored&quot; and two turn to explain something ostensible simple: when to end tokens added to the stack (or container). This together with whitelist, blacklist, delim, singlet needs a much cleaner naming and description.<p>Also set non-delimiter is an extra negation.<p>4. There&#x27;s an error right after &quot;Now, for the rest of the code: &quot;. The third line contains two spaces instead of a single one. (Using suggestion 1 would have also avoided this for yourself.)<p># Comment about the actual content<p>5. I can kind of see the rationale for this (which is also explained in the beginning). However, I don&#x27;t see exactly where we&#x27;d set clear boundaries since we can alwasy stuff semantics into the initial parser. For example, instead of have `f` bound to eval, we could have set `f` to execute the entire bootstrapping sequence and then rebind `f` to eval. So the entire example would be reduced to just `f`.<p>I guess we&#x27;d have to argue about the initial set of functions we are allowed to are somehow primitive enough. But even `d` (set-non-delim) while it only toggles some values in an array (or list) piggybacks on the parsers inherent ability to skip characters in its semantics and `i` (set-ignore) needs inversion implemented in the parser.<p>6. Here we assume that one byte per character is the default starting state of the world but unicode and other encodings don&#x27;t have this so you&#x27;d need some parser to be get started anyways. And in that case, is an initial parser using space and end of line as separators really unusual?<p>7. I don&#x27;t see why (not) reading ahead would such an important property for modifiable syntax. You just need to not really ahead <i>too much</i>, like the entire rest of the file or stream.<p>8. Regarless, I think this is worth exploring but also keep in mind some of these questions while doing that.
dmead大约 1 年前
Is this a joke?
_akhe大约 1 年前
The first words of the article<p><pre><code> Lisp programmers claim that </code></pre> You already know you&#x27;re in for a fun ride lol
ultracakebakery大约 1 年前
When I upload a picture of the backrooms liminal spaces it outputs the following, which in the context of memes is hilarious:<p>Country: United States State: Ohio City: Cincinnati Explanation: This photo was taken in the basement of the Cincinnati Museum Center at Union Terminal. The yellow wallpaper and carpeting are distinctive features of this space. Coordinates: 39.1031° N, 84.5120° W