8th code for device control

Doesn’t make it a language that it seems many of us here (or elsewhere) really have an interest in

It’s your loss, not mine. I don’t understand why you only accept post about Mac and Swift? There are other platforms too.

1 Like

Indeed there are other RELEVANT platforms. 8th is not one of them. You are happy with it? Okay. But did you got much Interest for it here? I guess not. Not as far as I could see. C#, Java, C++, C, Rust, GO, Flutter/Dart, Kotlin are relevant. 8th is not. Even if you believe it so: it is not. I have nothing against the postings. No question. But I have no, really no Idea why this should be a loss for Dave? I can’t see it. Go for it, write about it. But trying to place it as the middle of the universe: will not work. Middle of the universe are more and more Python, C++ and Java. With a big distance C# follows. After a big, really big distance others following. Xojo for example has not 0.01% of the user amount of Java. 8th has not even 0.01% of the user amount of 8th. Only for the question of relevance. dave is totally right in my eyes.

Hmmm… :wink:

  • Karen

8th isnt something I’d ever heard of
Forth yes

is it wildly popular ?
In certain niches I expect it is popular
Open Firmware was one of the very few places I ran into forth

I find it, and forth, hard to read as I’m not used to writing code & thinking like a stack machine

Doesnt mean it CANT be discussed but I too doubt that it will gain a much wider audience on INN even if the focus here is supposed to be on x-platform development

1 Like

Here is a little Java challenge for you:

Say we use JSON data from the Finnish web service Pörssäri:

{
  "metadata": {
    "mac": "XXXXXXXXXXXX",
    "channels": "1",
    "fetch_url": "https://api.porssari.fi/getcontrols.php",
    "timestamp": "1743686955",
    "timestamp_offset": "10800",
    "valid_until": "1743799500"
  },
  "controls": [
    {
      "id": "1",
      "name": "LVV",
      "updated": "1740313870",
      "state": "0",
      "schedules": [
        {
          "timestamp": "1743692421",
          "state": "1"
        },
        {
          "timestamp": "1743695917",
          "state": "0"
        },
        {
          "timestamp": "1743724822",
          "state": "1"
        },
        {
          "timestamp": "1743735570",
          "state": "0"
        }
      ]
    }
  ]
}

Pörssäri JSON API returns the cheapest quarter hour electricity prices for automation channels. The goal is to encode time period data for every channel as bits, taking daylight savings into account. Time periods also need to be properly decoded back as local date time from binary encondings.

Here is an example output from my 8th implementation :

{
  "metadata": {
    "mac": "XXXXXXXXXXXX",
    "channels": "1",
    "fetch_url": "https://api.porssari.fi/getcontrols.php",
    "timestamp": "1743686955",
    "timestamp_offset": "10800",
    "valid_until": "1743799500"
  },
  "controls": [
    {
      "id": "1",
      "name": "LVV",
      "updated": "1740313870",
      "state": "0",
      "schedules": [
        {
          "timestamp": "1743692421",
          "state": "1"
        },
        {
          "timestamp": "1743695917",
          "state": "0"
        },
        {
          "timestamp": "1743724822",
          "state": "1"
        },
        {
          "timestamp": "1743735570",
          "state": "0"
        }
      ]
    }
  ]
} constant data

  \ Parse and encode time periods as bits (bint):
  data "Europe/Helsinki" pörssari> .s

It returns two arrays:

Stack depth: 2
 0 a: 000000000371a780 1  [1328903477231328281674266948937973760]
 1 a: 0000000003718b00 1  ["1743627600"]

Binary data can easily be decoded back to time periods:

  \ Decode and display time periods for all the channels:
  ( rot n:1+ "Channel %d:\n\n" s:strfmt .
    "Europe/Helsinki" rot >n null? !if
      over unix> >d ( "%s - %s\n" s:strfmt . ) a:each! drop cr 
    else
      drop
    then 
  ) a:2each 2drop ;

Result:

Channel 1:

2025-04-03T18:00:00+03:00 - 2025-04-03T19:00:00+03:00
2025-04-04T03:00:00+03:00 - 2025-04-04T06:00:00+03:00

I am pretty sure Java and Swift struggle with this kind of task, but 8th happily calculates any bit number and date time for it.

Use the right code and there is no struggle. But perhaps: only 8th can do JSon correctly und datetime processing. Have a nice time.

Yeah, and we are still waiting for that promised Java tutorial. Must be a really long weekend or your own date time processing sucks big time.

If and when somebody has no Idea how to do it in Java he should never say it is not able to. Small hint. I have timestamp applications which do exactly that. All time correct. Read. Learn and get that Java has no problems. Not with JSon not with DataTime. Man. Horrible things you want to suggest,

Naturally Java can do it, but working with JSON and big numbers in Java is a lot more work. I can throw for my program a bit number that maps to date and time that is 50 years into the future without any problems, time zone and daylight savings are properly taken into account.

TBH not sure I understand the requirement ??

Many languages have the ability to do proper date & time computations over long time spans

Idea is simply to encode schedules for home automation channels as bits. Every bit corresponds to a 15 minute time period. JSON, I posted gives just control state changes and times can also have a random +/- 90 second offset that needs to be adjusted away. Data can span multiple days, so big number math is needed for calculations. Time zone and daylight savings need to be taken account in calculations (day can have 23, 24 or 25 hours).

I can calculate bit position for current time:

  d:new d:>unix "Europe/Helsinki" unix>n dup . cr
  "Europe/Helsinki" d:new n>d . cr

Outputs:

69
2025-04-07T17:15:00+03:00

Uhm OK ?
Still doesnt make sense from that code & description

But thats not here or there
Some languages have an easier time expressing certain concepts than others
Doesnt mean they are better or worse since they may fall down in other areas

Erlang is really easy to do parallel code in but its weird in other ways
Forth works well for a certain set of problems - and isnt for others
Everyone could work in assembler but thats not terribly productive and why we have as many languages to chose from as we do

I also have touch screen based GUI. It requires just hardware KMS/DRM support for the home automation controller, no window managers or desktops are needed. User registers ‘Pörssäri’ account, and uses it’s web interface to setup installation (location, house type, installed solar panels, weather forecast, electricity tariff, heating system, etc). After that electrician just installs the controller, inserts SD-card and powers on the controller. Only setup needed on controllers end, is to set ‘Pörssäri device id’ from the settings menu. After that everything just works. It’s also possible to manually control channel state from the user interface.

sadly cant even read the docs as it all looks to be in Finnish ?

But, as I said, for certain applications its probably the right choice
Forth is often one language that is quickly ported to new hardware