News for hackers. Stuff that matters.
Re:Thinking Forth: A Language and Philosophy for Solving Pro... by coldtea on Thursday February 08, 2024 @03:22AM (#39299598)
>but have no idea how I'd write a trig or stat function if it weren't already built in!

Well, that's not really about programmings skills though. That's math.

You could write a decent approximate SIN using the taylor series formula [1]. It's pretty easy, you don't even need to know math, can just look the formula up and translate it to an algorithm. Real world language SIN methods use more efficient and accurate methods, but it's still about knowing the math or looking up common such algorithms.

Or you could just invoke the libc (standard C library) SIN from Forth or whatever language you're using. That's what Python and other languages do.

The quote is more about the approach of writing an application by writing a DSL for the application, than about starting from zero and re-doing all the low level libraries like trig yourself.

[1] https://en.wikipedia.org/wiki/Taylor_series

Re:Thinking Forth: A Language and Philosophy for Solving Pro... by OldGuyInTheClub on Thursday February 08, 2024 @10:50PM (#39311176)
Fair enough. I certainly understand Taylor series. 40+ years ago I experimented with series approximations using the programmable HP calculators of the day to see how my functions compared to the builtins. I intended to say that I would struggle to write something worth using. Poor wording to say the least.

I had no idea FORTH could invoke libraries from C. I got the impression it would be used on systems where space is at a premium precluding the installation of other higher-level languages.

Re:Thinking Forth: A Language and Philosophy for Solving Pro... by coldtea on Friday February 09, 2024 @03:08AM (#39312579)
Yeah, it can, via it's favorite method for everything: adding params to the stack, and getting the return value there! Here's for GForth for example:

https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Cal...

There are even bindings to C/C++ GUI libraries and so on. Running at constrained systems is just a common deployment scenario, but nothing in Forth necessitates it. You can even run it under Windows.