lainchan / λ
FORTH
array · 2017-04-13 04:20
Welcome back, /λ/! Let's talk about FORTH. The language of true beauty.
What do you like about FORTH?
What do you use it for?
What are you working on?
What flavor do you like most?
What implementation do you use?
What domain do you find the language useful for?
What do you think the future will hold for FORTH?
Nanashi No Gombe · 2017-04-13 04:50
>>41
It's nice to see this thread back.
>What do you like about FORTH?
I like the simplicity, different approach to metaprogramming, and the stack discipline.
>What do you use it for?
>What are you working on?
Unfortunately, I can't say much in this respect currently. I find ANSI Forth annoying and haven't yet moved to a machine forth due to being busy.
It can be useful for writing low level software in memory constrained environments, as threaded code is typically quite compact and I'd use it in an embedded project if I couldn't squeeze more room out of the silicon through other means.
>What flavor do you like most?
I very much like the concepts I see in colorForth. With that written, it would probably be easiest to use a machine forth when I'm doing something. Unfortunately, it's easy to be torn between pure native code and Forth, which is why I find the F18A so alluring, as there's then no difference.
>What implementation do you use?
I currently use Gforth, but it typically just sits waiting for input. I've noticed that, compared to other languages, Forth doesn't fare as well as a calculator. To add to that, I have HP calculators, so my quick stack machine use is consumed entirely by those.
>What domain do you find the language useful for?
I see it most useful in the context of extreme memory limitations where speed isn't also as critically important and machine environments where a simple stack machine layer makes it much more approachable. I'd much rather use a Forth layered over x86(_64) than the machine directly, as an example.
>What do you think the future will hold for FORTH?
I wonder what Chuck Moore will think of next.
I'd like to see the F18A find more use and so become easier to play with cheaply. It's some very novel ideas and I think Forth may find itself primed for parallel computation with this direction in the future.
Leto Atreides I · 2017-04-15 20:28
Are there libraries for algebra (or at least vector manipulation) ready to use in FORTH that you'd recommend?
Vasya Pupkin · 2017-04-16 22:48
>What do you like about FORTH?
I can have a language powerful and a complete understanding of all it's functioning. How awesome is that?
>What do you use it for?
I made a bulls and cows solver, going to use it for a uni exam, and various FUN.
>What flavor do you like most?
The minimal: the better. I like the complete explained Jonesforth. Never tried the interesting colorForth.
>What implementation do you use?
gForth on PC and Android.
>What domain do you find the language useful for?
When you want to do a project, Forth give you full power.
>What do you think the future will hold for FORTH?
I don't think it will ever be famous.
Also, Factor is like kicking dead whales down the beach.
Tank · 2017-04-17 10:12
>>323
The Forth Scientific Library is an old effort and it probably does contain that, yes.
What do you need this for? Rather than use a library, it may be better to muse on the problem until the operation isn't required in that way.
Morpheus · 2017-04-17 10:30
>>323
>Are there libraries for algebra (or at least vector manipulation)
vector manipulation in a language where all data is hand manipulated on a stack, Id really love to see all the dupping and swapping to handle nested matrices
Cypher · 2017-04-17 10:37
>>406
Thanks, I'll look it up. I'd like to do some ML stuff, at the very least matrix-vector multiplication, dot product and such would be handy to have ready. For more advanced algorithms I'd need eigenvalue extraction and possibly some decompositions, but that's not an issue for the moment at least.
>>407
It sounds pretty bothersome to implement, aye.
nibble · 2017-04-17 14:45
>>407
>Dupping and swapping pointers
Where is the problem?
Forth problems (and joy) are not in the stack, are in the fact that you have to implement data structures yourself.
if · 2017-04-17 14:51
Made from scratch, surely there is better
marker lib ." Loaded "
: array ( dim — )
create dup , cells allot
does> ( n array — *array[n] )
swap 1+ cells + \ Array starts at 0, -1 is the length
;
: length -1 ;
: coords-matrix ( x y matrix — *matrix[x, y] )
swap over @ * rot + 2 + cells +
;
: matrix ( width height — )
create dup , swap dup , * cells allot
does> ( x y matrix — *matrix[x, y] )
coords-matrix
;
: width -1 0 ;
: height -2 0 ;
: matrix> height ;
: init-matrix ( matrix -- )
dup @ 0 ?do ( matrix )
dup 1 cells + @ 0 ?do ( matrix )
0 over i j rot coords-matrix !
loop
loop
drop
;
: .matrix ( matrix -- )
cr
dup @ 0 ?do ( matrix )
dup 1 cells + @ 0 ?do ( matrix )
dup i j rot coords-matrix ?
loop
cr
loop
drop
;
Von Neumann · 2017-04-17 15:19
>>423
Pretty much, the philosophy behind forth, afaik, is that you write your program directly tailored to the problem at hand, instead of relying on a bunch of code that you're not going to use out of a library, or code that is too general and not optimized to your particular application.
Nobody important · 2017-04-18 01:56
>>425
>philosophy behind forth, afaik, is that you write your program directly tailored to the problem at hand, instead of relying on a bunch of code that you're not going to use out of a library,
this seems to be less a philosophy and more of symptom of a lack of forth libraries and the fact that forth code tends toward becoming unresuable non portable
forth is and will always be a glorified assembler
Gyula Kovacs · 2017-04-18 14:19
>>458
Well I say philosophy because all this is no accident. Charles Moore made the language for his own use, and at's how he thinks ideal software is written.
Forth's philosophy is against complexity, the smaller the language the better. That's why Moore dropped ANSI Forth.
And yes, it's an assembler on steroids, that's the intended nature of it.
progn · 2017-04-26 21:21
Forth seems really neat, judging from this thread.
Besides learning the language itself a bit, how would I get started playing around with forth and some controllers, assuming I don't have any hardware yet.
Sorry for this absolute beginner question.
Can I just "export" my Forth program to a teensy or arduino? Which tools (besides the hardware itself) would I need? Is gforth enough?
Cowboy · 2017-04-26 22:40
>>759
There are forth projects for the arduino, one of them I think is called Forthduino. Use your favorite search engine.
Gforth is nice for learning the language. In my case, I am solving project euler challenges to learn the language. I think numerical problems are particularly well suited for the language. Or you can retend you're programming spacecraft for NASA and make a planet landing simulation.
However, I don't think it (gforth) is much in the spirit of Forth. In FreeBSD it requires gcc.
I think Forth is at it's best implemented directly in the machine language of the target processor. If you find arduino forth projects, I suggest you find one implemented in assembly.
Apoc · 2017-04-26 23:51
>>760
I see, so I use the appropriate Forth implementation. Thanks, lainon.
Some interesting posts I found:
https://hackaday.com/2017/01/27/forth-the-hackers-language/
https://hackaday.com/2017/04/19/moving-forth-with-mecrisp-stellaris-and-embello/
Seems like amForth is popular on the Arduino, as it uses a ATmega328P style microcontroller.
Nobody special · 2017-04-27 00:02
>>762
>Let’s start right off with a controversial claim: Forth is the hacker’s programming language.
Wholeheartedly agree. Thanks, I'll be giving these a read.
Switch · 2017-04-27 16:31
>>759
I'd suggest getting started with eForth (https://hackaday.io/project/16097-eforth-for-cheap-stm8s-gadgets) for STM8 microcontrollers. There are many different realizations of these devices, most of them are dirt cheap. And the interpreter itself is only 5000 lines of asm code, so you can completely understand how it works and even write your own from scratch. If you want a more powerful platform based on a more popular architecture, nintendo GBA looks pretty interesting. It has a powerful 17MHz ARM CPU, almost a half MB of RAM in total and a 240x160 LCD screen. You can use an emulator to start tinker with it, VBAM for example. It works great and even has a built-in convenient debugger.
Agent Jones · 2017-05-03 05:59
>Articles, Books, Implementations, etc
Easy Forth
https://skilldrick.github.io/easyforth/
Minimal FORTH compiler and tutorial
http://lambda-the-ultimate.org/node/2452
Buzzard Forth
http://www.ioccc.org/1992/buzzard.2.design
My history with Forth & stack machines
http://yosefk.com/blog/my-history-with-forth-stack-machines.html (HN Discussion: https://news.ycombinator.com/item?id=1680149)
Forth index
http://www.ultratechnology.com/forth0.htm
A Beginner's Guide to Forth
http://galileo.phys.virginia.edu/classes/551.jvn.fall01/primer.htm
Forth Warrior
https://github.com/JohnEarnest/Mako/tree/master/games/Warrior2
Mark 1 FORTH Computer
http://www.aholme.co.uk/Mk1/Architecture.htm
Advanced Forth Programming Topics
http://www.mosaic-industries.com/embedded-systems/sbc-single-board-computers/freescale-hcs12-9s12-c-language/instrument-control/forth-language-program-development
Concatenative Programming
http://concatenative.org/wiki/view/Front%20Page
Programming with a Differentiable Forth Interpreter
https://arxiv.org/abs/1605.06640
I wrote a Forth implementation for x86
http://davazp.net/2012/12/08/eulex-forth-implementation.html
MOVING FORTH
http://www.bradrodriguez.com/papers/moving1.htm
Stack Computers: the new wave
https://users.ece.cmu.edu/~koopman/stack_computers/index.html
Thinking Forth
http://thinking-forth.sourceforge.net/
Starting FORTH
https://www.forth.com/starting-forth/
comp.lang.forth
https://groups.google.com/forum/#!forum/comp.lang.forth
comp.lang.forth.repository
http://forth.sourceforge.net/
Forth Interest Group
http://www.forth.org/
Let's Build a Compiler: Tiny Kiss in iForth
http://home.iae.nl/users/mhx/crenshaw/tiny.html
Why Forth
https://bernd-paysan.de/why-forth.html
John Titor · 2017-05-03 06:32
Why does the Forth repl always duplicate the input? It's bloody annoying:
: sqr dup * ;
: sqr dup * ; ok
2 sqr .s
2 sqr .s <1> 4 ok
x<->y · 2017-05-03 12:12
>>896
It doesn't. Looks like you're using a terminal with the echo option turned on.
Kay · 2017-05-04 04:01
>>898
Not a terminal but Emacs via M-x run-forth. I'll inspect further.
Tequila · 2017-06-17 04:44
Bamp
I am trying Factor right now, it's really different from Forth in every aspect you could think of.
But I guess it can be related to Forth because of it's heritage. It is actually pretty nice if you can get over the fact that it doesn't really follow Forth philosophy. It took me about an hour to compile the whole thing, and it's full of features.
However, it is quite a nice forth-like language to use for common tasks, and it draws heavily from functional languages. It has words for currying and other combinators.
Here's an example from a tutorial[1] I'm reading:
: prime? ( n -- ? ) [ sqrt [2,b] ] [ [ multiple? ] curry ] bi any? not ;
the [ ] words are somewhat different from Forth, they create something like lambda functions. The 'curry' word makes a sort of 'closure'. The word bi is another combinator.
It also has a sort of weak "type checker" on the stack effects comment to check that the number of inputs and outputs is consistent with the definition. The comment is mandatory in the definition.
I guess overall it is pretty nice but it does feel a bit off to have such a big Forth-like language. I guess you could say it's to Forth as C++ is to C (and it's written in C++ heh)
[1] https://andreaferretti.github.io/factor-tutorial/
x<->y · 2017-06-17 05:56
>>46
>I wonder what Chuck Moore will think of next.
Is he still around? colorforth.com (his personal website) has been down for over a year, and greenarrays.com hasn't had any updates either.
Dozer · 2017-06-17 10:38
>>1849
I tried Factor, but I found it unnecessary verbose. The beauty of Forth it's also its minimalism.
I also like C more than C++, so you got a point.
drop · 2017-06-17 23:48
>>1855
I agree, Factor feels really verbose and, at least in the tutorial they suggested using combinators instead of stack manipulating words. Which ended up being... quite complex, and in my experience that diverges *a lot* from Forth style.
x<->y · 2017-06-28 05:12
There's a discussion on HN right now about the Canon Cat, a personal computer with an OS written in forth that was marketed as a word processor.
https://news.ycombinator.com/item?id=14650365
Zero Cool · 2017-11-21 06:46
So, I've been strongly considering buying a GA144 development board for a time now. It all seems so nice and simple and so different from everything else.
Do any of you have real experience with it and could tell me what you think of it? What do you use it for?
Gyula Kovacs · 2017-11-21 21:01
>>5161
I bought the GA144 breakout board from Schmartboard. I forgot to get a 1.8V regulator so I could power it, so it's currently just sitting in a box somewhere until I build/make/get one.
My current plan is to get it to read in serialized data from an OV7670 and do some kind of processing - maybe OCR? I haven't looked too much into GA144's capabilities, but to me, it seems like the perfect processor to use for image processing.
The Plague · 2017-12-08 11:22
bump
Just another Random Lainon · 2017-12-12 15:45
I spent some minutes trying to understand the basic and creating some programs, but the language is complicated as hell.
Is there any reason to use it in a environment with plenty of RAM memory and fast processor like any modern smartphone or computer?
I mean, it does make sense using it in a volcano sensor or in a space shuttle, but why to use it when memory is not scarce?
Dozer · 2017-12-12 16:42
I'll just leave this here.
http://pelulamu.net/ibniz/
Anonymous · 2017-12-12 19:37
>>5609
It's cool and you learn memory management.
The only thing I miss is graphic capabilities.
push · 2017-12-12 19:56
>>5609
The FreeBSD loader https://man.freebsd.org/loader(8) is ANS FORTH. Surely you can appreciate the value of using FORTH to troubleshoot boot problems.
Plus, you use it because is cool, and you want to be cool. Like me. I am cool.
nibble · 2017-12-13 10:21
>>5613
>>5612
Does it make sense make my own Forth implementation for using in my programs? Like the neckbeard master did with EmacsLisp in Emacs.
More specifically, for using inside mobile/Android applications. I dislike every attempt of scripting in Android programs, all of them are heavyweight and bloated. Implementing a minimal Forth seems a reasonable alternative.
John Rain · 2017-12-13 12:41
>>5627
Creating a domain-specific implementation language atop a framework is a time-honoured technique, it's certainly not unique to Emacs.
Elliot Alderson · 2017-12-13 16:08
>>5629
Of course, there's Lisp for Autocad, and lots of usages for Lua and etc.
I'm still wondering about creating a Forth that compiles for Dalvik bytecode. Is there some guide on how to create a Forth implementation?
Lukasiewicz · 2017-12-13 18:42
>>5630
>I'm still wondering about creating a Forth that compiles for Dalvik bytecode.
I don't think that'd make too much sense. Dalvik itself is a register-based VM, so basically you're talking about implementig a stack-based VM on top of two register-based ones.
>Is there some guide on how to create a Forth implementation?
Here: https://github.com/AlexandreAbreu/jonesforth It's for the i386 IS, but you can adapt it for any RISC machine pretty easily.
vector · 2017-12-13 21:18
>>5627
gforth for android is pretty cool and it works fine if you want to run some code
Batou · 2017-12-13 21:53
>>5633
Can I generate ARM assembly code "on the fly" from a normal Android application made in Java or Kotlin and execute it???
Will it be compatible between different devices????
Incognito · 2017-12-13 21:57
>>5639
I want it to be embeddable, I want to have the similar feature that you achieve by allowing to script C/C++ programs with Lua.
That's why I thought about generating Dalvik's bytecode, it'll operate at the same level of the host application.
Vasya Pupkin · 2017-12-13 22:02
>>5633
Or maybe I can simply interpret the source code on the fly, I don't think that the performance will be that horrible since the grammar will be very simple to parse.
The Phantom Phreak · 2017-12-14 01:36
>>5642
parse? you just have to separate tokens by whitespace, then you just perform the actions sequentially. The beauty of forth
typedef · 2017-12-14 09:19
>>5643
There is "parsing" (very simple, just to separate tokens by whitespace and valitade words and numbers), but there is no "grammar" indeed.
Hiro Protagonist · 2017-12-14 18:20
fuarrrk.
I thought this language was some silly meme, but after learning it a bit I'm in love with this thing.
Even if I'm completely unable of writing any useful program with it.
Joey · 2017-12-14 20:42
By the way, for those of you who can't seem to fathom doing mundane tasks in forth, here's a very good (IMO) video that shows a simple application of the language.
Enjoy.
https://www.youtube.com/watch?v=mvrE2ZGe-rs
Hopper · 2017-12-14 20:52
>>5659
It's pure magic.
Tomohisa "Tom" Kanezaki · 2017-12-22 21:45
Hey lainons, this post >>5659 got me really into forth and it's wider philosophy, so I'm now making a simple editor for my own use (I heard Chuck Moore say that everyone should write their own editor in a lecture about colorforth, what a madman).
I'm using ncurses for the interface, but find that I'm constantly forced to write:
s\" blahblah\0" drop
whenever I want to get a c-style string to pass to any c function.
I imagine it should be possible to make a macro/immediate word to simplify this process, but I have no idea how I'd do it. Could a lainon help me with this and point me to a good tutorial on writing immediate words?
Thanks.
Dox · 2017-12-22 22:40
>>5798
Amazing, please share your code after it's complete.
Moore · 2017-12-22 23:06
>>5800
Sure lainon, I'll put up a git if it reaches the point where I use it as my main driver.
I'll warn you that it's meant to be highly personalized and little care will be given for easy configuration and that kind of thing. I was even considering of making a JIT compiler (compiling a purpose built forth) just for this specific purpose, but I'll stick with gforth for now I think.
You'll be more than free to look at and reuse the code tho.
Six · 2018-03-19 07:57
This thread should not die.
queue · 2018-03-21 17:01
Hey all,
Ran across this post a while back concerning a formal representation of concatenative functions
https://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html
I'm curious if anyone maps things out mathematically before typing away. Especially with Forth. Charles Moore seemed a little notorious for eschewing theory for practicality.
Cat Mother · 2018-03-28 08:31
Learning how to use Forth as an Algol-like language is not that difficult.
The problem is getting a deep understanding of compilation/interpretation semantics, and the postpone/immediate words... I'm wondering how to write macros in Forth, but it's very difficult to master those concepts.
Can anyone help me?
fsociety · 2018-03-28 19:29
>>7508
>Learning how to use Forth as an Algol-like language is not that difficult.
Why would you want to use it like that?
>The problem is getting a deep understanding of compilation/interpretation semantics, and the postpone/immediate words... I'm wondering how to write macros in Forth, but it's very difficult to master those concepts.
>Can anyone help me?
An immediate word is simply executed when it's encountered; just think of it as arbitrary compile-time computation, which is how metaprogramming generally works. All postpone does is compile the action a word would do, so it does it later.
What kind of macros are you trying to write? You really only need to write a word that performs the calculations and places the result in the appropriate location.
Spike Spiegel · 2018-03-28 21:10
Just out of curiousity, have there ever been any project in transpiling Forth to a more popular language? I know that there was something (out there somewhere) that transpiled Forth to C, but what about asm.js or webassembly? Would that even be possible?
In my mind, the Forth system would have to be given a file with Forth-ish syntax that it would then translate into the necessary output for whatever the target was.
藤原純一 · 2018-03-29 06:46
>>7522
>Why would you want to use it like that?
This is just a step in the learning curve, get used with the syntax, stack and etc., not the final goal.
Ivan Horvat · 2018-03-29 06:47
>>7522
>what kind of macros are you trying to write?
I want to write a macro for performing a short-circuit or/and.
Void · 2018-03-29 07:58
>>7535
>This is just a step in the learning curve, get used with the syntax, stack and etc., not the final goal.
Alright.
>>7536
>I want to write a macro for performing a short-circuit or/and.
So, you should look at how, say, the case immediate word is programmed to get an idea of how to use this. I'll assume you want to use it like this; let's call it & since this is Forth and and is already taken:
: word one & two & three & four ;
I suppose the chain would be prematurely broken if any of these words placed a value indicating failure on the stack.
Now, the first thought that comes to mind is, of course, how to do this simplest. You could simply write an immediate word which writes an if and return and else and all of that, but why bother doing that when you could define & like this, instead:
: & if rdrop then ;
So, this & will accept a test and either return to allow the chain to continue or return from where the calling word would return. You can implement an or (why not call it ^) similarly and simply enough. Wouldn't you agree this is more elegant?
Unknown · 2018-03-29 08:06
>>7538
I didn't get the "rdrop". Can you explain me what will happen if you discard the top element from the return stack?
Erik Johansson · 2018-03-29 08:13
>>7538
I've tested here, you should put a "invert" for the &&, and leave it as it is for the ||
: & invert if rdrop then ; ok
: | if rdrop then ; ok
Unspecified · 2018-03-29 08:22
>>7540
>>7539
>>7538
Lesson 20 Data on the Return Stack >R R@ R> 2>R 2R@ 2R>
You will occasionally find it convenient to be able to put a stack item temporarily in another place. "Another" place is the return stack. Your Forth almost certainly uses the return stack for its own purposes, so your use of the return stack must follow certain rules:
Data put on the return stack must be taken back within the same word.
Data put on the return stack outside a ?DO (DO) ... LOOP (+LOOP) cannot be accessed within the loop.
Data put on the return stack within a ?DO (DO) ... LOOP (+LOOP) must be taken back before leaving the loop.
Data cannot be on the return stack when executing I or J in a loop.
In the following descriptions of return stack words, ( S: ... -- ... ) shows the (data) stack effect
( R: ... -- ... ) shows the return stack effect.
>R ( S: x -- ) ( R: -- x ) moves x from the stack to the return stack.
R@ ( R: x -- x ) ( S: -- x ) copies x from the return stack to the stack.
R> ( R: x -- ) ( S: -- x ) moves x from the return stack to the stack.
2>R ( S: x1 x2 -- ) ( R: -- x1 x2 ) moves x1 x2 from the stack to the return stack.
2R@ ( R: x1 x2 -- x1 x2 ) ( S: -- x1 s2 ) copies x1 x2 from the return stack to the stack.
2R> ( R: x1 x2 -- ) ( S: -- x1 x2) moves x1 x2 from the return stack to the stack.
I'll use return stack words in future lessons. The uses will simplify coding. You won't find anything like this:
\ pascal.f
\ Pascal's Triangle
: POSITION ( row -- ) CR 33 SWAP 2 * - SPACES ;
: PAS ( 0 ... 0 -- 0 ... 0 )
0 >R
BEGIN OVER + >R DUP 0= UNTIL
BEGIN R> DUP WHILE DUP 4 .R REPEAT ;
: PASS ( -- )
0 1 0
13 0 ?DO DUP POSITION >R PAS R> 1+ LOOP DROP ;
: PAX ( 0 ... 0 -- ) DROP BEGIN 0= UNTIL ;
: PASCAL ( -- ) PASS PAX ;
BYE
Batou · 2018-03-29 08:25
>>7541
A note of caution: since the rstack is critical to execution we mess
with it at our peril. If we use the rstack for temporary storage we
must restore it to its initial state. A word that places a number on
the rstack must remove it —using R> or RDROP (if it has been defined)
— before exiting that word. Since DO...LOOP also uses the rstack,
for each >R folowing DO there must be a corresponding R> or RDROP
preceding LOOP. Neglecting these precautions will probably crash
the system.
RDROP is not an ANS Forth word that can be assumed predefined on any system.
Since it is not Standard, some systems call it R>DROP (which also is not
Standard). Here is its definition if needed:
: RDROP ( or R>DROP) ( r: n -- ) R> DROP ;
Erik Johansson · 2018-03-29 08:33
>>7539
>I didn't get the "rdrop". Can you explain me what will happen if you discard the top element from the return stack?
So, since the return stack is used as the return address, the & will either return to where it was called or where the word that called it was called, achieving a premature return.
>>7540
>I've tested here, you should put a "invert" for the &&, and leave it as it is for the ||
I didn't know which way you wanted it, but, yes, it's simple enough to change however you want.
>>7541
You'd want to be careful you use this correctly, yes.
>>7542
Alright; it's been so long since I've played with ANSI Forth that I'd forgotten this detail.
I'm glad I was able to help.
Pulse · 2018-03-29 08:56
>>7543
>So, since the return stack is used as the return address, the & will either return to where it was called or where the word that called it was called, achieving a premature return.
Very neat trick, mah boy, now I got it.
Now that this thread got attention: do you lainons learn/use Forth just as a "hobby" (it's very fun coding in Forth) or do you do serious work with it?
Is it pratical to use at a high application domain level? Most of its successful case stories I've read are for embedded systems.
bit · 2018-03-29 09:02
>>5801
Hi, anon. Are you there?
Motoko Kusanagi · 2018-03-30 01:48
>>7545
Yeah, thanks for asking.
I've been a lot of neat stuff in Forth lately, but have kinda of put off VLED (Visual Line EDitor) for a while now.
I'm running a Forth Discord server. It's a bit slow now, but we've had some good discussions there. I'll post an invite if someone asks
pic related
Y.T · 2018-03-30 01:50
>>7555
>>7544
I don't really like the way that anon did it, because it'll skip over to the end of word being compiled, not to the last &. Still a neat trick tho.
>>383
pic related inspired by this post
Turing · 2018-03-30 01:52
>>7556
That's pretty much all I've written in the last few months. maybe it isn't that "neat" kek
Debbie Charteris · 2018-03-30 10:03
>>7557
Is this your text editor, or it is Vim?
I'm longing for see the whole code on github.
Donna Hawthorne · 2018-03-30 15:45
>>7575
Nope, I haven't really been working on my editor lately. Still just a prototype.
fuarrrking admins, which rule did I break? >.>
array · 2018-03-30 16:10
>>7595
You should upload the current state of the source somewhere. How big is it so far?
You should ask that question in /q/. I won't explain here.
Joe Bloggs · 2018-03-30 16:14
>>7597
It's around 150-200 LOC ig. I haven't uploaded it anywhere cuz it's fuarrrking abysmal code iirc.
I'll take another look at it to see if it's any good.
I was just sperging out a bit, I don't blame you for cleaning up the thread a bit, it's better this way
dictionary · 2018-03-30 16:20
>>7598
>>7597
soykaf isn't even booting up properly now. Maybe I'll work on it tonight and then post a git.
Here's the linked list "library" I wrote for it tho. I prefer to define structs in Forth by simply writing the functions to create and work on them. I find the usual structure word to be kinda useless.
Hououin Kyouma · 2018-03-30 17:38
>>7599
>cons
>car
Are you using some garbage collector?
Crash Override · 2018-03-30 17:49
>>7601
??? no
I just prefer using those names to refer to links in linked lists. I started as a lisper and those names are pretty short but quite unambiguous. I don't see why you automatically associate cons with garbage collection.
Dox · 2018-03-30 17:53
>>7602
Because when you extract a list's tail and discard the head, that node's reference will be lost, etc.
over · 2018-03-30 17:57
>>7603
that's why I used allocate instead of allot...
I haven't implemented it yet, but you can just call free on an address allocated by allocate and it'll free it. I just need to go back and make sure free is called when removing a cons.
Neo · 2018-04-05 05:56
>>7690
>>7690
Don't lose hope. Forth is hard as hell but you can learn it by being insistent. I also felt dumb for Forth, but after learning it it's a joy.
Turner · 2018-04-05 15:51
>>7692
>but after learning it it's a joy.
I see what you did there.
Anonymous · 2018-04-06 08:48
>>7699
Oh... It wasn't intentional...
Wintermute · 2018-04-06 08:58
>>7711
Umm... I don't get what you did there can you explain it?
Lord Nikon · 2018-04-06 13:07
>>7712
> I also felt dumb for Forth, but after learning it it's a joy.
There's a Forth inspired language called "Joy" that claims to be a better Forth.
I didn't remember it when I wrote the post.
Joe Bloggs · 2018-04-06 18:41
I've dabbled in FORTH years ago (mostly gforth, but also some factor). What always bugged me about gforth is how it's datatypes don't correspond well to the capabilities of modern CPUs. Everything being essentially a 16 bit integer isn't as useful if you have a 64bit CPU with FPU and SIMD registers.
So is there a "modern day" FORTH that actually has extra stacks for floats, matrix math on SIMD, etc...
What also bugged me is the global dictionary of ANS FORTHs, that is also someway dated imo.
Hagbard Celine · 2018-04-06 19:24
>>7719
All ANS Forth's have a separate floating point stack, including gforth.
Not sure what you're talking about when you mention 16 bit integers, gforth uses whatever cell size your cpu works on, maybe it didn't when you used it tho, idk.
You should really take another look at gforth, it has come a long way since you used it.
And yeah, ANS Forth was outdated when it was created. You shouldn't limit yourself to ANS Forth. The Forth way is to create a highly specialized Forth for your application and hardware, that's why Chuck hates ANS Forth.
Creating your own Forth is also a trivial task. Many Forth interpreters+compilers come in at less than 1kb. I really think everyone Forther should write their own Forth at least once.
BloodCat · 2018-04-06 19:36
>>7722
The 16bit integer thing I may have been remembering wrong. I can have a look what's up during the weekend.
Writing my own forth is an idea, although I would probably go away from ANS Forth on the PC.
More in the direction of Machine Forth on a STM32F103. Can run over a usb serial console.
I always wanted a device costing $1 that can compile it's own code.
Probably won't mess around with thumb assembly and do it in C and libopencm3.
Hong, Guil Dong · 2018-04-06 20:20
>>7723
>Probably won't mess around with thumb assembly and do it in C and libopencm3.
The whole point of Forth is that its minimalist and pretty low level, why bloat it by using C and a library?
It's stupidly easy to write a Forth in asm.
Elliot Alderson · 2018-04-06 20:34
>>7726
Well that is what I am already familiar with. I can always go ahead and re-write some function that implement base words is asm if I feel like it.
Second using a "library" isn't necessarily bloat in that regard.
The alternative to something akin to libopencm3 is studying the whole 500 page STM developer manual and datasheet for the device which I will certainly won't finish.
libopencm3 already has handy macros and functions to access timer peripherals, [ins, adc registers, etc...
It would be a tour-de-force to not utilize something like that.
I know myself well enough, too many abandoned projects as it is.
Boole · 2018-04-06 20:44
>>7727
>The alternative to something akin to libopencm3 is studying the whole 500 page STM developer manual and datasheet for the device which I will certainly won't finish.
???? no it isn't
I won't derail the thread any longer with this, but you don't need to know everything about your cpu to implement a basic Forth, you just need to know basic assembly. If you do need to know some cpu specific stuff, then just consult the few pages of the manual that discuss it like everyone else.
Ein · 2018-04-07 00:48
>>7728
>If you do need to know some cpu specific stuff, then just consult the few pages of the manual that discuss it like everyone else.
This is the thing: It's not just a few pages, it's all vendor specific the whole vendor manual.
Then there is the cortex m3 manual which is implementation (arm spec) specific, about as large and then there is finally the thumb2 instruction set.
I am familiar with neither of these things, and if you are more power to you.
Also: WTF, I have somebody telling me how I should write my code all week, why should I listen to you? You don't give me money.
scnr the snark
Tank · 2018-04-07 01:10
Back on topic:
There's mecrisp forth that runs on several microcontrollers.
http://mecrisp.sourceforge.net/
https://hackaday.com/2017/08/04/take-the-blue-pill-and-go-forth/
I'll try this tutorial out tomorrow
https://jeelabs.org/article/1608d/
Gonna look at the mecrisp sources once that is running, wish me luck.
FYI: The boards cost between $1 and $2, the programmer $5 (clone). If you spin your own boards that can be had for under $1
Incognito · 2018-04-07 01:50
>>7735
I was just trying to say that bare metal programming is actually really quite simple and its something I recommend you dive straight into without fear ;_;
>>7736
Nice post lainon, I'll read more about it when I'm not so sleepy.
Gyula Kovacs · 2018-04-07 09:44
I think that forth needs a community, a package manager and frameworks.
I know, I know
>much secret (embedded) language
But I live this language and it's a shame it's not used---and improved---more.
>>7556
I'm >>383, your solution is cool, but my solution (the one I posted) works with a variable number of arguments. ¶:
↑ · 2018-04-07 13:49
>>7743
>I think that forth needs a community, a package manager and frameworks.
No, it really doesn't. Forth just isn't that kind of language. It isn't fit for that.
I don't want to derail this thread too much, but there are reasons why Forth is only used in small cpus and as a scripting language embedded in other programs - that's how its best utilized. It really doesn't fit the model of using large libraries and frameworks to write boilerplate code.
When I tried your solution it only seemed to work with more than one argument and wasn't recursive? It seemed quite buggy, I'm not sure.
Mine doesn't reverse the order of the arguments to better fit the lisp syntax, but that's quite easy to add.
nil · 2018-04-07 17:15
>>7744
>ut there are reasons why Forth is only used in small cpus and as a scripting language embedded in other programs - that's how its best utilized
There's actually some reason:
* Forth Inc composed of assholes
* most Forthers are old farts
* Chuck Moore himself as a mindset stuck on the sixties
Knuth · 2018-04-07 17:27
>>7751
Yeah, those fuarrrking old cis white males are keeping Forth down!! It has nothing to do with the fact concatenative languages are inherently bad at juggling more than a couple arguments at a time, pfft.
Use gforth to write a wrapper for OpenGL (or some other bloated library of your choosing) and then use that to write a basic application and you'll get what I mean.
Hard mode: don't use local variables at all, they're slow af ;)
setq · 2018-04-07 17:57
>>7752
Right. Forth is good for really simple tasks like programming a microprocessor to make a bunch of LED's blink in order. It's also inherently real-time, which is why it was used for ESA's Philae lander.
It's not a good fit for working with towers of abstraction on desktop computers. It's good for projects where the problem domain is mostly talking to hardware.
Nobody special · 2018-04-07 18:18
>>7754
Exactly, this is why Forth peaked in the 80's.
The Plague · 2018-04-15 00:26
This language is pretty cool:
http://kittenlang.org/
It's basically a pure functional Forth with hindley-milner type inference.
Roy Batty · 2018-04-15 02:03
>>7873
god, that mix of postfix/infix and concatenative/applicative syntax is fuarrrking disgusting
Are these people incapable of appreciating the inherent simplicity of true concatenative languages? Why complicate them with infix bullsoykaf?
Anamika · 2018-08-12 04:01
I'd really like to use Forth to reimplement a program of mine, but I dislike ANSI Forth and all of the messes it causes to write a portable program.
All I need for this is a very simple Forth that uses an eight bit byte and a sixteen bit cell; I've been recommended eForth, but I've had issues finding any good material on eForth. Unfortunately, I'll also need to be able to interact with the filesystem, but I can work around this if I really need to. Interactivity and character granular input is a necessity.
I'd like to reimplement this program nice and simply in a Forth, but ANSI Forth is just too complicated to make it seem worthwhile.
Do you have any good suggestions for me? I'd use a machine Forth, but I couldn't get Jonesforth to assemble and I'm doing something abstract enough that I'd like to have some portability if I could.
Cereal Killer · 2018-08-12 04:34
>>10031
Write a naive forth in C to fit the domain and interact natively with the libraries you need.
simplest [?ForthSimplicity] solution I can think of...
t · 2018-08-12 05:12
>>10032
I don't know C; it would be easier to implement it in a machine code.
I could do this, but I'd rather avoid it if I could. So, getting Jonesforth to work is likely the easiest solution.
Switch · 2018-08-12 11:31
>>10033
how do you not know c?
J.C. Denton · 2018-08-12 21:44
>>10035
Why would I use C when I know Forth?
Splicer · 2018-09-15 18:40
gforth or pforth? What's best for general programming? Others?
> inb4 factor
It is like kicking dead whales down the beach
Splicer · 2018-09-19 06:31
>>10426
>gforth or pforth? What's best for general programming? Others?
I'm the same user from earlier wondering about this.
I suppose I'm likely going to just use gforth and redefine some words to make it feel like what I want.
Still, in a way, I'm considering other low level languages for my project, instead. I understand the Forth will be smaller and ultimately simpler, but I tire when I consider the refinement it would take to reach that. My project can't be as simple as I'd like, because it must interact with system APIs. I'm likely going to end up implementing it in pieces, since the project is amicable to this, and later collecting it into a whole once I finish enough, however long into the future that is.
So, just do what I'll be doing and use gforth. It's not the simplest and it's not the smallest, but it's easy to install and will likely have all of the functionality you end up needing as gforth extensions.
over · 2018-09-19 13:56
>>10426
Retro Forth. forthworks.org/retro
Lunch · 2018-09-23 20:30
I just downloaded gForth but I literally don't know what to do. Is there an IDE for gForth, perhaps? I really want to give Forth a go but I'm new to stuff like this regarding compilers. If I'm not using Code::Blocks, I really don't know what the heck's going on. I just see this folder and it has these folders like "arch", "asm" and "compat" and I just want to write some Forth and I don't know what's what.
If not for Code::Blocks, I don't think I would've ever compiled a program, ever. Somebody spoonfeed me on this whole process.
array · 2018-09-24 04:40
>>10499
It seems like you are trying to learn Forth, an IDE is overkill for it try reading starting forth then try writing some code after reading the first chapter or two
>If not for Code::Blocks, I don't think I would've ever compiled a program, ever. Somebody spoonfeed me on this whole process.
You don't 'compile' forth programs or any interpreted language because the interpreter executes the program without converting the program down to machine code. As for C(++) I suggest looking at how the IDE does it or reading gcc manuals every other C compiler should follow a similar syntax
starting-forth: https://www.forth.com/starting-forth/
The Fin · 2018-09-24 17:10
>>10499
just run gforth.exe or the binary depending on your operating system, that is the compiler, the interpreter, the editor etc etc
JARGON · 2018-10-10 20:06
Not very impressive but proves the concept viable. If I were pursuing this further I'd have the tick compare to a jump table and use that to determine the correct number of operands. I would also implement a state-smart TICK ( ', ['] ) to allow compilation of s-expression styled code
: operate dup 0= invert if >r 1- recurse r> then swap ;
: s( ' 0 60 ;
: eq<? dup 60 = ;
: ))s eq<? if drop else >r recurse r> -rot 1+ rot then ;
: )s ))s dup 1- >r operate r> 0 do dup >r execute r> loop drop ;
s( 2* 1 2 3 4 )s . cr bye
Boris Grishenko · 2018-10-18 16:28
>>10507
I know it's a bit late but I just wanted to say: you never really answered my question. Admittedly though, I never really properly gave you one so here it is:
How do I go from code written in Forth to a program that executes that code?
You're telling me to go off and read how an IDE does it or to read gcc manuals but that's not what I wanted. I didn't want literally the entirety of the process for how source code gets compiled into machine code. I just wanted to know how to go from code -> program with Forth.
>>10524
There is no gforth.exe in the folder I downloaded.
I held off on replying for so long because, even now as I type, I still have yet to get around to reading that "Starting Forth" book. If the answer is in there, sorry but until then, yeah. You see, it's not just Forth. There was another stack-based programming language I wanted to try called "Joy" but when I checked out Joy, I found the same problem where, when you attempt to download the things you need for the programming language, all you get are these files and folders that I know nothing of what to do with. WIth Code::Blocks, by clicking a little gear with a green triangle, I can go from code -> program. I just felt like there was some kind of general method for trying out different programming languages that I don't know of if they all seem to be doing this same thing. It's like, I thought I bought something but what I actually bought were the parts for something and I'm expected to know how to assemble it, so much so that there isn't even an assembly guide!
TL;DR
How do I go from Forth code -> Forth programs?
Spike Spiegel · 2018-10-18 16:36
>>10976
Starting Forth is ancient. Just read the manual for your Forth system.
>gforth
gforth's tutorials are pretty good. especially the 'crash course'.
gforth has several ways (all bad) to produce something like an executable; what you should do with gforth is produce a script, instead.
>gforth.exe
use another system. Win32Forth and SwiftForth($) can create a turnkey .exe for you. Read their manuals. The process for SwiftForth is
1. store an XT in 'MAIN -- this will be executed when your program starts
2. run PROGRAM FOO -- this will create a foo.exe with the current image of your Forth system, which will run 'MAIN when it starts
note that you can actually run PROGRAM FOO multiple times. I used this to create a "quick refresh" and a "hard refresh" variant of an app, by adding a bunch of entries to a linked list between the two PROGRAMs
null · 2018-10-18 17:09
>>10977
What's my Forth system? I have Linux Mint. I have a keyboard, a mouse and a monitor.
What's a script and what's an executable? I just want to write Forth and then have that Forth code turn into something that does things.
>another system
What?
>turnkey .exe
Why are you using all these new terms? Is it really necessary? I thought just trying Forth would be straightforward
SwiftForth seems to come at a cost and I'm on Linux so I'm pretty sure Win32Forth is unusable to me. What's wrong with gForth anyway? It's free after all. I just don't know where to start with it or what to do. There isn't even a gForth.exe file contained within the folder.
typedef · 2018-10-18 17:17
>>10977
Never mind. Rather than try to use google, I used youtube instead.
You literally just go into the terminal and type "sudo apt-get install gforth" and it's all yours and you can get started.
I cannot believe nobody said this.
Six · 2018-10-18 18:50
>>10981
nobody said that because that has nothing to do with his question. OTOH, by >>10980 he's completely clueless, so who even knows what he means.
St. IGNUcius · 2018-10-18 21:44
>>10983
>>10499
>>10976
>>10980
>>10981
All of these posts were by me. Which part of my posts seem confusing, I wonder? I literally just wanted to get started in writing Forth code and making Forth programs.
In the same way I can download CodeBlocks and immediately get started in writing C or C++ code, I expected to be able to download some kind of IDE and immediately get started in writing Forth code. At first, it seemed to not be so simple. Then, with Youtube, it turned it that it is that simple. However, there's still a lot of things I don't understand, such as:
My observation of a poster referring to gforth.exe as a "system" and his recommendation that I use another "system".
What a "turnkey .exe" is.
Why it's necessary to use all this jargon with someone who is both clearly new to Forth, clearly new to programming (I did indeed say I was new to stuff like this regarding compilers) and why there is no attempt to explain any of it.
In the end though, even if I've now watched that Youtube video, there's one critical fact: I didn't read "Starting Forth" so potentially, I really don't have much room for criticism as the book might explain how to get started in trying the Forth language.
Bob Arctor · 2018-10-19 00:54
>>10989
I get it, you're just dumb or trolling.
I love lainchan and this forth thread is cool, but your attitude is innerving.
Do you know that forth is an interpreted language? Do you know that for most programming language there isn't a dedicated ide botnet? These info are a wiki away, so please give us some of your background, are you under 15?
You are just trolling and joking on the positive attitude of this site in respect of the usual imageboards.
Some examples?
The entirety of your answers. I started picking examples, but I noticed you wanted to derail the thread in EVERY reply you made, so I think that all that you write suffice as evidence.
Why I wrote this? Who knows, you just succeded in trolling me, and I wanted to say go soykaffing yourself.
Ps: how does it feel pretending to be a retard?
Ops, sorry. You are not pretending, are you?
Iverson · 2018-10-19 01:01
>>10989
>Starting Forth
no, it doesn't get you started. Manuals for systems get you started. Read one. Gforth has one. Just search for it: https://duckduckgo.com/?q=gforth+manual
A "system" is an implementation of Forth.
A "turnkey exe" is a deployable executable that you can run without needing a Forth system around. You put a key in a car and turn it and the car starts. You do not need a car factory around to help you start your car.
".exe" is one Microsoft's historical required extensions for executable files. It's probably actually a CP/M thing. I mentioned it because you sounded like you were not even on a Linux system.
>Which part of my posts seem confusing
"How do I go from Forth code -> Forth programs?"
what you meant: How do I even begin to use Forth at all?
what I heard: How do I take the Forth programs I've written and have already run interactively with a Forth system, and turn them into nice deployable executables?
I heard that because what you meant is an absurd reading of what you said. Why did you even ask that instead of reading any documentation? Why are you fixated on Starting Forth? It has some cute pictures, tells you a little bit about Forth, and describes a system that doesn't much resemble modern Forth systems. It's nearly useless as an introductory work.
Sipho Nkosi · 2018-10-19 01:33
>>10999
<not who youre quoting>
I think youre trying to hard to sell gforth. Its an ok forth if you want something that will interface with a standard desktop OS but youre are totally missing out on the potential of forth by not running forth bare metal on an embedded development board. Forth is the one programming language that can function as an OS. Embedded systems programmers commonly use forth to test their systems. Go find an ARM board, find out what forth implementations are ported to it and then learn forth that way.
It is possible to make binaries from forth programs but forth is at its core an interpreted language that runs on the CPU itself and gives direct access to registers and I/O peripherals.
() · 2018-10-19 02:03
>>10998
Calm down, Lain. These posts will make good copypasta in years to come. Pay it forward!
HELIOS · 2018-10-19 07:23
>>11000
there's really no reason to use forth except in extremely resource-constrained environments. Many backup computers on satellites are programmed in forth.
Mitnick · 2018-10-19 08:57
>>10998
>but your attitude is unnerving
What's the correct attitude for someone that hopes to get into Forth? I literally said that I downloaded the files but I didn't know what to do. I literally exposed myself as knowing nothing. How could that possibly not be sufficient?
>Do you know that forth is an interpreted language?
I don't even know what that means or why, for a beginner, that would even matter. I feel quite certain these technicalities only become relevant when you've progressed a bit further into programming and have reached an intermediate level and are now more concerned with higher matters regarding computers like performance speed and cpu architectures and stuff I, as of yet, still do not understand.
>Do you know that for most programming languages, there isn't a dedicated ide?
I suspected as such which is why in one of my earlier posts, I also mentioned the Joy programming language, another stack-based programming language I was curious about and wanted to give a go. The issue however was the fact that I, yet again, when attempting to try the language only found myself coming upon a collection of files and folders, that I, as I said, know nothing of what to do with. I can't find a readme.txt, I can't find a .exe, I can't find anything I think would help me get started.
>These info are a wiki away
What wiki?
>Are you under 15?
I'm 25. I've been quite comfortable with Windows my whole life but now I've wandered off the beaten path and feel confused. To be fair though, there is a "Linux for Dummies" book so in a sense, this is all self-inflicted. It's just, even if it was perhaps impatient, I really did think that I could just "try out" a language in the same way IDEs for C and C++ let me do so.
>I noticed you wanted to derail the thread in every reply you made
You mean to divert it away from Forth and towards how to get someone new to Linux and new to Forth programming in Forth?
>You are not pretending, are you?
I've literally stated several times that I don't know what to do that there's a lot I don't know. Is this not enough?
>>10999
THIS. THIS is the informative post I was looking for.
>Why did you even ask that instead of reading any documentation?
Where do I find the documentation? Like I said, I didn't see a readme.txt
>Why are you fixated on Starting Forth?
Because I assume it's beginner-friendly and explains how to get started in writing forth code that makes the computer do things, based off of that code (I'm avoiding using the word "program" here because you've revealed there's a bit more to its definition that I was initially aware of).
>It's nearly useless as an introductory work
Well, poo. How does one even get started then?
Incognito · 2018-10-19 09:25
>>10998
Oh, sorry. I just want to clarify: I have successfully gotten started with gforth so I have at least that but yeah, I don't know how to try out programming languages without IDEs. Even when you say to check the documentation, when I downloaded the gforth files, there isn't even a "documentation" folder. Again, when I return to the Joy programming language, I do not see a "documentation" folder nor a readme.txt.
I guess I took the ease of IDEs for granted but even then, I didn't think the barrier to entry would be that high. I remember my first time coming upon .rar files and needing to get Winrar so I could do the extractions. I figured there was some kind of program that would take these programming language files and combine them somehow into an IDE I could use to start writing software or something.
Boole · 2018-10-19 11:38
>>11008
gforth is your IDE. A "system" is a distribution, like CPython and Pypy, you have gforth, Lina Forth, iForth, SwiftForth etc. You sound like you want SwiftForth, the Forth system maintained by Forth, Inc. It's proprietary software though, so that may turn you off. If you're a Windows user who appreciates open source, look at Win32Forth, which is public domain. If you use Linux, I wholly recommend you DO NOT use gforth and instead use Lina Forth, a much simpler system written in assembler. Lina Forth comes with a ''wealth'' of documentation.
A forth system is an interpreter and compiler in the same binary. For most systems, "compiling" forth means rolling your code into the executable and having it run your code on execution - this is called a turkey system (i.e. you turn a key to start a car, you turn a key and your Forth boots up). Most open-source Forths do not really have the ability to generate turnkey programs, but the same holds true for most LISPs. The idea is that having a Forth system installed will be a prerequisite to running your program - this is similar to requiring a libc or a python interpreter or whatever. In that case you would just run a normal `gforth <forth-file>` or `lina -s <forth file>`. Starting Forth is a good book. Only a tryhard would pretend it isn't. Read it, work through it, and you'll come to a great understanding of the stack and how canonical Forth (sometimes called FIG-Forth) works. Use the online version, it adheres to the current standard. gforth and Starting Forth have some disagreements, but they're usually something you can just ignore because you'll figure it out later.
If you have any questions, hit me up, WilhelmVonWeiner in #Forth on Freenode irc (irc.freenode.net). The #Forth channel is mostly meta-discussion about how a Forth should do what (the kind of thinking which killed the Forth "community"), but it's still pretty solid.
list · 2018-10-19 17:23
>>11008
> IDE - Integrated Development Environment
> UTP - Universal Tool Platform (an acronym invented for Eclipse)
> OS - Operating System
> EMACS - Eight Megabytes And Constantly Swapping
if you try, you can justify replacing any of these acronyms with any of the others.
The 'IDE' of most good languages is Unix.
It's especially suitable for C, but only because lots of languages don't try.
hey what does the 'open' syscall do? 'man 2 open'
what about 'fopen' in libc? 'man 3 fopen'
how do you compile stuff? cc
how do you build stuff? make
how do you debug stuff? gdb
how do you trace stuff? strace, ltrace, ftrace
how do you reserve parts of your screen for different stuff? use windows, or use tmux within a terminal. Have a little shell on the bottom for make, gcc, etc. Have a big editor in the middle. Have some logging in a side panel. Have a bunch of documentation open in w3m or man or info that you can switch to with a keypress. oh no the last compile had a big error, but you have a tiny section fo your display for compiles --> C-b C-o , OK now your editor is really tiny and you've lots of space to look through what happened.
pop · 2018-11-02 22:23
I started a block editor (well, 80x22 blocks) but currently feel obliged to refactor it because mty code is so inconsistent but I CAN'T BE fuarrrkIN ARSED. Here's some code if you want, run it as `gforth scred.f`. wouldnt be hard to add features at this point
warnings off
80 CONSTANT #W ( Width)
22 CONSTANT #H ( Height)
#W #H * CONSTANT #TEXT
#W CONSTANT #MODELINE
#W CONSTANT #MINIBUF
VARIABLE 'TEXT #TEXT ALLOT
VARIABLE 'MODELINE #MODELINE ALLOT
VARIABLE 'MINIBUF #MINIBUF ALLOT
'TEXT #TEXT ERASE
'MODELINE #MODELINE ERASE
'MINIBUF #MINIBUF ERASE
( XY POSITION IS ON THE STACK)
: C' POSTPONE [CHAR] ; IMMEDIATE
: XY DUP #W /MOD ;
: XY! XY AT-XY ;
: ESC[ 27 EMIT 91 EMIT ;
3 CONSTANT FG
4 CONSTANT BG
( )
9 CONSTANT DEFAULT
0 CONSTANT BLACK
7 CONSTANT WHITE
2 CONSTANT GREEN
: COLOUR ESC[ 48 + EMIT 48 + EMIT [CHAR] m EMIT ;
: FG! FG COLOUR ;
: BG! BG COLOUR ;
( Editor function )
: SETTER OVER 'TEXT + C! ;
: CRNL 80 OVER XY DROP - + 1- XY! ;
: CRNL? DUP 13 = IF DROP CR RDROP THEN ;
: BS 1- XY! BL EMIT 1- XY! ;
: REALIGN DUP DUP 'TEXT + OVER 1- 'TEXT + ROT 1760 SWAP - ; ( CANCER!)
: BS? DUP 127 = IF RDROP DROP REALIGN CMOVE> BS THEN ;
: ESC? DUP 27 = IF PAGE BYE THEN ;
: SPECIAL? ESC? BS? CRNL? ;
: PRINTABLE? DUP 32 127 WITHIN IF RDROP SETTER THEN ;
: INPUT PRINTABLE? SPECIAL? DROP ;
: PRINTER ROT ROT DO DUP I + C@ EMIT LOOP DROP ;
: MINIBUF ;
: (MODELINE) #MODELINE 0 'MODELINE PRINTER ;
: MODELINE #TEXT XY! DROP GREEN BG! 80 SPACES DEFAULT BG! ;
: WINDOW #TEXT OVER DO 'TEXT I + C@ EMIT LOOP ;
: WINDOW #TEXT OVER 'TEXT PRINTER ;
: DRAW XY! WINDOW MODELINE MINIBUF 1+ XY! ;
: EDITOR KEY INPUT DRAW RDROP RECURSE ;
PAGE
0 DRAW EDITOR
BYE
Judge Fang · 2018-11-09 19:33
Someone on #Forth wrote a "GETLINE" word in a huge "ANS-style" block with nested IFs and the like. It was so visually gross I wrote it as regular Forth
: PRINTER >R 2DUP + R> DUP EMIT SWAP C! 1+ ;
: PRINTABLE? DUP 32 127 WITHIN IF RDROP PRINTER 0 THEN ;
: DECREMENT 1- 0 MAX ;
: BS 8 EMIT 32 EMIT 8 EMIT ;
: BS? DUP DUP 8 = SWAP 127 = OR IF RDROP DROP DECREMENT BS 0 THEN ;
: CRNL? DUP DUP 10 = SWAP 13 = OR IF RDROP RDROP DROP THEN ;
: INPUTTER CRNL? BS? PRINTABLE? DROP 0 ;
: GETLINE BEGIN KEY INPUTTER UNTIL ;
VARIABLE TEXT 128 ALLOT
TEXT 0 GETLINE
CR TYPE CR BYE
Lain Iwakura · 2018-11-10 03:03
>>11287
This is a nice piece of Forth.
One thing that bothered me while I was reading and understanding this was the BEGIN UNTIL loop that places unnecessary values on the stack to appease it.
ANSI Forth doesn't have real recursion with TCO, but I just used recurse with a dummy word. Here's what I changed:
: PRINTABLE? DUP 32 127 WITHIN IF PRINTER ELSE DROP THEN ;
: BS 8 EMIT ;
: BACKSPACE BS SPACE BS ;
: BS? DUP DUP 8 = SWAP 127 = OR IF RDROP DROP DECREMENT BACKSPACE THEN ;
: INPUTTER CRNL? BS? PRINTABLE? ;
: (GETLINE) RDROP KEY INPUTTER RECURSE ;
: GETLINE (GETLINE) ; Here's the entire thing, for convenience:
: PRINTER >R 2DUP + R> DUP EMIT SWAP C! 1+ ;
: PRINTABLE? DUP 32 127 WITHIN IF PRINTER ELSE DROP THEN ;
: DECREMENT 1- 0 MAX ;
: BS 8 EMIT ;
: BACKSPACE BS SPACE BS ;
: BS? DUP DUP 8 = SWAP 127 = OR IF RDROP DROP DECREMENT BACKSPACE THEN ;
: CRNL? DUP DUP 10 = SWAP 13 = OR IF RDROP RDROP DROP THEN ;
: INPUTTER CRNL? BS? PRINTABLE? ;
: (GETLINE) RDROP KEY INPUTTER RECURSE ;
: GETLINE (GETLINE) ;
VARIABLE TEXT 128 ALLOT
TEXT 0 GETLINE
CR TYPE CR BYE Note that I didn't check my changes thoroughly, but I did test them. I also removed some other now unnecessary words, such as the RDROP in PRINTABLE?. Now the only thing left to fix is the lack of overflow protection and the ability to backspace indefinitely. You could have an INCREMENT, so just the last letter changes once you hit the limit, as one option. In any case, putting this check in PRINTER seems best.
There's still a ways to go before this little program is finished, but it's getting there.
Debbie Charteris · 2018-11-10 10:54
>>11290
Ah, nice one mate. I was going to RDROP RECURSE but hadn't sseen the obvious "dummy word" solution, even if I subsequently used it to handle input. Cheers
Hagbard Celine · 2018-11-10 14:31
>>11290
I don't think you can backspace indefinitely, `DECREMENT 1- 0 MAX` . Buffer overflow protection if that's your thing:
: CRNL? DUP DUP 10 = SWAP 13 = OR IF RDROP RDROP DROP DROP THEN ;
: DECR 1- 0 MAX ;
: BS 8 EMIT 32 EMIT 8 EMIT ;
: BS? DUP DUP 8 = SWAP 127 = OR IF RDROP DROP >R DECR R> BS THEN ;
: (PRINTER) ( c-addr n m c) >R ROT ROT 2DUP + R> DUP EMIT SWAP C! 1+ ROT ;
: LIMITER 2DUP >= IF SWAP 1- SWAP BS THEN ;
: PRINTER >R LIMITER R> (PRINTER) ;
: PRINTABLE? DUP 32 127 WITHIN IF RDROP PRINTER THEN ;
: INPUTTER CRNL? BS? PRINTABLE? ( ELSE) DROP ; ( I dislike hiding detail)
: (GETLINE) KEY INPUTTER RDROP RECURSE ;
: GETLINE (GETLINE) ;
VARIABLE TEXT 128 ALLOT
TEXT 0 128 GETLINE
CR TYPE CR BYE
Morpheus · 2018-11-12 06:03
how come it multiplies it once more
: ^ ( n1 u1 -- n )
dup 0=
if 2drop 1
else over swap 0
do over * loop
then ;
Motoko Kusanagi · 2018-11-12 07:07
>>11319
rewrote it once more but it still gave me b^(n+1) instead of b^n, so i replaced the word after the loop, which was nip, with swap /
Although it feels like a hack
forth
: expt ( nB uN -- uB^N )
dup 0=
if 2drop 1
else
over swap
0 do
2dup * nip
loop
swap /
then ;
Delilah · 2018-11-12 10:18
>>775
tell me more about gba and forth
Demeere · 2018-11-12 10:22
>>913
did you solve your problem, because i'm having the same
cdr · 2018-11-12 17:36
>>11321
Did this just now. Will implement it recursively some time
: ** ( n m --)OVER SWAP 1 DO OVER * LOOP NIP ;
word · 2018-11-12 17:43
>>11336
: ** DUP 0= IF 2DROP 1 ELSE OVER SWAP 1 DO OVER * LOOP NIP THEN ;
Boris Grishenko · 2018-11-12 22:12
>>11338
>9 1 **
Yuki Nagato · 2018-11-12 23:06
>>11342
: WORD-USING-** DUP 1 = IF DROP ELSE ** THEN ;
idk glitterboy leave me alone the code mostly works
later I'm writing it with an actual alg. jerking off at the moment
Hopper · 2018-12-10 12:52
>>11323
I use a different forth than gforth, namely pforth. This solves the problem of duplicated input.
(setq forth-program-name "pforth")
roll · 2018-12-28 11:01
>>475
>it's an assembler on steroids, that's the intended nature of it.
No it isn't. Forth is an application language.
Vasya Pupkin · 2019-02-17 04:01
Has there been any progress on expanding forth out so you can bury yourself in it?
Like lisp has scsh, emacs lisp, theoretically lisp machine lisp , lisp markup language
Is there a forth shell for unix?
Nguoi La · 2019-02-17 08:03
>>12554
You can live forever in a forth interpreter, just look for some system interaction
HELIOS · 2019-02-17 18:30
i can't decide between learning forth or lisp :( you all seem cool OK bye I have to go to dinner
null · 2019-02-17 19:52
>>12558
I only learned lisp so far but I plan on learning forth someday. I'd say why not both ?
Ok that might not be the most constructive answer ever.
dup · 2019-02-18 07:39
>>12558
>>12559
Lisp is beautiful, but with Forth, you'll learn how computer works, and it's fun too.
Lain Iwakura · 2019-02-18 18:38
>>12567
I'm scared to learn. I don't know if I'm smart enough. I wish there was a book called little forther or sicp using forth.
can forth do Internet or gui? I wanna make os.
Lukasiewicz · 2019-02-19 00:39
>>12578
I'm not a genius and I can grasp forth. Read "starting Forth" to learn the syntax, use gforth and the manual on the site for reference, it's pretty clear.
Read thinking with Forth if you like the language and ideas behind it.
I still can't find a language so easily expressive (maybe just K).
My dream is Forth with Perl hashes and string manipulation, Lua arrays, Haskell laziness and Fortran speed...
overriding · 2019-02-19 01:08
>>12578
There is a server-side web framework written in Forth: http://www.1-9-9-1.com/
Starting Forth is a lot like The Little Schemer.
https://www.forth.com/starting-forth/0-starting-forth/
It's a nice little book. After that, Thinking Forth will change how you think about programming in general.
>I don't know if I'm smart enough
It's a very simple language. You just push data onto the stack and get back a result by applying operations to it.
To add 1 and 2,
push 1
push 2
apply '+' --> pops 2 numbers off the stack, adds them, pushes result onto stack
voila, 3 is on the stack!
To write this, it's just "1 2 +"
to square a number:
dup --> pop stack, duplicate number, push both onto stack
* --> pop 2 numbers off the stack, multiply them
To turn this into its own word:
: square dup * ; To square 10:
10 square .
We can cube a number by dup'ing a number and dup'ing it again, then multiplying the result. dup'ing a 2nd time will duplicate the top number only, so there are 3 identical numbers. Now multiply them!
: cube dup dup * * ; >I wanna make os.
You've come to the right language!
>>12580
There is Joy, which is a purely functional stack-based language. You could build your own interpreter and add laziness to it.
Joy in Prolog: https://osdn.net/projects/joypy/scm/hg/Joypy/blobs/tip/thun/thun.pl
Boole · 2019-02-20 04:46
>>424
this gif is so comfy. what's it from?
() · 2019-02-20 08:21
>>12605
Final Fantasy tactics if I remember correctly
bit · 2019-02-20 18:44
>>12581
What implementation do I use
The Oracle · 2019-02-21 12:55
>>12621
Consider writing your own from scratch. It won't be the fastest Forth VM ever created, but it'll give you a deep understanding of how Forth actually works.
https://github.com/AlexandreAbreu/jonesforth/blob/master/jonesforth.S
If you're not familiar with the assembly language, you can choose a more convenient architecture than x86. MIPS, for example, is a pretty good choice.
https://chortle.ccsu.edu/AssemblyTutorial/index.html
cond · 2019-07-26 05:15
Anybody implemented their own forth? I wrote a colorforth implementation with 2 compilers in less than 1000 loc with most of the lines being primitive functions.
This language is great since it fits in your head.