5 ms·
Forth: The programming language that writes itself
- l_theanine 4y ago[flagged]
- phist_mcgee 4y agoI didn't even know that edge was on ios
- l_theanine 4y ago[flagged]
- sitzkrieg 4y agoyou might wanna look up what all browsers on ios are forced to use
- davegauer 4y agoPlease note that these are slides for a talk. Regular web page in the works!
- mikewarot 4y agoStoical is an older forth with an interesting twist. 'string is a quoted string that is terminated by a space. Colon takes a string parameter, to avoid a lot of "compile mode" nonsense. To define the cube function 'cube : dup dup * * ;
- teddyh 4y ago> 'string is a quoted string that is terminated by a space. Sounds like LISP symbols, which have the same syntax, are also essentially strings, and are also used to refer to names of function and variables.
- kragen 4y agothis is a great idea, among other things because it puts the name you're defining in the left margin where it's easiest to scan to, but i don't see how it avoids any compile-mode nonsense. in this line of code, 'cube still has to push the string on the stack at compile time, and : has to consume it at compile time, while dup just has to compile some code into the colon definition, which at least strongly suggests that the interpreter is being run in a different mode that compiles things like dup instead of executing them? https://stoical.sourceforge.net/summary.php https://stoical.sourceforge.net/summary.php https://sourceforge.net/projects/stoical/files/stoical/0.1.8/ https://sourceforge.net/projects/stoical/files/stoical/0.1.8... some example code % %(var) 1+! % Increment the variable addressed by TOS. % % '1+! : dup @ 1+ swap ! ; % %(math) hex % Set radix to hexadecimal. % % 'hex : 16 radix ! ; % %(io) cr % Output a newline. % % 'cr : '\n = ; % %(io) space % Output a space. % % 'space : 32 put ; % ----- define the more traditional interface to flow control. % %(conditional) if (*) % "n IF ... then" % Conditionaly execute the instructions. The instructions following IF will be % executed if TOS is not FALSE upon invokation. % % 'if : () if{ exec ; immediate it seems to be dynamically-typed and garbage-collected?
- version_five 4y agoIn case it's new to anyone, I recommend going through the jones forth "literate program" - even if you don't understand assembly. You can try porting it to a language you know, it gives a good understanding of how forth works https://github.com/nornagon/jonesforth/blob/master/jonesforth.S https://github.com/nornagon/jonesforth/blob/master/jonesfort...
- messe 4y agoOh, nice, Jones forth! I second the recommendation to read through it. I ported this to ARM assembly years ago, and it was a lot of fun. No idea where that program is now, unfortunately. Now that I'm using Apple Silicon day to day, maybe it's time I try rewriting it for ARM64.
- golem14 4y agoIt gets hard when you discover that apple has mostly disallowed self modifying code on their arm architecture. You can, with lots of hoops, but a straightforward assembler in forth becomes all but impossible.
- bitexploder 4y agoAlso just learn assembly. The basics take a half hour to grasp if you have any exposure to programming :)
- Nadya 4y agoAnd make it a fun ASM. Like 6502 [0]. [0] https://skilldrick.github.io/easy6502/ https://skilldrick.github.io/easy6502/
- bitexploder 4y agoMy favorite learning assembly. It all mostly applies to every other Von Neumann machine too.
- rwmj 4y ago
- optimalsolver 4y agoA great introduction is the book Starting Forth [0]. It has the most charming illustrations I've ever seen in a text book. [0] https://www.forth.com/starting-forth/ https://www.forth.com/starting-forth/
- barrenko 4y agoDidn't need this rabbit hole, but thanks!
- gareth5851 4y agoloved this
- NikkiA 4y agoMy biggest problem with forth has always been the curmudgeonly-ness of the community, it's like they feel compelled to do things at exactly 180⁰ to how the rest of the computer industry works, even this webpage throws out every norm about how web pages must be navigated, and feels like something from the 1970s while still looking modern. I love the language, at least part of it, but the community and that 180⁰ shift always feels like any attempt to utilise forth is swimming upstream in monsoon season.
- armitron 4y agoThis is one of its greatest strengths. The Forth community, large parts of which treat Forth as a secret weapon of sorts, has no particular reason to make concessions on the altar of popularity. This attitude helps to attract out-the-box thinkers and people with a tendency to go against established norms. The SVFIG meetings have been traditionally excellent in showcasing these somewhat unique in today's mainstream programming culture strengths.
- uonpopular_th 4y ago[flagged]
- zozbot234 4y agoIt's important to realize why the computer industry works a certain way and how that compares to different approaches. For instance, there's very real issues with stack machines when you try to generalize them to parallel programs - including extracting fine-grained parallelism from sequential code. The most elegant approach is probably dataflow, but that's still a far cry from the simplicity of the FORTH-inspired, concatenative approach. The register-based CPU's we use are a pragmatic, middle-of-the-road approach.
- jvanderbot 4y agoThis appears very insightful, but I can't grok the differences. Got an explainer handy that I and others might start with?
- kerkeslager 4y ago
- submeta 4y agoI learned about stack based programming when I bought a HP28s calculator in 1988. It could be programmed in its Forth like language, had data structures like lists, arrays, matrices, and symbols. It was also my intro to Scheme. It was like revelation. When everyone else around me was learning C or Pascal, where arrays had fixed lengths, I had seen the future with dynamic data structures. I could implement and test ideas that would take me ten or a hundred times more LOC. Now over 30 years later I still use a stack to implement tree traversal instead of using recursion.
- zozbot234 4y ago> Now over 30 years later I still use a stack to implement tree traversal instead of using recursion. Recursion is the same as "using a stack". It's just using the system stack generally, which might not be what you want.
- submeta 4y agoBut it is possible to get a stack overflow error when using recursion to implement tree traversal if the depth of the tree is too large or if the recursion is not properly managed. Implementing tree traversal iteratively can help avoid that because it does not rely on recursive function calls that can build up on the call stack. Instead, an iterative approach uses an explicit data structure (such as a stack or queue).
- skybrian 4y agoWell, you could run out of memory implementing a stack as an array too. It all depends on what the limits are.
- roflyear 4y agoI kind of like that because if your tree depth is that large you're throwing away the benefits of a tree generally and that is an indication you should be doing something different.
- mrtomorrow 4y ago[flagged]
- crabbone 4y agoMy biggest problem with Forth is that you simply cannot start reading a program at an arbitrary point because you only have few valid entry points where you know that the stack is empty. Otherwise you just have no idea what's going on. This is where it differs from languages which try to guard the scope, but is, in a way similar to the problems created by violating the locality of the problem by using global variables. I feel like Forth might have evolved to mitigate this problem (as well as many similar ones, like not needing to specify the number or names of arguments to the subroutines, or not really having much structure to the routines that can be expressed through something like paired delimiters or indentation...) but, unfortunately, it didn't. Or, maybe I never found any descendants that would take the language further towards implementing some of the more modern ideas about how to structure large programs.
- version_five 4y agoI've only dabbled in forth so I'm not the right one to answer - but I just want to mention there are other stack based or concatenative languages like Factor and Joy that have had a lot of work put into them. From what I recall they feel like they were created and maintained by somewhat eccentric people... they may have put more thought into the problems you mention
- ahefner 4y agoIn Factor the stack effects are static and annotated.
- crabbone 4y agoThat's interesting. I'd have to try to find out more about these. Thanks!
- int_19h 4y agoThey are also generally not as low-level as Forth, and thus don't have the same "easy to port to a completely new arch from scratch" thing going for them.
- adastra22 4y ago
- skybrian 4y agoEmbedded programming on tiny devices hasn't gone away, but the part that seems rather old-fashioned nowadays about Forth's approach is assuming that the programming environment has to be small and simple to run on the device. These days we program and interact with devices using a powerful machine like a laptop. Being able to do over-the-air updates can be very useful, and interactive debugging can be useful. But there's no reason you can't assume the UI and compiler are on a much more powerful computer that can run a web browser and whatever toolchain you need. So that means you can do things like autocompletion and static analysis, and that has effects on what kind of language features you'll want to have, even if the target machine and generated code is very small.
- fsckboy 4y agoyou're right, there are "good" embedded systems, but there are still all sorts of 8 bit processors (some of them the same old suspects) with small on-chip memory embedded in devices. You think those christmas cards that play tinny music are running multivoice synths DSP through GPUs with 18 bit D/A and spare cycles, and will do autocomplete for you if you can get a terminal connected? uh uh.
- mock-possum 4y agoI can see what this is reaching for --- but the presentation is just... tedious. --- inscrutable --- insufficient payoff for the patience it requires of the reader --- I gave up half way down the page. --- There just isn't enough continuity to these little nibbles of narrative --- Sometimes things are explained --- explained with citations even --- other times they're just thrown out with no explanation whatsoever --- or a wink and a nod, utterly impenetrable to those not in the know --- and no sense of what's important to pay attention to, and what can safely be glanced past. --- Could really use some workshopping.
- rossjudson 4y agoWere you distracted by your phone?
- bitwize 4y agoI think these are slides for a talk, dude.
- davegauer 4y agoExactly, thank you. :-)
- johnisgood 4y agoI think you should mention Factor, too, since you mentioned Joy. Factor is amazing. Lots of great stuff have already been implemented, and the code is pretty concise. I found a lot of goodies in the "extra" vocabulary I never thought I would! Some random stuff I found interesting: https://github.com/factor/factor/blob/master/extra/bittorrent/bittorrent.factor https://github.com/factor/factor/blob/master/extra/bittorren... https://github.com/factor/factor/blob/master/extra/hashcash/hashcash.factor https://github.com/factor/factor/blob/master/extra/hashcash/... https://github.com/factor/factor/blob/master/extra/bitcoin/client/client.factor https://github.com/factor/factor/blob/master/extra/bitcoin/c... Interesting talks: https://concatenative.org/wiki/view/Factor/Talks https://concatenative.org/wiki/view/Factor/Talks
- ofalkaed 4y agoI love forth and stack based languages in general, writing a forth implementation has become my standard way to learn languages. Lately I have been playing with MinForth[0], it transpiles to C so you can effortless mix C in with the forth and get easy access to C libraries, good fun. 0: https://minforth.sourceforge.io https://minforth.sourceforge.io
- omeysalvi 4y agoLearning languages like these feels like the premise of Arrival(2016) where learning a new language expands the way you think about and solve problems. I'm trilingual like most Indian people but I suspect learning languages like Japanese or Mandarin which use a different, pictorial way of representing words would be a similar way to improve cognition.
- jallmann 4y agoTry one of the sign languages. Not sure where you are located, but many countries have their own, including India.
- teddyh 4y agoLISP is worth learning for a different reason – the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot. (You can get some beginning experience with LISP fairly easily by writing and modifying editing modes for the Emacs text editor, or Script-Fu plugins for the GIMP.) It’s best, actually, to learn all five of Python, C/C++, Perl, and LISP. Besides being the most important hacking languages, they represent very different approaches to programming, and each will educate you in valuable ways. http://www.catb.org/~esr/faqs/hacker-howto.html#skills1 http://www.catb.org/~esr/faqs/hacker-howto.html#skills1
- jacquesm 4y agoMay I suggest adding PROLOG to that list? Or Erlang, for yet another different take on programming.
- proper_elb 4y agoThis would be my 2023 list: Python, C, LISP, Fortran, Haskell, Prolog, SmallTalk. Also likely Rust, it might replace C in my list and is quite similar to Haskell in some ways, particularly when it comes to turning runtime errors to compile time error.
- 4y ago
- Kapura 4y agoIs there a version of this website that works better for non-mobile browsers?
- PaulHoule 4y agoI'd say it works about the same on desktop and mobile. You might prefer something that isn't so wasteful of whitespace and doesn't make you scroll but that could be accomplished in a way that works the same on desktop and mobile.
- foresto 4y agoHave you tried Firefox's reader view? I find it very helpful for annoying site designs, especially after adjusting its style settings.
- davegauer 4y agoPlease note that these are slides for a talk. Regular web page in the works!