4 ms·
Forth is actually pretty high level. You just have to get there first by building up the abstractions. You can end up with an almost Ruby/Python like language o
by csmuk 13y ago
Forth is actually pretty high level. You just have to get there first by building up the abstractions. You can end up with an almost Ruby/Python like language on top of it if you want. But you probably won't want that after using Forth for a bit and will end up writing DSL's for your programming concerns.
The use case I had for Forth was a PLC-like controller. You ended up describing the configuration in Forth by the time the abstraction was built. Example for a simple "virtual relay" controlled light switch taht turns two separate circuits on and off in a ladder:
bob relays
0 switch inports
1 light1 2 light2 outports
switch inport
bob coil
ladder
bob contact
begin
light1 outport
light2 outport
logical-and
ladder
plc
Was awesome. Unfortunately I don't have rights to the source. It ran on a Z80 board.
- davidw 13y agoForth is quite interesting, and cool in its own way, but: how can anything where you have to remember what is supposed to be on the stack 'high level'?
- Jtsummers 13y agoAs I understand it, the ideal in Forth is to build up a base that hides those complexities in a domain appropriate API. You don't throw 3 numbers onto a stack and leave them on the stack to represent a vector, you wrap that up with a call to 'make-vector', and from there on you're dealing with 'vectors' as a unit rather than '3 points on the stack'. Or if you don't, you develop an API that deals with them sensibly so that every routine that operates on vectors doesn't have to get into the nitty-gritty. Write a routine that represents the common operations (add-vectors, multiply-by-scalar, dot-product, etc) and build your complex routines on those, so that vector projection could be: : project-a-onto-b (a b -- c) swap rot dot-product swap scalar-mult; Ok, 3 stack manipulations but someone who's done more than just toy programs in RPL and Forth might be able to come up with some other routines that can hide those as well. EDIT: And once written, the user of the routine needs to know, "put the two vectors onto the stack, the first one is what I'm projecting, and the second is what I'm projecting onto". Another point to consider, dynamically typed languages suffer a similar 'failing' if they're to be considered 'high level'. How can they be 'high level' if you can add 1+"b"? (in code, won't work in runtime unless it's weakly typed, similar to having too few items on the data stack). How can any language be considered 'high level' if you have to remember how many parameters, their types and in what order for every function call?
- csmuk 13y agoNice to see a mention of RPL. Still use an RPL machine daily (HP50g)
- Jtsummers 13y agoTragically, my HP48G+ (?? I know this model exists, may have been mine, sounds right) bit the dust a few years back (water damage, think it happened while stuff was in storage between residences). It wouldn't be particularly useful in my day-to-day stuff, but RPL is probably the main reason Forth seemed so natural to me when I played around with it a few years back.