Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 2e1b610af98e82d6f0fbe360bdc4615265c165c5
parent 86b2527c940d5905910b331830823499ef4565c8
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue,  8 Aug 2023 21:02:55 -0400


Aslides.adl | 274+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 274 insertions(+), 0 deletions(-)

diff --git a/slides.adl b/slides.adl @@ -0,0 +1,274 @@ +SIZE 1b,12 + +NAME Introduction +FILL 03 +GOTO 02,02 +MODE 0c +HEAD An Introduction +HEAD to the Forth +HEAD Programming Language +MOVE 02,04 +TEXT Alex Wennerberg + Welcome, thanks for coming + +NAME About +FILL 03 +GOTO 04,04 +TEXT This Talk +MOVE 02,04 +TEXT - Not directly useful +TEXT - Won't really teach you Forth +TEXT - Provides a new perspective on computing + + +NAME Quote +FILL 03 +GOTO 04,04 +TEXT "I've tried to brainstorm a different language. +TEXT A better language than Forth, and failed +TEXT completely. Far as I'm concerned, Forth is it. +TEXT Forth is the computer language, that everyone +TEXT should be using it. And it is a social tragedy +TEXT that they aren't." +TEXT - Chuck Moore (Creator of Forth) + This slide is for piquing your interest + +NAME Some Code +FILL 03 +GOTO 04,08 +TEXT ." Hello, World!" +MOVE 00,04 +TEXT : log2 ?dup not if abort then 32 for +MOVE 02,00 +TEXT >> ?dup not if 32 i - break then next ; + Two example Forth programs. + Hello world + Log base 2 of an integer. Don't worry about understanding it + +NAME Learning Forth +FILL 03 +GOTO 02,02 +TEXT Concatenative, stack oriented +MOVE 02,02 +TEXT y = foo(x) +TEXT z = bar(y) +TEXT x foo bar +MOVE 00,02 +TEXT 2 3 + . +TEXT 2 3 swap - . + Applicative programming language: what we are used to + Concatenative programming language: Forth + "all expressions denote functions, and the juxtaposition of expressions denotes function composition" -- Wikipedia + Basically, you put things next to each other, you 'concatenate' them + + "Relies on a stack machine for passing parameters" -> every word is a stack operation + Postfix notation. Instead of 2 + 3, we write 2 3 +. Lets break it down + 2 -> push to stack + 3 -> push to stack + + -> consume top two items on the stack, add them, push result to the stack + . -> pop top item of the stack, print to console + + swap -> stack operation. These are common in forth. + Break for questions + +NAME Fahrenheit and words +FILL 03 +GOTO 02,02 +TEXT Words +MOVE 02,02 +TEXT : washer wash spin rinse spin ; +TEXT : rinse fill agitate drain ; +TEXT 85 32 - 5 * 9 / +TEXT : f>c 32 - 5 * 9 / ; +TEXT 85 f>c + Let's provide a simple example. Fahrenheit to celsius + A word is basically the only programming language construct in forth. + Everything is a word (except numeric literals). "+", "swap", etc. + We can define our own words. + Break for Q's + +NAME fizzbuzz and loops +FILL 03 +GOTO 02,02 +TEXT fizzbuzz +MOVE 01,01 +TEXT : fizz ( n -- f ) +TEXT 3 mod not if ." fizz" 1 else 0 then ; +MOVE 00,01 +TEXT : buzz ( n -- f ) +TEXT 5 mod not if ." buzz" 1 else 0 then ; +MOVE 00,01 +TEXT : fizzbuzz +TEXT 1 100 for2 i fizz i buzz or not +TEXT if i . then nl> next ; + More complexity + How to solve problems with words + What is fizzbuzz + Break this down + IF -> IS a word! Control structures are not part of the language! Wow! + now you can get a job in forth + + +NAME Interpretation Loop +FILL 03 +GOTO 02,02 +TEXT Interpretation loop +MOVE 01,01 +TEXT begin word runword again +MOVE 00,02 +TEXT 1. Read a word from input +TEXT 2. Is the word in the dictionary? +TEXT ---> execute, go to 1 +TEXT 3. Is it a number? +TEXT ---> push number to the stack, go to 1 +TEXT 4. else, print "word not found", go to 1 + Forth is an OS/Language + This is what happens when I boot a forth environment. Language/OS + Forth is an interpreted language, basically. It reads text input one at a + time via the interpretation loop + +NAME Comments +FILL 03 +GOTO 02,02 +TEXT Implementing comments +MOVE 02,02 +TEXT : \ begin in< 1+ $21 < until ; + One example of forth's "magical" simplicity -> Comments are just a word + This is it! Think about how Golang implements comments. About 150 lines of code. + Scan -> parse -> tokenize -> Build AST -> compile + An attitude towards simplicity + Skepticism towards complexity + Maybe programming doesn't have to be complex + TWO POINTS -- Forth's SIMPLICITY and its ability to build abstractions quickyl + +NAME Tiny Forths +FILL 03 +GOTO 02,02 +TEXT Small Forths +MOVE 02,02 +TEXT Forth is really, really simple +TEXT - A 3-instruction forth in 66 bytes +TEXT - Sectorforth 10 code words, 512kb +TEXT - UXN -- machine forth in 98 lines of C +TEXT - Dusk OS 10k LOC 32-bit OS +MOVE 00,01 +TEXT "Forth has the simplest syntax and therefore the +TEXT simplest parser, interpreter, and compiler ever +TEXT used in a "mainstream" general-purpose +TEXT programming language." + Is not just its simplicity, but its ability to build abstractions + +NAME Abstraction +FILL 03 +GOTO 02,02 +TEXT Abstraction +MOVE 02,02 +TEXT - Build abstractions quickly +TEXT - Don't hide from 'lower' layers +TEXT : :c cctok$ nextt cparse ; +TEXT S" //" s= of drop begin ( ) +TEXT ccin dup not if ( EOF! ) rdrop exit then +TEXT ?line+ LF = until +TEXT nextt? endof +MOVE 00,01 +TEXT dusk C -> 1.4k LOC +TEXT tcc -> 30k LOC + +NAME Idiolect +FILL 03 +GOTO 02,02 +TEXT "Forth is the coinage of words. Each Forth +TEXT program thereby breaks loose from the continuum of +TEXT the history of Forth. In consequence, however, a +TEXT growing Forth program would tend to absorb its own +TEXT dictionary of primitives into its expanding store +TEXT of neologisms, until the system itself would +TEXT barely resemble any other so constructed. It is as +TEXT if all "human natural languages" were to be +TEXT absorbed into their speakers' idiolect" + +Points here: +- Forth is non-standard +- Every forth is different +- Software companies as large institutions that want the same standards +- Forth hasn't succeeded for this reason +- Forth requires rethinking how we work, and how + we work together. + + +NAME Endless Abstraction +FILL 03 +GOTO 02,02 +TEXT "Preventing the Collapse of Civilization" +TEXT Jonathan Blow +MOVE 00,02 +TEXT - Building towers of abstraction +TEXT - Losing foundational knowledge +TEXT - Unsustainable levels of complexity + As engineers, we love abstractions, we love + making it so we "don't have to" think about + underling systems. There is a danger here. + +NAME Conclusion -- Felix Winkelmann +FILL 03 +GOTO 01,01 +TEXT "[Forth] is not a language for writing meaningless +TEXT abstractions on top of other meaningless +TEXT abstractions, or for writing a library that solves +TEXT a specific problem in the most possible general +TEXT way, using that fancy algorithm or data format +TEXT that happens to be hip today. [...] It requires +TEXT out-of-the-box thinking and a lot of thought, but +TEXT rewards you with something that stands a better +TEXT chance of not being just another pile of code that +TEXT barely works, quickly rots, or ends up being a +TEXT liability that you regret having ever written and +TEXT that has grown to a point where rewriting or + +NAME ctd +FILL 03 +GOTO 01,01 +TEXT replacing it becomes harder and harder. +TEXT Writing "good" Forth code is very hard, [...] it +TEXT requires an additional effort to simplify your +TEXT code to a point where everything becomes obvious. +TEXT This is an art, it is a moment of transcendence, +TEXT which I don't claim to have ever reached, but +TEXT sometimes I get a glimpse of it, an inkling of the +TEXT fact that if I would work very hard on this, it +TEXT will become so simple, so heavily factored, using +TEXT such obvious and clear names that everything just +TEXT falls into place. It is this moment that +TEXT programmers experience every once in a while, + +NAME ctd2 +FILL 03 +GOTO 01,01 +TEXT where a short, simple piece of code just does what +TEXT it is supposed to do, without any extra baggage, +TEXT easily understandable. To achieve it in Forth is +TEXT much harder, it may require more time, many +TEXT rewrites, but the results are even more +TEXT satisfying, as the result is smaller, much +TEXT simpler, fully self-contained and not burdened by +TEXT code that you can not trust. When you forget about +TEXT that urge of productivity, which has become the +TEXT moloch we sacrifice our children to, you may be +TEXT able to achieve that particular thing that is +TEXT called quality, elegance, art. It may take a + +NAME ctd3 +FILL 03 +GOTO 01,01 +TEXT lifetime, you may never reach that far, but still +TEXT you should strive for it. Or you remain a +TEXT cog in the machine, developing on absurdly +TEXT convoluted "software stacks", using inadequate and +TEXT brittle languages, connect barely matching +TEXT interfaces to only small parts of too many bloated +TEXT libraries, using insanely sophisticated tools of +TEXT incomprehensble complexity and trot on, asking +TEXT yourself why everything sucks and why the last +TEXT time you actually enjoyed programming and were you +TEXT could be genuinely and deservedly proud on what +TEXT you accomplished, was when you were a kid...