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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: Easy Forth

122 点作者 skilldrick超过 9 年前

8 条评论

richdougherty超过 9 年前
Nice!<p>If you like Forth, there&#x27;s information about similar languages over at <a href="http:&#x2F;&#x2F;concatenative.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;concatenative.org&#x2F;</a>.
评论 #10635344 未加载
vive-la-liberte超过 9 年前
I often use dc(1) so my first instinct was to type &quot;1 2 3 +&quot; into the input without intermediate linebreaks. I was delighted to see that this was correctly understood to mean what I wanted to express instead of it doing something silly like taking just the first int of my string or trying to parse the string as a whole straight to int.<p>These are the sort of things which encourage readers to read on :)<p>Edit: Unfortunatelly, when I try to scroll and read the rest, the input field steals focus rendering me unable to continue. Firefox on Android.
评论 #10635431 未加载
danbolt超过 9 年前
This is an enjoyable read! I&#x27;ve been coming across mentions of Forth much more often lately, so it feels satisfying being able to get a sense of it.<p>One thing that caught my attention is that Forth&#x27;s boolean value for &quot;false&quot; is 0, and for &quot;true&quot; is -1. This makes sense if you look at their binary values, being 00000000 and 11111111, respectively. Does anyone know if there was an underlying design decision for this? Fast hardware checking? Bit masking tricks?
评论 #10636863 未加载
评论 #10636187 未加载
peter303超过 9 年前
Forth programs are very compact. And so are Forth intepreters. Great for 1970s PCs with memories as small as 8K. But postfix programs are hard to understand. An hour later and you&#x27;ve forgotten what you have written.
评论 #10637984 未加载
评论 #10636488 未加载
zatkin超过 9 年前
Everything is great, simple, and easy to understand, and then I get to that Snake example and the code is nearly unreadable.
评论 #10635348 未加载
david-given超过 9 年前
A couple of months ago I wrote a Forth interpreter, because I&#x27;d always wanted to. I haven&#x27;t really used it in anger, but passes the basic ANS Forth tests, so it should be reasonably complete.<p>(It&#x27;s here: <a href="https:&#x2F;&#x2F;github.com&#x2F;EtchedPixels&#x2F;FUZIX&#x2F;blob&#x2F;master&#x2F;Applications&#x2F;util&#x2F;fforth.c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;EtchedPixels&#x2F;FUZIX&#x2F;blob&#x2F;master&#x2F;Applicatio...</a> It&#x27;s a single, portable C file which is also an executable shell script containing an awk script! It compiles to about 8kB of code on a microcontroller.)<p>From the experience I learnt two main things about Forth:<p>(a) the realisation of how Forth works, and the way in which the language bootstraps itself out of nothingness, and the way in which it takes about two basic principles and then builds an entire language out of them, is truly mind expanding. The process was full of &#x27;aaah!&#x27; moments when it all came together and I realised just how elegant it was.<p>(b) actually <i>engineering</i> a Forth interpreter, and dealing with the ANS spec, was an exercise in frustration. Those elegant principles are compromised at every stage of the process. The spec defines things which no sane person would define. I&#x27;d implement a word, and it&#x27;d be clean and work, and then the ANS tests would fail and I would realise that the specification dictates a particular half-arsed implementation which makes no sense whatsoever. The process was full of &#x27;uuugh!&#x27; moments when I saw a thing in the spec and realised how much more complicated it would make my life.<p>Examples follow:<p>- double words are pushed onto the stack in high word &#x2F; low word order. Regardless of whether your architecture is big or little endian. Good luck with using 64 bit load&#x2F;store instructions!<p>- DO...LOOP is defined to use the return stack for temporary storage. Valid Forth programs can&#x27;t call EXIT from inside a DO...LOOP structure. If you try, your program does a hyperspace jump and crashes.<p>- BEGIN...REPEAT is defined <i>not</i> to use the return stack for temporary storage. Valid Forth programs are allowed to call EXIT from inside a BEGIN...REPEAT structure.<p>- DO...LOOP has different termination characteristics depending on whether you&#x27;re counting up or down.<p>- Mismatched control flow structures are not just not detected, but they are actually, in certain combinations, defined to work. The spec actually defines what some of them do --- IF, THEN, BEGIN, WHILE, REPEAT, if I recall correctly --- and lets you mix and match them. Good luck if you want to use different, more efficient implementations.<p>- The memory model assumes that Forth is the sole owner of the memory. It starts at the bottom and works up. When compiling a word, you have to decide what address it&#x27;s being written to before you know how long it&#x27;s going to be. Want to share the heap with something else? Good luck with that.<p>- Division. How overcomplicated can it be? Answer: extremely.<p>- Rearranging values on the stack gets old very, very, <i>very</i> quickly.<p>- Forth isn&#x27;t typed! Except where it is, and it doesn&#x27;t check them, and if you get them wrong my the gods have mercy on your soul, because the interpreter surely won&#x27;t.<p>I would still say that anybody with any interest in programming should learn at least the basics of Forth, and should write at least the core of a Forth interpreter. (It won&#x27;t take long, and you&#x27;ll learn a hell of a lot.) But I&#x27;d be really hesitant about recommending it for real programming use, other than for the special niches where it excels, such as embedded systems. Most of the problem is that it&#x27;s overspecified; it would be so much simpler, faster, and easier to understand if the spec had more undefined behaviour in it. I now understand why so many people just ignore it and write their own dialect. Strong type checking would really help, too.
tonyonodi超过 9 年前
This looks amazing! Thank you. I&#x27;ve been meaning to learn Forth since forever now.
berntb超过 9 年前
Fun environment.<p>A couple of weeks ago I installed 8th to learn a Forth as a hobby. (It promised iOS integration, so it might even be useful. I&#x27;m not there yet. :-) )