Sunrise/sunset 8th sample

Here is a simple 8th sample on how to get sunrise/sunset times for given location. I use this stuff in my home automation software.

needs astro/sunrise
needs geo/cities

\ Set location
: location!  \ m  --
  ["lat", "lon"] m:_@ a:open
  astro:longitude ! astro:latitude ! ;

: d:tzoffset?  \ -- n
  "%Z" d:new d:format ":" s:/ ' >n a:map
  [60,1] ' n:* a:2map ' n:+ 0 a:reduce ;

: astro  \ d -- sunrise sunset
  "%Y-%M-%DT" over d:format >r astro:sunrise 2 a:close
  ( 60 n:* 60 n:/mod "%02d:%02d:00+00:00" s:strfmt r@ swap s:+ d:parse d:tzoffset? d:tzadjust ) a:map
  rdrop a:open ;

: sunrise?  \ d -- d
  astro drop ;

: sunset?  \ d -- d
  astro nip ;

: app:main
  argc 2 n:= !if
    "Requires city and country code as params" throw

  0 args 1 args loc:city_country 0 a:_@ null? if
    "Could not find location" throw
    location! d:new astro 2 a:close ["Sunrise at: %H:%T:%S%Z", "and sunset at: %H:%T:%S%Z.\n"] ' d:format a:2map
    " " a:join .
  then ;

Sample takes city and country code as input parameters from command line and outputs sunrise and sunset times as local time:

ohjaus@raspberrypi:~ $ /opt/8th/bin/rpi64/8th astro.8th Hämeenlinna FI
Sunrise at: 06:15:00+03:00 and sunset at: 20:26:00+03:00.
ohjaus@raspberrypi:~ $

8th looks really interesting. Though to someone not familiar with 8th, it is quite cryptic.

It is a cryptic language with hard to read code and hard to maintain code. But it has fans which believe it is the future. What shall I say, I am happy while not using it. But is somebody feels that’s his way: why not?

Why do you think code is hard to maintain? I have used it for home automation, net stuff, small games, morphing program, my own tilemap based platformer game engine…

It definitively looks cryptic to those unfamiliar with the language’s syntax. This is also true for regular expressions and any type of code (sic!) when the reader has no knowledge of the syntax.

1 Like

Even with the knowledge of the syntax it is hard to read. Something to solve mathematical problems? Yes. Something I would use to write text next form of Data keeping App? Gawd no. But so everything has it’s target audience.

People intentionally make languages this cryptic as a joke: