9 comments to Forth, Lisp, & Ruby: languages that make it easy to write your own domain specific language (DSL)

  • Enki75

    Can you provide a link to the Cuneiform Transliteration Parser and Sign Frequency Generator?

    Could be of interest in the context of digital cuneiform analysis:
    1. Analyzing Handwritten and Transcribed Symbols in Disparate Corpora, and
    2. Multi-Scale Integral Invariants for Robust Character Extraction from Irregular Polygon Mesh Data

  • Assad Ebrahim

    Hi Enki, thanks for sharing your papers on using pattern recognition for automated drawing and transcribing of cuneiform tablets. Cool stuff!!

    To explain what I’ve built:
    Assuming that (a) the signs in the raw clay have been identified already (by a human or your program), and (b) a transliteration has been recognized for these signs, then the sign frequency generator can provide the distribution of individual signs with the transliterated text.

    It does so by scanning a transliteration downloaded file from the CDLI database which contains the set of tablets which are desired to be analyzed.

    If this is in line with what you’re looking for, drop me a note and I’ll share the sources ahead of the article that is in preparation on this topic.
    Assad-

  • Simon

    Interesting read.
    Just to note, Forth and Lisp are not the only ones to ‘do it’ out of the box.
    Tcl is the third major language that has exactly the same properties.
    Meta-programming is the Tcl idiom and it has more in common with Forth than Lisp does.

    Homoiconicity appears to be the key word here.

  • Assad Ebrahim

    Simon, you’re right, TCL is indeed another relatively simple language that makes metaprogramming easy. Amongst languages built for meta-programming (power), if we measure simplicity as the extent to which syntactic sugar (parentheses, braces) is required in the language’s specification, then TCL appears to be perhaps on a par with Ruby, with Forth the simplest that I am aware of (the only syntactic sugar is whitespace). Thanks for the comment!

  • Simon

    And thanks for the interesting article, although, I hope you’ll forgive me if I suggest that:

    It’s highly questionable whether simplicity is measurable through syntax alone (if it were then Smalltalk would belong in this article).
    Forth is certainly simple to ‘parse/interpret’, but there is, even according to Chuck Moore, some reasonable debate as to whether this makes things harder to comprehend as a result. It’s a trade-off.
    The real power-through-simplicity (beyond implementation) is found because all words can be arbitrarily composed and because it’s essentially typeless and point-free. The latter being, I would suggest, far more significant.

    Of course, there’s also a little sleight of hand, in that Forth does have symbolic words, that operate the same way as ‘syntax’. ‘:’ and ‘;’ for example. I agree it’s a somewhat blurry distinction, but nevertheless Forth does require a few words that serve the same syntactical purpose as you’d find in Lisp or Tcl.

    Also, it’s worth noting that Tcl has slightly less syntax than Lisp. You could get by in Tcl with nothing more than whitespace {}, “” and [].. even the $ sign is only sugar for the ‘set’ word/command, much in the same way ‘:’ or ‘” is used in Forth.

    As Tcl is itself a DSL of sorts, it, (similar to Forth), has no actual commands, control structures, logical operations, or in fact, anything at all. There is, like Forth, no core language directives. Ultimately Tcl is (at the theoretical level) *only* syntax / convention.

    Tcl’s notion is commands – Forth has words; strikingly similar. The only real difference is prefix vs postfix notion. (and of course, both Forth and Tcl can support the other n-fix, trivially, and do so.)
    Prefix is simpler to implement, but is it simpler to work with than postfix? ( I really don’t know)
    It’s the stack that really separates the two.

    Forth uses white space, Tcl uses \n to separate words and whitespace to separate values. (hence the need for {})
    It should also be noted that braces in Tcl, do not serve the same purpose as in other languages. They are still part of the ‘text’ of a program, all they do is prevent substitution. They do not, for example, describe block structure as one might find in C, or in () in Lisp.

    Tcl and Lisp *could* be argued to be simpler (meta-programming) languages because they are both homoiconic, Tcl perhaps the simpler of the two. Forth is not, and this is makes meta-programming a tiny bit harder. Tcl is certainly much simpler, and more internally consistent and much nearer to Forth than Ruby.

    There’s a lot of nuances in all of this.

    And finally, implementation. Given what I said above, Lisp is of course relatively complex compared to the other two.
    Tcl however, could be implemented as trivially (more so even) than a Forth. A handful of syntactic rules, and a basic command / fetch / execute loop, and you would have a mininal Tcl. The fact there is a canonical implementation of Tcl, is just an accident of history.
    But, maybe Forth just has the edge there.

    As for Ruby, nice language, though it is, it’s not even close to these three, syntactically or semantically. Surely it’s in the same broad group as Python, and has an entirely different objective. A decent scripting language, but lacks much of the above.

    Overall though, I can only agree with your general positive conclusions about Forth.

  • Assad Ebrahim

    Simon, thanks for the detailed analysis. Yes, you’re right, if we consider : and ; in Forth, these are indeed syntactic sugar elements corresponding to brackets in Lisp.

    I’m particularly intrigued by your comment on the ease of Tcl implementation. One of the attractions of Forth is that it is a relatively small language that can be implemented natively onto a microcontroller, after which one has no need in most cases for any other development tool or operating system and can rapidly prototype functionality within Forth itself. Presumably then Tcl should have a similar application…

    And indeed (courtesy of Google):

      ParTcl minimal interpreter
      Tcl integrated with special hardware
      Small TCL for hardware constrained devices
      TinyTcl for embedded applications
      Tcl and Arduino

    I had not had Tcl on my radar for embedded control applications — thank you for the insightful observations! Will be exploring this in the near future.

    Assad-

  • […] mathematical linguistics), biology (chaos theory, self-organizing systems), economics, finance, linguistics and fuzzy logic, and […]

  • […] 8: A low-level toolchain for x86: NASM (Netwide Assembler) and TCC (Tiny C Compiler) Chapter 9: Language-Oriented Programming: Forth, Lisp, and Ruby: Languages that enable solving your problem in …. Part 3: The Embedded Stack Chapter 10: Microcontrollers, Sensors, and Embedded Systems: Low-Cost […]

  • […] assembly language, while retaining the efficiency and elegant design of a high level language or domain specific language (DSL). Forth is lightweight, has some incredible capabilities, can be used for both low- and high-level […]

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Your comments are valued! (Please indulge the gatekeeping question as spam-bots cannot (yet) do simple arithmetic...) - required

