Nim (programming language) on the Atari

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Nim (programming language) on the Atari

Post by czietz »

Disclaimer: In total, I have about a day's worth of experience with Nim. Please excuse if I get anything wrong or do something in an overly complicated way. Or feel free to correct me, if you're already familiar with Nim.

Over the New Year's break, I got a bit interested in the Nim programming language. In the words of its creators, "Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula."

What made it interesting to me was that it can use a C compiler as backend and -- with the proper configuration -- C code generated by the Nim compiler only depends on the standard C library. Also, it allows easy interfacing with C functions, e.g., to call operating system functions. In fact, the section Nim for embedded systems describes almost everything that was needed to compile Nim programs for the Atari using Vincent's gcc and MiNTLib.

Thus, I created a nim.cfg configuration file in my project directory containing...

Code: Select all

m68k.any.gcc.exe = "m68k-atari-mint-gcc"
m68k.any.gcc.linkerexe = "m68k-atari-mint-gcc"
gc = arc
passL="-s"
define = "useMalloc"
... and this allows me to compile programs:
nim c --cpu:m68k --os:Any -o:myprog.tos myprog.nim
... for the debug build or:
nim c --cpu:m68k --os:Any -d:release -o:myprog.tos myprog.nim
... for the (faster, smaller) release build.
(Note: the "passL" line in the configuration file is not strictly required, but instructs gcc's linker to strip symbols for smaller executables.)

Building with libcmini (instead of MiNTLib) is a bit more involved, in particular because libcmini requires its startup code (crt0.o) to be linked first, which normally the Nim compiler would not support.

However, this can be solved by an updated nim.cfg:

Code: Select all

m68k.any.gcc.exe = "m68k-atari-mint-gcc"
m68k.any.gcc.linkerexe = "m68k-atari-mint-gcc"
m68k.any.gcc.linkTmpl = "-o $exefile /home/czietz/libcmini-experimental/build/crt0.o $objfiles $options"
gc = arc
passL="-nostdlib"
passL="-L/home/czietz/libcmini-experimental/build"
passL="-lcmini"
passL="-lgcc"
passL="-s"
define = "useMalloc"
define = "noSignalHandler"
Notes:
* The path to libcmini must obviously be adapted to your system.
* "noSignalHandler" needs to be added because libcmini does not implement the signal() function.
* If you want to run the resulting executable under TOS (as opposed to MiNT), you should compiler libcmini with -DSTDIO_MAP_NEWLINE, so that it maps LF (as used by Nim's runtime as line ending) to CR/LF (as expected by TOS).

This allows you to build working, reasonably small executables with Nim.

During my first experiments, I found two small issues:
  1. A few of Nim's standard libraries are "impure" (their words), i.e., they depend on external libraries. For example, "re" (regular expressions) depends on the PCRE library. The Nim compiler wants to link to these dynamically which does not work on TOS (because of no shared library support). Maybe the compiler could be told to statically link to these, but I haven't explored that yet.
  2. Unfortunately, compiling with --os:Any disables printing of an explanatory error message in case of an uncaught exception. Instead the program just terminates, which makes debugging harder. The clean solution would of course be to add support for something like --os:AtariTOS (*) to the compiler/library, but for the time being, I fixed it by simply editing the standard library, specifically the system/excpt.nim file. (The library is provided as source code and modified files are automatically(!) recompiled when building your application. Nice!)

    Code: Select all

    proc reportUnhandledError(e: ref Exception) {.nodestroy.} =
      if unhandledExceptionHook != nil:
        unhandledExceptionHook(e)
      when true: #hostOS != "any":
        reportUnhandledErrorAux(e)
      else:
        discard ()
    
    (I just commented out hostOS != "any" bit.)
Instead of just a hello-world-style program, I wanted to write something specific to the Atari. So, here's a demo program that prints the cookie jar. Along the way, it shows some features of Nim, like easy calling of C funtions or macros (Super/SuperToUser), iterators (like, e.g., in Python), the table data structure (a hash table, much like Python's dict) indexed by strings, string formatting, exception handling ... For reference: When building this with libcmini and in the "release" configuration, the executable size is about 57 kB. When building this in the "danger" configuration (that removes all run-time checks) it's just 28(!) kB -- with all the modern language features compared to C.

Maybe I got someone interested in Nim, too.

Code: Select all

import tables
import sequtils
import strformat
import strutils
import volatile

type RawCookie = object
    id: clong
    val: clong

# UncheckedArray is an array without bounds checking, equivalent to a C '[]' array
type RawCookies = UncheckedArray[RawCookie]

type Cookie = object
    id: string
    val: int

# Easy syntax to call C functions
proc Super(val: clong): clong {.header: "<osbind.h>".}
proc SuperToUser(val: clong)  {.header: "<osbind.h>".}

# Converts an array of chars to a string
# openArray is an array with 'flexible' bounds, defined by the caller
proc chartoString(chars: openArray[char]): string =
    result = foldl(@chars, a & b, "")

# Returns the string representation of a cookie ID
proc cookieName(id: clong): string =
    result = chartoString(cast[array[4, char]](id)) # only works with a big-endian C long

# Retrieves the pointer to the cookie jar.
# Note that this pointer is stored at an address only accessible in supervisor mode.
proc getCookieJar: ptr RawCookies =
    let old_ssp = Super(0)
    # Use a volatileLoad (instead of a '[]' derefence) to make sure that value
    # is really being read between the Super/SuperToUser calls.
    result = volatileLoad(cast[ptr ptr RawCookies](0x5A0))
    SuperToUser(old_ssp)

# An iterator over all cookies in the jar
iterator cookieIterator(): Cookie =
    let COOKIE_JAR = getCookieJar()
    if COOKIE_JAR != nil:
        for k in 0 .. high(int):
            if COOKIE_JAR[k].id == 0:
                # found end of jar
                break
            yield Cookie(id: cookieName(COOKIE_JAR[k].id), val: COOKIE_JAR[k].val)

# Returns all cookies in a table indexed by cookie name (similar to a Python dictionary)
proc getCookiesTable(): auto =
    result = initTable[string, int]()
    for c in cookieIterator():
        result[c.id] = c.val

# Show 'strformat' formatting
for c in cookieIterator():
    echo fmt"Cookie '{c.id}' = {c.val:08X}"

# Show 'tables' module
let allCookies = getCookiesTable()
echo "_CPU cookie is: " & toHex(allCookies["_CPU"])
# Show exception handling
try:
    echo "FROB cookie is: " & toHex(allCookies["FROB"])
except:
    echo "FROB cookie not found!"
(*) The Nim compiler actually has a definition for --os:Atari, but I have no idea what this is supposed to target. If defines a executable file name extension of .tpp and expects an OS with shared libraries ending in .dll. (???)
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

This looks like something to my taste: simple and (apparently) effective. Thanks for sharing!

(and good use for libcmini is an extra plus ;), of course! )
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

