by rtpg · 12y ago · 0 comments
Here's tar in Factor:
https://github.com/slavapestov/factor/blob/master/extra/tar/...
For untarring the linux kernel, Factor tar beats /usr/bin/tar on my Mac by 1s, but 30s vs 6s on Linux for some reason. Could be SSD vs spinning disk, or worse i/o code on Linux. Funnily, there are about 10 files that differ in case only, and Mac file system is case-insensitive by default, so you can't even untar the linux kernel correctly.
Here's host using the dns client library:
https://github.com/slavapestov/factor/blob/master/extra/tool...
https://github.com/slavapestov/factor/blob/master/extra/dns/...
I wrote it because gethostbyname is blocking and Factor has nonblocking i/o for everything else.
There's a cross-platform disk usage tool that outputs the same stuff as df but works on Windows too:
https://github.com/slavapestov/factor/blob/master/basis/tool...
USE: tools.files file-systems.
There's a high-level library for doing whatever you want with unix users/groups:https://github.com/slavapestov/factor/blob/master/basis/unix...
effective-user-name [ ] with-effective-user
effective-user-id [ ] with-effective-user
all-users
https://github.com/slavapestov/factor/blob/master/basis/unix... effective-group-name [ ] with-effective-group
effective-group-id [ ] with-effective-group
all-groups
Graphics demo--raytraced spheres using GLSL on a checkerboard pattern, spheres each play their own music:https://github.com/slavapestov/factor/tree/master/extra/gpu/...
https://github.com/slavapestov/factor/blob/master/extra/gpu/...
The main file that sets up the world and loads the shaders and sound is 130 lines and reuses the game library.
The whole idea of picking a Forth or another concatenative language off the shelf is spoiling 3/4th of the concept. The point of stack languages is that they are very easy to implement.
So don't learn a stack based language, make one and grow it until you can actually use it to make useful tools.
but for myself, the fun is in writing a toy concatenative language. The parsing difficulty borders on non-existent, making it easy to skip to thinking about semantics. once you actually try to implement programs within concatenative syntax, you will surely run into its main pitfalls: there are too many valid programs that produce wrong results, and there are whole new classes of errors introduced through having to maintain stack state yourself. writing code in this style can develop into a complex puzzle very quickly, although it's beautiful when it does work.