Optionally add an image (JPEG only)

 

Stats: 1,066,417 article views since 2010 (March update)

Dear Readers:

Welcome to the conversation!  We publish long-form pieces as well as a curated collection of spotlighted articles covering a broader range of topics.   Notifications for new long-form articles are through the feeds (you can join below).  We love hearing from you.  Feel free to leave your thoughts in comments, or use the contact information to reach us!

Reading List…

Looking for the best long-form articles on this site? Below is a curated list by the main topics covered.

Mathematics-History & Philosophy

  1. What is Mathematics?
  2. Prehistoric Origins of Mathematics
  3. The Mathematics of Uruk & Susa (3500-3000 BCE)
  4. How Algebra Became Abstract: George Peacock & the Birth of Modern Algebra (England, 1830)
  5. The Rise of Mathematical Logic: from Laws of Thoughts to Foundations for Mathematics
  6. Mathematical Finance and The Rise of the Modern Financial Marketplace
  7. A Course in the Philosophy and Foundations of Mathematics
  8. The Development of Mathematics
  9. Catalysts in the Development of Mathematics
  10. Characteristics of Modern Mathematics

Electronic & Software Engineering

  1. Electronics in the Junior School - Gateway to Technology
  2. Coding for Pre-Schoolers - A Turtle Logo in Forth
  3. Experimenting with Microcontrollers - an Arduino development kit for under £12
  4. Making Sensors Talk for under £5, and Voice Controlled Hardware
  5. Computer Programming: A brief survey from the 1940s to the present
  6. Forth, Lisp, & Ruby: languages that make it easy to write your own domain specific language (DSL)
  7. Programming Microcontrollers: Low Power, Small Footprints & Fast Prototypes
  8. Building a 13-key pure analog electronic piano.
  9. TinyPhoto: Embedded Graphics and Low-Fat Computing
  10. Computing / Software Toolkits
  11. Assembly Language programming (Part 1 | Part 2 | Part 3)
  12. Bare Bones Programming: The C Language

Pure & Applied Mathematics

  1. Fuzzy Classifiers & Quantile Statistics Techniques in Continuous Data Monitoring
  2. LOGIC in a Nutshell: Theory & Applications (including a FORTH simulator and digital circuit design)
  3. Finite Summation of Integer Powers: (Part 1 | Part 2 | Part 3)
  4. The Mathematics of Duelling
  5. A Radar Tracking Approach to Data Mining
  6. Analysis of Visitor Statistics: Data Mining in-the-Small
  7. Why Zero Raised to the Zero Power IS One

Technology: Sensors & Intelligent Systems

  1. Knowledge Engineering & the Emerging Technologies of the Next Decade
  2. Sensors and Systems
  3. Unmanned Autonomous Systems & Networks of Sensors
  4. The Advance of Marine Micro-ROVs

Math Education

  1. Teaching Enriched Mathematics, Part 1
  2. Teaching Enriched Mathematics, Part 2: Levelling Student Success Factors
  3. A Course in the Philosophy and Foundations of Mathematics
  4. Logic, Proof, and Professional Communication: five reflections
  5. Good mathematical technique and the case for mathematical insight

Explore…

Timeline