The language seems to rely on indentation for grouped statements (obviously inspired by python). I consider that one of the biggest nonsense ever made, and reminds me of early versions of COBOL and FORTRAN... not something that i would call a modern programming language.
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

Fortunately, this is not proper the thread to discuss personal preferences w.r.t. to programming languages.

Getting on-topic again: Nim has "pure" (i.e. implemented in Nim) libraries for network access that only rely on the sockets interface and with little effort can be made to work under MiNTNet (MiNT's networking/IP stack).

For example, this is all it takes with Nim to make a HTTP request and print its result:

Code: Select all

import httpclient
var client = newHttpClient()
echo client.getContent("http://www.chzsoft.de/site/")
The following steps were needed to make this compile for the Atari:
- One has to add -d:posix to the command line to enable use of POSIX functions: nim c --cpu:m68k --os:Any -d:posix -o:http.tos http.nim.
- One has to compile with MiNTLib, as libcmini (by design) does not provide these functions.
- A few changes were required to the Nim standard library:

1. For "struct timeval" Nim imports "sys/select.h", but needs to import "sys/time.h". (This might actually be a bug in the Nim library, as this struct is supposed to be in "sys/time.h" even with POSIX.)
2. MiNTLib does not define the MSG_NOSIGNAL constant.
3. MiNTLib does not have clock_gettime(CLOCK_MONOTONIC, ...).

In summary, these are my changes to the Nim 1.4.2 library in "unified diff" format that make the above example work under MiNT:

Code: Select all

diff -ur nimorig/nim-1.4.2/lib/posix/posix_other.nim nim-1.4.2/lib/posix/posix_other.nim
--- nimorig/nim-1.4.2/lib/posix/posix_other.nim	2020-11-30 08:11:10.000000000 +0100
+++ nim-1.4.2/lib/posix/posix_other.nim	2021-01-04 18:03:23.550862500 +0100
@@ -353,7 +353,7 @@
     sched_ss_max_repl*: cint         ## Maximum pending replenishments for
                                      ## sporadic server.
 
-  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+  Timeval* {.importc: "struct timeval", header: "<sys/time.h>",
              final, pure.} = object ## struct timeval
     tv_sec*: Time ## Seconds.
     tv_usec*: Suseconds ## Microseconds.
diff -ur nimorig/nim-1.4.2/lib/pure/net.nim nim-1.4.2/lib/pure/net.nim
--- nimorig/nim-1.4.2/lib/pure/net.nim	2020-11-30 08:11:10.000000000 +0100
+++ nim-1.4.2/lib/pure/net.nim	2021-01-04 18:05:08.661801800 +0100
@@ -1640,7 +1640,7 @@
   when useWinVersion or defined(macosx):
     result = send(socket.fd, data, size.cint, 0'i32)
   else:
-    when defined(solaris):
+    when true: #defined(solaris):
       const MSG_NOSIGNAL = 0
     result = send(socket.fd, data, size, int32(MSG_NOSIGNAL))
 
diff -ur nimorig/nim-1.4.2/lib/std/monotimes.nim nim-1.4.2/lib/std/monotimes.nim
--- nimorig/nim-1.4.2/lib/std/monotimes.nim	2020-11-30 08:11:10.000000000 +0100
+++ nim-1.4.2/lib/std/monotimes.nim	2021-01-04 18:44:57.041571100 +0100
@@ -100,10 +100,12 @@
     result = MonoTime(ticks: ticks * machAbsoluteTimeFreq.numer div
       machAbsoluteTimeFreq.denom)
   elif defined(posix):
-    var ts: Timespec
-    discard clock_gettime(CLOCK_MONOTONIC, ts)
-    result = MonoTime(ticks: ts.tv_sec.int64 * 1_000_000_000 +
-      ts.tv_nsec.int64)
+#    var ts: Timespec
+#    discard clock_gettime(CLOCK_MONOTONIC, ts)
+#    result = MonoTime(ticks: ts.tv_sec.int64 * 1_000_000_000 +
+#      ts.tv_nsec.int64)
+    let ts = clock()
+    result = MonoTime(ticks: int64(float(ts) * (1_000_000_000 / CLOCKS_PER_SEC)))
   elif defined(windows):
     var ticks: uint64
     QueryPerformanceCounter(ticks)
diff -ur nimorig/nim-1.4.2/lib/system/excpt.nim nim-1.4.2/lib/system/excpt.nim
--- nimorig/nim-1.4.2/lib/system/excpt.nim	2020-11-30 08:11:10.000000000 +0100
+++ nim-1.4.2/lib/system/excpt.nim	2021-01-04 12:43:10.115932700 +0100
@@ -393,7 +393,7 @@
 proc reportUnhandledError(e: ref Exception) {.nodestroy.} =
   if unhandledExceptionHook != nil:
     unhandledExceptionHook(e)
-  when hostOS != "any":
+  when true: #hostOS != "any":
     reportUnhandledErrorAux(e)
   else:
     discard ()
mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Nim (programming language) on the Atari

Post by mikro »

Frankly, I have never heard of this language but from Atari point of view it definitely looks better than BASIC and more approachable (setup-, memory- and speed-wise) than, say, Python (I have intenionally omitted C and assembler).

If you ever finish this port, I'm sure it could inspire a programmer or two who are scared of C/asm yet willing to code on Atari. :)
joska
Hardware Guru
Hardware Guru
Posts: 5342
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Nim (programming language) on the Atari

Post by joska »

Interesting. I have never heard of Nim before either, but it looks very useful. Did you try to compile it for MiNT?
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
shoggoth
Nature
Nature
Posts: 1219
Joined: Tue Aug 01, 2006 9:21 am
Location: Halmstad, Sweden
Contact:

Re: Nim (programming language) on the Atari

Post by shoggoth »

This looks really interesting! Never heard of Nim before, but I decided to take a look at it now. It's got some Pythonesque qualities (I'm fairly hell bent on using C all the time, but when writing test code, coding tools, conversion tools, etc, I always resort to Python).

How it integrates so easily to C and the library functions and bindings we use on our platform makes this useful out of the box, that's a really nice feature tbh.
Ain't no space like PeP-space.
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

joska wrote: Mon Jan 04, 2021 6:39 pm Did you try to compile it for MiNT?
No. Frankly, I prefer cross-compilation; I don't even have a gcc set up under MiNT.
User avatar
calimero
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2575
Joined: Thu Sep 15, 2005 10:01 am
Location: Serbia
Contact:

Re: Nim (programming language) on the Atari

Post by calimero »

ThorstenOtto wrote: Mon Jan 04, 2021 3:14 pm The language seems to rely on indentation for grouped statements (obviously inspired by python). I consider that one of the biggest nonsense ever made, and reminds me of early versions of COBOL and FORTRAN... not something that i would call a modern programming language.
And what is “modern” by your standards?

Or better question: what is bad thing about strict indentions?

Sorry for offtopic :(
But I would really like to hear whats is bad with indentions...
And thanks for give us note of Nim.
Last edited by calimero on Mon Jan 04, 2021 8:13 pm, edited 1 time in total.
using Atari since 1986.http://wet.atari.orghttp://milan.kovac.cc/atari/software/ ・ Atari Falcon030/CT63/SV ・ Atari STe ・ Atari Mega4/MegaFile30/SM124 ・ Amiga 1200/PPC ・ Amiga 500 ・ C64 ・ ZX Spectrum ・ RPi ・ MagiC! ・ MiNT 1.18 ・ OS X
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

And this is an FTP example that can be compiled for and run under MiNT after removing two further occurences of MSG_NOSIGNAL in asyncdispatch.nim (in the Nim standard library).

Code: Select all

import asyncdispatch, asyncftpclient
proc main() {.async.} =
  var ftp = newAsyncFtpClient("ftp.funet.fi", user = "ftp", pass = "ftp")
  await ftp.connect()
  echo("Connected")
  let dir = await ftp.list("/pub/atari")
  echo(dir)

waitFor(main())
I still have to understand, though, how async/await exactly works under Nim.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

czietz wrote: Mon Jan 04, 2021 8:07 pm after removing two further occurences of MSG_NOSIGNAL in asyncdispatch.nim
I think that should be worked around by using ifndef MSG_NOSIGNAL. Older glibc versions don't have that flag defined, either, so i think it is not available everywhere. Another option would be to add it to mintlib, but of course that does not mean it is implemented in the socket library.
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

OSX does not implement MSG_NOSIGNAL as well. So there is likely a code path there already that implements a workaround for it.

Probably the most compatible way is to follow the same path (didn't look into it, but I would assume it just installs a signal handler for SIGPIPE that does nothing).
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

Yes, there is...

Code: Select all

when defined(macosx):
  # We can't use the NOSIGNAL flag in the ``send`` function, it has no effect
  # Instead we should use SO_NOSIGPIPE in setsockopt
  const
    MSG_NOSIGNAL* = 0'i32
  var
    SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
elif defined(solaris):
  # Solaris doesn't have MSG_NOSIGNAL
  const
    MSG_NOSIGNAL* = 0'i32
elif defined(freertos) or defined(lwip):
  # LwIP/FreeRTOS doesn't have MSG_NOSIGNAL
  const
    MSG_NOSIGNAL* = 0x20'i32
else:
  var
    MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
      ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
So, a possible way would be to add an atari or mintlib define here and for all my other changes. That would be relatively simple, compared to the bigger change of adding a new OS to the compiler and library. (I'll only go through the effort of the latter if I decide to code a bigger project in Nim.)
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

mfro wrote: Tue Jan 05, 2021 9:01 am (didn't look into it, but I would assume it just installs a signal handler for SIGPIPE that does nothing).
It's flag for send()/recv(), so it can't just install a signal handler. It's the other way around: if the flag is set, no SIGPIPE signal is sent to the current process (the functions still return an EPIPE error code however).

A signal handler could be installed by the application, but for a library that is troublesome. The same signal could come a died forked process. Also the application might have already installed a signal hander, for other purposes.

Implementing that flag in MiNT should not be too difficult (see attached patch), but that may be too late (you would need an updated kernel, or at least updated inet4.xdd). And a corresponding define has of course also be added to mintlib. Until then, you need to check whether you can get away with just defining the flag to zero (maybe you get unexpected process terminations in some cases).
You do not have the required permissions to view the files attached to this post.
User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 13285
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Nim (programming language) on the Atari

Post by wongck »

HAH... finally networking with signals making some headway.... something I was asking on Mintlist back in 2017.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff that are no longer for sale due to them over 30 years old - click here for list
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

Would be nice if someone could test the patch, then i can push it (just copy the definition of MSG_NOSIGNAL to <somepath>/include/bits/socket.h, or locally where you use it).

PS.: do you have a link to a mailing list archive for that request?
mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Nim (programming language) on the Atari

Post by mikro »

I think wongck means this thread: https://github.com/freemint/freemint/issues/53
PeterS
Atari Super Hero
Atari Super Hero
Posts: 640
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Nim (programming language) on the Atari

Post by PeterS »

ThorstenOtto wrote: Mon Jan 04, 2021 3:14 pm The language seems to rely on indentation for grouped statements (obviously inspired by python). I consider that one of the biggest nonsense ever made, and reminds me of early versions of COBOL and FORTRAN... not something that i would call a modern programming language.
Yaml has the same retrograde step back to the bad old days.

Those who forget their history are doomed to repeat it.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

mikro wrote: Tue Jan 05, 2021 8:52 pm I think wongck means this thread: https://github.com/freemint/freemint/issues/53
That discussion was mostly about SIGIO, to signal processes when data is available. SIGPIPE is basically the opposite, when the process that is supposed to receive the data has died.
User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 13285
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Nim (programming language) on the Atari

Post by wongck »

Darn it !!! Back to square 1 then.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff that are no longer for sale due to them over 30 years old - click here for list
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

In case you're wondering what's so great about tables, iterators, etc. (even if this means bidding farewell to your beloved curly braces, SCNR!); they allow an simple and comprehensible syntax to access even complex data structures.

Code: Select all

import httpclient
import net
import json
import strformat

const Location = "Berlin"

var client = newHttpClient()
let jsondata = client.getContent("http://api.weatherbit.io/v2.0/forecast/daily?key=MY_SECRET_API_KEY&days=4&city=" & Location)
let jsonobject = parseJson(jsondata)
let location = jsonobject["city_name"].getStr() & ", " & jsonobject["country_code"].getStr()
echo "Weather forecast for: ", location
for forecast in jsonobject["data"]:
    let fortime = forecast["valid_date"].getStr()
    let forcond = forecast["weather"]["description"].getStr()
    let formax = forecast["max_temp"].getFloat()
    echo "Forecast for {fortime}:  {formax: 5.1f} \xf8C, {forcond}".fmt
... prints a weather forecast pulled from the net:
IMG_4586.JPG
(The forecast includes much more data that can be accessed just as easily.)

PS: I've started organizing my changes in a fork on Github: https://github.com/czietz/Nim/commits/Atari_TOS_support. In contrast to my initial post, this now allows for compilation with --os:Atari. But beware that this is very much WIP!
You do not have the required permissions to view the files attached to this post.
mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Nim (programming language) on the Atari

Post by mikro »

Wow, this is really 21st century code on our small Ataris, amazing!
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

Same thing in perl:

Code: Select all

#!/usr/bin/perl -w

use strict;

use LWP::Simple;
use JSON;

my $Location = 'Berlin';
my $url = 'http://api.weatherbit.io/v2.0/forecast/daily?key=MY_SECRET_API_KEY&days=4&city=' . $Location;

my $jsondata = LWP::Simple::get($url);
my $jsonobject = decode_json($jsondata);

my $data = $jsonobject->{data};

foreach my $forecast (@$data)
{
	my $fortime = $forecast->{valid_date};
	my $forcond = $forecast->{weather}{description};
	my $formax = $forecast->{max_temp};
	printf("Forecast for %s:  %5.1f \xc2\xb0C, %s\n", $fortime, $formax, $forcond);
}
But with some curly braces :D
mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Nim (programming language) on the Atari

Post by mikro »

@ThorstenOtto but compare the installation effort and runtime requirements. As I understand it, Nim's .prg is in tens of kilobytes and doesn't need anything else, i.e. running on plain ST + networking stack.
User avatar
viking272
Atari Super Hero
Atari Super Hero
Posts: 705
Joined: Mon Oct 13, 2008 12:50 pm
Location: west of London, UK

Re: Nim (programming language) on the Atari

Post by viking272 »

This looks really interesting, never heard of it before either - thanks Czietz
Post Reply

Return to “Coding”