[HN Gopher] Bashforth: A Forth interpreter, written as bash script
___________________________________________________________________
Bashforth: A Forth interpreter, written as bash script
Author : ColinWright
Score : 67 points
Date : 2022-01-08 13:48 UTC (9 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| chubot wrote:
| I added this to
|
| https://github.com/oilshell/oil/wiki/The-Biggest-Shell-Progr...
|
| although there are a lot of whitespace and comments to get up to
| ~3800 lines.
|
| The biggest shell scripts in the world seem to be about 10x
| bigger, around ~30K lines. Feel free to add any "program" that's
| more than 10K lines, and smaller ones if they are "interesting".
| (That's subjective, but I think a Forth qualifies.)
| sudobash1 wrote:
| My brother just finished writing a forth like interpreter for a
| freshman CS project (in java, not Bash, thankfully). It is a
| really nice language for learning the basics of an interpreter
| without worrying about the parser side too much.
| shadowofneptune wrote:
| Now that I think about it, the grammar is entirely regular,
| yes?
| Someone wrote:
| I'm not sure Forth has a grammar in the traditional sense.
|
| I think any grammar needs to cover immediate words because
| you cannot ignore CREATE... DOES>. Those can do anything, so
| how do you handle them?
|
| There's also BASE (the current number conversion radix). It
| makes parsing integers context-dependent.
| codr7 wrote:
| It's just a stream of tokens, which are either literals or
| identifiers; it's the only language I know that has less
| syntax than Lisp.
| vitiral wrote:
| And "tokens" are literally "any string of non whitespace
| characters."
|
| One of it's biggest downfalls imo is that the toeknizer is
| too simple. I'm making GitHub.com/civboot/fngi as a "better
| than forth".
| codr7 wrote:
| Oh, I've been down that rabbit hole for a long, long time
| :)
|
| It makes a nice foundation for syntactic experiments.
|
| https://github.com/codr7/gfoo
|
| https://github.com/codr7/forthy2
| cachvico wrote:
| "Bash and forth" would be a good name
|
| Edit: I'll get me coat
| daenz wrote:
| Can someone explain to me why people are writing complex systems
| in Bash? It seems to be somewhat of a joke/meme, but I am having
| a hard time understanding why someone would put so much effort
| into a joke. Another recent example:
| https://news.ycombinator.com/item?id=29648135
| ColinWright wrote:
| Same reason why people write non-trivial programs in any of the
| esoteric languages ... in part it's a challenge, in part it's a
| demonstration of cool techniques, and in part it's a
| demonstration of your skills.
|
| For them it's fun, for the readers it's a view into a weird
| world. Maybe it's just not for you, but not everything has to
| be for you.
| daenz wrote:
| Are you saying there is credibility/virtue in making
| something deliberately difficult to build, read, and
| maintain, in the absence of real constraints?
| ColinWright wrote:
| Are you saying that there's no value in demonstrating the
| skill to create something that many, perhaps most,
| programmers would say is impossible?
|
| Have you looked at the code? It's beautifully laid out,
| extremely readable, and completely maintainable. If you
| don't know bash it's a great example of how to create a
| reasonably complex program that's designed to be read and
| maintained.
|
| And finally, yes, when taken as an opportunity to improve
| your skills, absolutely there is value in creating
| something as a vehicle for developing your abilities, to
| demonstrate to others that you _have_ those skills, and
| quite simply, as a challenge.
| daenz wrote:
| I don't think most or even many programmers would say it
| is "impossible" to write a Forth interpreter in Bash. If
| you changed "impossible" to "worth the effort", I would
| agree. For the same reason it's (in the absence of real
| constraints), it's not worth the effort (nor impossible)
| to write a Forth interpreter with a hex editor.
|
| From an interviewers perspective of "value", I would be
| both impressed at the perseverance demonstrated, but
| horrified at the deliberate masochism.
|
| >completely maintainable
|
| This is far less maintainable than a clean Forth
| interpreter written in Java. Maintainability is relative,
| so saying that something "is maintainable" has no meaning
| unless you compare it to something else.
|
| >absolutely there is value in creating something as a
| vehicle for developing your abilities
|
| I agree, but applying that to this is like saying "let's
| learn to build a house by using a hammer that has no
| handle, and a saw that is made out of raisins."
| ColinWright wrote:
| Perhaps I'm reading you wrongly, but everything you are
| saying here and elsewhere implies to me that you take the
| attitude that everything you do must have value to other
| people in the world.
|
| Do you do crosswords? Sudoku? Wordle? Do you play chess?
| Go? Backgammon? Do you play any video games? Do you watch
| movies? Do you play a musical instrument? Do you paint or
| draw?
|
| If so ... why? What value do these provide for the rest
| of the world?
|
| If not, fair enough ... that's just you, and maybe you
| won't ever understand that sometimes other people do
| things purely for the challenge, and sometimes on the way
| these things hone skills, increase knowledge, and provide
| satisfaction.
| daenz wrote:
| I think we are talking past eachother. I don't play
| Sudoku without writing, or chess using only my pinky toe,
| or video games with a glitchy controller, or watch movies
| backwards, etc. There is a difference between doing X for
| pleasure/learning, and doing X _as difficultly as
| possible for the sake of being difficult._ Maybe my point
| would be more clear about this project, if instead of
| using Bash, it was "using only GOTOs and single-letter
| variables."
| ColinWright wrote:
| Well, I guess I just don't understand your question.
| They've implement a Forth interpreter in a programming
| language. I don't see why you equate this with using
| hammers without handles, or saws made of raisins, or
| doing sudoku without writing.
|
| Using bash is perhaps unexpected, but it's not like
| writing machine code in raw, unadorned, inscrutable hex
| by toggling bits in through a front panel.
|
| It's just a programming language, and it's interesting
| and instructive to see the end result, unlike watching
| someone playing chess with their pinky.
|
| I don't see why you think it's so bizarre. It's not doing
| it in a way that's as difficult as possible .. really, it
| isn't.
|
| But ... I guess I just won't understand your question.
| bendbro wrote:
| Yes, compare it to art.
| sharkbot wrote:
| Part of what attracted me to technology, computers,
| programming, etc is the ability and freedom to tinker and
| experiment with ideas.
|
| If I'm building something professionally, then difficulty
| in building, reading and maintaining is a problem.
|
| If I'm building something to learn or to be creative, I
| don't worry about how difficult it is to build or read or
| maintain: my aim is different, and therefore so are my
| concerns.
| exdsq wrote:
| Bash is fun! And with unit testing libraries & shellcheck you
| can get pretty far :)
| janderland wrote:
| Because it's enjoyable to build things. It's like solving a
| puzzle or riddle: there's no purpose other than the experience
| of solving it.
| daenz wrote:
| Why not solve a real world puzzle then? To me, it's kind of
| like deliberately spilling a bag of sand on the floor, then
| toiling by picking up each grain with tweezers. Sure, it is
| difficult, and nobody can deny the work that you did, but you
| also created the work and the constraints yourself.
|
| I think I just don't "get it" and my pov is probably colored
| by frustrating interactions that I have at work where people
| do the similar things in code shared by others, to
| (seemingly) demonstrate "their skills."
| ColinWright wrote:
| > _I think I just don 't "get it" ..._
|
| Maybe that's simply the way it is, maybe you'll just never
| understand why other people do for pleasure things that you
| see no point in.
| macintux wrote:
| Given the wild popularity of Advent of Code, I think it's
| safe to say that many people have different priorities.
| daenz wrote:
| Advent of Code is different, unless one of the
| requirements is you make your solution as obfuscated and
| esoteric as possible, which is rarely in a code challenge
| (the IOCCC being an exception). In Advent of Code, you're
| still trying to solve problems efficiently.
| justinpombrio wrote:
| Compare it to learning to ride a unicycle. Sure, it's a lot of
| effort, and bicycles are better in every practical way. But
| some people put a lot of time into it and find it fun, and that
| someone has done it is impressive even if you wouldn't go
| through the trouble yourself.
| daenz wrote:
| Maybe that is the part I am misunderstanding. I'm an
| experienced engineer and I code for fun, and think that
| coding a Forth interpreter (or any interpreter) would be fun,
| but have a very hard time believing that "fun" (versus
| "trying to impress people") is the primary motivator to using
| Bash to code an interpreter.
|
| But I acknowledge that I could be wrong too. Maybe they had a
| blast using Bash.
| justinpombrio wrote:
| Yes, I strongly suspect they're having fun using Bash. I
| wouldn't find that very fun myself, either, but to each
| their own.
| bendbro wrote:
| Tangentially related, but I have found making good use of local,
| functions, and jq (for structured data) makes large bash programs
| significantly more viable.
|
| The nice thing about using bash is it implies the program is
| intended to be quick and dirty, and easy to deploy. Users might
| have to get their hands dirty- and they can since it is
| interpreted and interactive. Code reviewers usually respect this
| and don't hang you out to dry.
___________________________________________________________________
(page generated 2022-01-08 23:01 UTC)