15 ms·
Show HN: A Lispy, embedded Forth
- tluyben2 10y agoThat is a bit too exciting this early in the morning...
- codr4life 10y agoSorry about that :) Time zones...I strongly prefer Lisping and Forthing after midnight, too much noise on all levels during days.
- tluyben2 10y agoYep, I live in the EU but I am in Cambodia now and I love three languages the most; Lisp, Forth and APL. So you know what to do to make me cry and have eternal enlightenment... Edit; I use Lisp in the form of Clojure daily as well as Forth for embedded. When writing embedded code, instead of assembly (check my profile, the stuff we use definitely has no room for Node but often not even C) I usually port a Forth if one is not available, at least for testing but usually it is good for production too.
- jessaustin 10y agoWhat resources would you recommend for getting started with Forth?
- mbroncano 10y agoThis is a more interesting question that it might seem. For a Sunday afternoon read, please take a look to Jonesforth [1] for an implementation of a basic Forth for Linux/32 bits. It's written in literate style and it reads like a nice book. If you are not that interested in the implementation of the compiler (and if so you might be missing the ultimate point of Forth), Starting Forth [2] is a classic resource. Edit: formatting [1] https://github.com/AlexandreAbreu/jonesforth https://github.com/AlexandreAbreu/jonesforth [2] https://www.forth.com/starting-forth/ https://www.forth.com/starting-forth/
- tluyben2 10y agoCharles Moore Thinking Forth is excellent if you want to work with resource limited systems.
- astrobe_ 10y agoThe author of Thinking Forth is Leo Brodie. From Chuck Moore, the father of Forth, "1X Forth" ( http://www.ultratechnology.com/1xforth.htm http://www.ultratechnology.com/1xforth.htm ) is worth reading before and after Thinking Forth.
- tluyben2 10y agoYou are absolutely right. Got my authors mixed up. Both are great reads.
- david-given 10y agoI have a reasonably portable pure-ANSI-C Forth here in about 2.5kloc: https://github.com/EtchedPixels/FUZIX/blob/master/Applications/util/fforth.c https://github.com/EtchedPixels/FUZIX/blob/master/Applicatio... It's not well commented, but it should be easy enough to read. It passes the basic ANS Forth test suite. The C file is also an exciting self-modifying shell script with embedded awk and Forth parts.
- PeCaN 10y agoHeh. I like you. One of my many language projects is an array-oriented Forth-like language. I've iterated on the idea several times, I think it's really great. Unfortunately, I have yet to capture the beautiful simplicity and elegance of Forth or APL in any of my projects. Prolog is another one of my favorites, you should check that out.
- codr4life 10y agoSecond Prolog, I have a feeling the same kind of fusing can be accomplished as with Forth. I've seen a couple of attempts, the most recent being in Clojure; but none of them hit the sweet spot for me. Logic by itself doesn't really help any one; but fused to a swiss army chain saw, it's very useful.
- tluyben2 10y agoI did my degree at UvA which is the home of SWI Prolog and I studied AI. But now you really upset my sore brain ;) I am going to say Mercury and then step away.
- stevedonovan 10y agoBack in the day (early 90s) there was something called ASYST which was indeed a array-based Forth on steroids. It had a nice library and could make plots interactively. It was not elegant ;)
- eggy 10y agoYou must be my long lost twin ;) I went from Basic, Assembly and then C to Lisp, Forth and then APL, well J [0], but then some APl (Dyalog). I have decided to do all of my work in either Lisp, Forth or J. I sometimes have to code in Python (there's always Hylang!), but all of my personal interest stuff is in the other three. I am currently going through the 4th edition of "Fractals, Visualizations and J", which is a great introduction to the J language and graphics. I am trying to make a livecoding (toplap.org) environment in J similar to oK, but more musical and with webgl shaders [1,2]. I'm convinced the proliferation of using GPUs, distributed processing, and multi-core CPUs are all a good fit for a true array or vector-based language like APL, J, and K. I get more of a functional high on J than in Haskell, and feel like I am writing Math equations after memorizing the 'words' of J, more like operators (nouns, adverbs, conjunctions, verbs, etc...) Shen is a great mix of Lisp and a typed (optional), lazy (optional) language with great pattern matching that has been implemented on a lot major programming platforms (Python, Ruby, JavaScript, Scheme, Haskell, Common Lisp, Clojure, JVM, and Emacs Lisp) because it runs atop a small set of 46 primitives called KLambda similar to the original Lisp 1.5. If you implement KLambda, and pass the tests, in a given PL, you can then run any Shen program on that platform [3]. [0] jsoftware.com [1] https://github.com/JohnEarnest/ok [2] http://johnearnest.github.io/ok/index.html [3] http://www.shenlanguage.org/
- tluyben2 10y agoI love Shen. Check the mailinglist (Google) you can see my name there months ago. I have my own implementation of KLambda and Shen which is faster than any of those on the site, I sponsored the open source license and bought and read both his books. However when Mark decided to make it closed again kind of for professionals and when I found his mindset is too different from OSS I stopped working on it. I am still sorry because I really like Shen. I might revisit that when I have more time because it is very nicely done. Not OSS for a programming language really does not work for me. I mailed and talked how to make money with OSS (I do...) and that a language bar Mathematica, Matlab, K/Q and Labview cannot be closed and paid. And to be one of those you need a niche and first mover clients. I had a first mover client to pay for OSS dev and libs but it never happened. So Clojure. Pun intended.
- deleted 10y ago[deleted]
- ioddly 10y agoThat's cool! I actually tried something like this myself, but ended up with a less conventional syntax. I'm not really familiar with Forth, but my impression from writing a little bit of postfix code was that some pattern matching would make e.g. writing a large conditional much easier.
- codr4life 10y agoForth is trivial to learn but takes serious effort to master, like Lisp and C. I'm a humble beginner myself when it comes to Forth. A match operator is a possibility, but too much of that will ruin all that's good about Forth. I already added word scoped variables, and I already feel like I'm balancing near the point of negative return.
- PeCaN 10y agoThat's something I'm working on, actually. I think matching the top stack item(s) fits well into a postfix stack-oriented language. For example: TYPE: Tree | Branch(Tree,Tree) | Leaf ; :: depth Tree -> Int ; : Branch($,$) depth {depth} dip depth + ; : Leaf depth 1 ; $ is extract, so the pattern Branch($,$) pops the top of the stack and pushes the 2 members. Types and type constructors have to start with a capital letter, but I like the : Pattern word definition ; syntax a lot.
- agumonkey 10y agoreminds me of jvtoups emacs-lisp stacking monad (IIRC)
- simplify 10y agoI strongly believe concatenative languages – particularly statically typed ones – are one paradigm of programming that have not been explored nearly enough. It's good to see more activity in this area :) Here's another interesting concatenative language in development that I'm following: http://kittenlang.org/ http://kittenlang.org/
- chubot 10y agoI dunno, it feels like Factor kind of exhausted it several years ago? I think the problem is that concatenative programming is super elegant for some things, and then falls on its face for others. In particular the object/class system of Factor was baffling to me. The paradigms just don't fit together well. I also think Lisp has an awkward object system(s). If you want that paradigm, I think a dedicated language is better.
- aidenn0 10y agoSomewhat OT, but I'm curious what you think is awkward about CLOS?
- cronjobber 10y agoSimple member access like object.foo.bar is apt to read more like this: (class2-bar-of (class1-foo-of object))
- junke 10y agoWhy not use simpler names? (bar (foo object)) I mean, I understand that "a.foo" (class A) does not represent the same name as "b.foo" (class B) due to scoping rules, and so logically you would have to use (a-foo a) and (b-foo b) if you wanted to replicate the same in CLOS. But on the other hand, FOO can be generic and applied to different types of objects. You might even have a mixin providing the FOO slot, which classes A and B inherit from. I find the notation fine, it looks like regular function application (some people prefer threading macros, I personally don't care). Note also that CLOS allows you to add code "between the dots" by specializing accessors on qualifiers (:before, :after, :around), which can be useful to add orthogonal things like logging, persistency, ...
- aesir 10y agoabc
- mondoshawan 10y agoSo, serious question: if the property of a concatenative language is the ability to pass outputs to inputs of a function without specifying parameters, could Iolang or Smalltalk also be described as concatenative? Ie: Transcript show: 'foo'; cr. In this case the output of "Transcript show:" is the Transcript object, which is used as the sender for cr.
- yorwba 10y agoThe property of concatenative languages is not the ability to compose functions without specifying parameters, but that this in the only way of building programs. Your Smalltalk example has a lot more special syntax going on, in a stack-based concatenative syntax it might be written as Transcript ' foo' show cr assuming appropriate primitive programs "Transcript", "'" (for literal quoting), "show" and "cr"
- kazinator 10y ago> I've been craving for a trivial, embedded scripting language that feels just right for a long, long time; something I can quickly drop into any project that needs scripting without too much ceremony. How are you quickly and casually going to drop in a scripting language into any project, if it requires Common Lisp? Maybe this means "into any CL project". But why would you need a scripting language in a CL project.
- deleted 10y ago[deleted]
- codr4life 10y agoThe idea doesn't really require Common Lisp; the same thing could be implemented in C with a bit more effort. But for me, any project mostly means Common Lisp as that's the first tool I reach for. I need a scripting language because exposing the full host language is not really scripting, pretending so is a cop out that always comes with unintended consequences. Given the right definitions, Forth reads like the kind of pseudo code most non-programmers would write; and the lack of syntactic fluff makes it a viable alternative for scenarios involving sequential processing, templating etc.
- 0xdeadbeefbabe 10y agoI've been wondering if they called the hp48g's forth ui lisp to avoid lawsuits.
- childintime 10y agoactually I'd like to see a (~16 bit) Forth backend for LLVM... so I don't have to "think RPN" myself. just load the binary into serial flash, point the interpreter at it, and of it goes.