DEV Community

JoeStrout
JoeStrout

Posted on

What's New in Command-Line MiniScript v1.2

This week saw the release of version 1.6 of the MiniScript language, as described here a couple days ago. But it also came with an update to command-line MiniScript, with some significant new features of its own.

The biggest and most obvious change is that command-line MiniScript now supports the import command, just like Mini Micro. This loads another script, located by name among an ordered set of import module directories, and makes any file-level variables in that module available to the main script. For example, MiniScript has no built-in "distance" function, but the new mathUtil module does:

MiniScript 
Command-Line (Unix) v1.1; language v1.6.0 (Feb  5 2023)
> import "mathUtil"
> mathUtil.distance([1,5], [10,7])
9.219544
Enter fullscreen mode Exit fullscreen mode

Command-line MiniScript now comes with 11 standard import modules:

  • dateTime: functions for getting the current time/date, and manipulating times and dates, including conversion to/from strings
  • grfon: converts data to and from the GRFON serialization format (sort of like JSON, but more compact and human-friendly)
  • json: converts data to and from JSON format
  • listUtil: dozens list-related utilities and extension methods
  • mapUtil: a dozen utility functions related to maps (dictionaries)
  • mathUtil: mathematical functions and constants
  • matrixUtil: functions to do matrix math with 2D arrays
  • qa: "quality assurance" module, providing methods like qa.assert
  • stringUtil: a large selection of string manipulation methods, including fill and match
  • tsv: converts data to and from Tab-Separated Value format
  • vt: provides VTxxx escape codes for controlling colors, cursor position, and font in a terminal window

Image description

The new import function will search for a module, by default, first in a lib folder next to the script, then in a lib folder next to the executable. The standard installation would keep these official modules, plus any custom modules you want to be always available, in the folder next to the executable; and then create project-specific include modules in the project's lib folder. But you can arrange them however you like, using the MS_IMPORT_PATH environment variable to control where MiniScript looks.

All this is functionality that Mini Micro users have taken for granted, but until this 1.2 update, command-line MiniScripts had to be contained entirely in one file, and there was no simple way to get access to these standard libraries. This is a real game-changer! Now, not only can you benefit from the standard modules, but you can also break your large projects up into neat, self-contained modules called by the main program.

Now that this capability is there, I hope we'll start to see all sorts of creative and interesting import modules written by the user community. How about one to generate SVG or PDF files? Or one for stats and data analysis? How about something to simplify CGI programming? Or even something as simple as a log module, that neatly manages the proliferation of log files that results?

The possibilities are endless. I can't wait to see what you dream up!

Top comments (1)

Collapse
 
sebnozzi profile image
Sebastian Nozzi

Great stuff. The import-functionality is indeed a game-changer.