❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

HAC - recursive maze generator demo

28 May 2020 at 19:53
New example/demo, adapted from Rosetta Code's recursive maze generator.
HAC's Web site is here, source code is mirrored here.
Behind the scenes, the compiler was improved a little bit for displaying fixed-sized strings.

C:\Ada\hac\exm>..\hax -v2 maze_gen.adb

*******[ HAX ]******* Compiler version: 0.061 dated 28-May-2020.
*******[ HAX ]******* Caution: HAC is not a real Ada compiler. Type "hax" for license.
. . . .[ HAX ]. . . . Compiling from file: maze_gen.adb
. . . .[ HAX ]. . . . Compilation finished in 0.000414700 seconds.
. . . .[ HAX ]. . . . Starting p-code VM interpreter...
Height: 15, Width: 24
Starting generation at 7, 12
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | |
+ +---+ +---+---+ + +---+ +---+ +---+---+ + + + + +---+---+---+---+---+ +
| | | | | | | | | | | | | | |
+---+ +---+ +---+ + +---+---+ + + +---+---+---+ + +---+---+ + +---+ +---+
| | | | | | | | | | | |
+ +---+ +---+---+---+ +---+ + + +---+---+---+ + +---+ +---+ + +---+---+ +
| | | | | | | | | | | | | | |
+ +---+ + + + + + + +---+---+ + + + +---+ +---+ +---+ +---+---+ +
| | | | | | | | | | | | | | | | | | |
+---+ + + + +---+ + + + + + + + +---+ +---+ + + + + +---+ +
| | | | | | | | | | | | | | | | |
+ +---+ +---+---+ + + +---+ + +---+ + + +---+ +---+---+ +---+ + +---+
| | | | | | X | | | | | | | | |
+ + +---+---+ +---+---+ + +---+---+ + + + + + +---+ +---+ +---+ + +
| | | | | | | | | | | | | | | | |
+ +---+ + +---+---+ +---+---+---+ +---+---+ +---+ +---+ +---+---+ + + + +
| | | | | | | | | |
+ + +---+ + +---+---+ +---+---+---+ + +---+ + +---+---+ +---+---+---+---+ +
| | | | | | | | | | | | | | |
+ + + + + + + + + + +---+ + + +---+---+---+ +---+---+---+---+ +---+
| | | | | | | | | | | | | |
+---+ + + +---+---+---+---+ +---+ +---+ + + + + +---+---+---+---+ +---+ +
| | | | | | | | | | | | |
+ +---+---+---+ +---+---+ +---+ + + +---+ +---+ +---+---+---+ +---+---+ + +
| | | | | | | | | | |
+ + +---+---+---+---+ +---+---+---+ +---+---+---+ + +---+---+---+---+ +---+---+ +
| | | | | | | | | | | | |
+ + + + + + + +---+ + +---+---+---+ + +---+---+---+ +---+ + +---+ +
| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
-------[ HAX ]------- VM interpreter done after 0.080759500 seconds.

C:\Ada\hac\exm>

HAC v.0.07 - Exceptions and trace-backs

1 June 2020 at 14:35
Since yesterday, errors are propagated by HAC, as expected, down the call stack.
You get by default a detailed trace-back, like the following one. HAC's output is:
  HAC VM: raised Constraint_Error
Out of range
Trace-back locations:
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 18
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF at line 27
exception_04.adb: Exception_04.Nest at line 34
exception_04.adb: Exception_04 at line 42
GNAT's output on the same program is:
  raised CONSTRAINT_ERROR : exception_04.adb:18 range check failed
[C:\Ada\hac\test\exception_04.exe]
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:18
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf at exception_04.adb:27
Exception_04.Nest at exception_04.adb:34
Exception_04 at exception_04.adb:42
Main at b__exception_04.adb:294

You can look in the "test" directory at the files "exception_01.adb", "exception_02.adb", ... for playing with some examples.

HAC (HAC Ada Compiler) is available on two open-source development sites:

  https://hacadacompiler.sourceforge.io/
  https://github.com/zertovitch/hac

HAC is a small, quick, open-source Ada compiler, covering a subset of the Ada language.
Even though the HAC documentation is more or less non-existent, the good news is that you can use as a help Ada books and online documentation about Ada: HAC does not define a dialect of Ada, only a subset. A glimpse into the file "src/hac_pack.ads" gives you the currently available types and subprograms.

Enjoy!

LEA 0.71 - exception trace-back

3 June 2020 at 18:31
Following the implementation of trace-backs in HAC, this feature is now included in the LEA editor.

Better showing an example. Suppose your Ada program has a bug that was not detected at compile-time (it happens sometimes), like an array index being out-of-range. In this case HAC will raise a Constraint_Error exception (as expected from any Ada system).



Once you have closed the message box about the unhandled exception, the message list will display the trace-back, that is the chain of all subprogram calls at the moment the error has happened. Here we have an example with recursive calls, and the error was planted for the moment where the parameter Level is 0.
For your comfort, you can click on a line of the trace-back and LEA will find the correct file and the correct line as well!



Here is a link to LEA: https://l-e-a.sourceforge.io/.
You can download a read-to-use Windows executable there.

The LEA sources are available on the above site as well as on GitHub: https://github.com/zertovitch/lea .

Furthermore, the sources for the HAC system are located at
    https://hacadacompiler.sourceforge.io/
and
    https://github.com/zertovitch/hac .

Enjoy!


HAC v.0.072 - Subtype Indication

7 June 2020 at 19:44
One more step in our adventures in compiler construction...
Recently, we've moved the parsing of ranges to a new package, HAC.Parser.Ranges.
One chunk was about static ranges like "1 .. 5" for defining arrays.
The second chunk was the dynamic ranges in FOR loops (like in "for i in j + k .. l * 2 loop").
It was logical to put both pieces in the same package, especially since the Ada standard has a much more general definition: discrete_subtype_definition (RM 3.6 (6)).
Of course, with HAC, we don't try to implement the full standard or even the full dynamic aspects of a single syntactical element like discrete_subtype_definition, which allows constructs like this one:
    procedure SD3 is
begin
for I in 1 .. 3 loop
declare
type T1 is new Integer range 1 .. I * 5; -- I is dynamic
subtype T2 is T1 range 1 .. T1 (I);
type T3 is array (1 .. 2 * I) of T2;
type T4 is array (1 .. 3 * I) of T3;
B: T4;
begin
null;
end;
end loop;
end;

We prefer to add piece by piece features we find cool in Ada.
For instance, the subtype_indication (RM 3.2.2).
Again, something that sounds very bureaucratic, but what it represents is a very powerful shortcut:
Instead of writing
    x : array (False .. True) of Integer;

you can write in a nicer way:
    x : array (Boolean) of Integer;

same for loops:
    for b in Boolean loop
x (b) := ...
end loop;
As an illustration, here is an excerpt of the before/after comparison on one of the HAC examples:

Click to enlarge

New Fed Put Levels (Update: June 2020)

17 June 2020 at 11:57
In the 20th century, financial investment was a complex and serious topic.
You had to choose your mix of bonds of various maturities and risk levels - all associated with a very broad range of rates.
Similarly, you could build your mix of stocks (value vs. growth) or replicate more or less an index.
There was this thing called "free market". Good or bad - this is not the question. Perhaps it was just to show to the "Reds" that this notion of "free markets" was working so much better.

Now, things are much simpler. After a series of crises (dotcom, subprimes, Euro zone, and recently, the covid-19) the central banks have been more or less forced to set interest rates to zero or less, and frequently launch new programs for monetizing bonds and other financial assets. Governments take the opportunity of low interest rates and monetization not to balance their budget, but to increase their debts to the infinity. Same for corporations and even individuals. Zero rate = infinite leverage. Easy.

So, presently, all is simple. Bonds are a nonsensical business for investors - except those who are obliged to buy them, like insurances. Regarding stocks, old-school valuations like P/E ratios, or book value, or dividends, or credit rating of the underlying company, do not matter anymore: the Fed or the ECB will buy everything, even junk bonds. A funny consequence is that stock of bankrupt companies like Hertz are doing well, and the same Hertz is now selling new shares while under Chapter 11. Perhaps they will sell enough to balance their books, who knows!

Since the Fed's latest emergency plan a couple of days ago, we know what are the current approximate, implicit levels at which the Fed will do something more to support the financial markets.



Trade accordingly!
__
PS: The parts of the charts' data prior to 2020 was automatically digitized by the Recurve tool (part of the open-source Generic Image Decoder project in Ada).
PPS: here a "meme" about the subject:


LEA 0.74 - embedded Ada samples collection

27 June 2020 at 20:23
From now on, LEA has got the uber-gadget: a samples collection.
Are you looking for an example to start a script, or an algorithm, or some other inspiration?
The menu selection "Actions → Code sample" will offer you a choice of programs of various sizes.
Actually, they are examples from the HAC project (the HAC compiler is embedded in LEA).
You don't even need to fish those examples in the Internet: they are embedded within LEA as well.
In a few clicks, an example will pop in a LEA window and you can run it immediately.

LEA (Lightweight Editor for Ada) is a free, open-source software. It can be found here.

Feedback is appreciated.
Don't hesitate to sponsor the project with a small donation (from the link above: "Donate" link).

Enjoy!

New menu entry: Code sample (click to enlarge image)

Sample selector (click to enlarge image)

Bullshit Generator: the Next Steps

1 July 2020 at 06:11
Here we admire again the recyclability of high-quality bullshit. The latest additions to the CBSG stem from an article written in 1996 - a time when the double-digit-growth boys were busy replacing boring industry by shiny finance. The article was found by bootstrapping (mark a sentence from the CBSG, search it with your preferred search engine). Some extracts are appealing:
Enron didn't rely on huge "bet-the-company" gambles to create growth. Each step was a manageable investment that built on established capabilities and offered the potential to add new ones.
A company need not possess strengths in all areas of a business—just in the areas important to making money. Growers distinguish between attributes that garner value and those that are simply necessary to play the game. Enron became a world leader in international private power generation because it saw that profit did not depend on construction and operation skills, but on deal structuring and risk allocation.
Anyway. Here are some new key additions to the CBSG, put in practice:

One thing about talent retention is clear: reputation and resiliency turbocharge a values-based market practice.
One thing about data practices is clear: delivery framework, competitive differentiator and solution boost architectures.

The Digital Marketers create strategic options and opportunities across geographies.
The pioneers create strategic options and opportunities going forward.

Opting out of reorganizations is not a choice, while the team players create new business options.
A profit-maximizing portfolio shaping 24/7 reenergizes a motivational onboarding solution. As a result, the team players create new business options.

Trending your numbers should carve a competitive position.
The point is not merely to carve a competitive position. The point is to reinvest in a high-grade footprint.

The team players preempt competitors by thinking outside of the box.
High-performance benchmarkings challenge us to preempt competitors.

The group facilitates our value-chain without pre-empting or constraining future flexibility.
The key representatives improve top-line talents without pre-empting or constraining future flexibility.

The challengers co-specify cross-platform, bifocal, evolutions.
The resources formulate a non-linear, bifocal and hyper-hybrid business equation.
Fully networked, company-first, industry market shifts challenge us to front-face bifocal value propositions.

Cross-pollinations deepen a manageable brand value.
The white-collar workforce potentiates manageable efficient frontiers.
Manageable portals motivate the market thinker.

The tolerably expensive, innovative, digital acceleration interacts with our distinctive workflows.
The decision makers strengthen distinctive swim lanes.
The enablers take control of structured, distinctive, organizational and high-level visibilities.
Probably, if we search for "wirecard double-digit growth" we'll find some fresh stuff for the CBSG...

Pasta! Statistics

4 August 2020 at 15:04
For your fun, here is in a chart the statistical distribution of the players of the Pasta! game, per level.

Click to enlarge

The yellow bars show the number of players who have completed level n (after the scoring system was implemented).
The bars in other colours show where the players are currently and the maximum level they are allowed to play (1, or the highest completed level + 1).

Together forever...

26 August 2020 at 08:51

Latest commit to the Corporate Bullshit Generator (live web app - source site 1 - source site 2): only one addition, but which one!

[prompt] produce_corporate_bullshit -h

Options:
-1, --one, --sig single sentence
-b, --bulk EXPR infinite loop; shows only sentences with EXPR
-h, --help this help
-w, --workshop workshop format

[prompt] produce_corporate_bullshit -b "together, we"

Together, we synergize a workforce-focused, deterministic, global touch-base.
Together, we prioritize well-implemented accelerators.
Together, we solutionize profiles.
Together, we execute on priorities.
Together, we enhance game-changing strategic staircases.
Together, we identify known unknowns.
Together, we facilitate our competitive success.
Together, we whiteboard outward-looking challenges.
Together, we create momentum.

Zip-Ada for Audacity backups

22 September 2020 at 18:21

Audacity is a free, open source, audio editor, available here.

If you want to backup you Audacity project, you can manually do it with "Save Lossless Copy of Project..." with the name, say, X, which will create X.aup (project file), a folder X_data, and, in there, a file called "Audio Track.wav".

Some drawbacks:

  • It is a manual operation.
  • It is blocked during playback.
  • Envelopes are applied to the "Audio Track.wav" data. So data is altered and no more a real lossless copy of the project. Actually this operation is something between a backup and an export of the project to a foreign format.

A solution: Zip-Ada.

The latest commit (rev. 796) adds to the Preselection method a specific configuration for detecting Audacity files, so they are compressed better than with default settings.

Funny detail: that configuration makes, in most cases, the compression better than the best available compression with 7-Zip (v.19.00, "ultra" mode, .7z archive).

The compressing process is also around twice as fast as 7-Zip in "ultra" mode. This is no magic, since the "LZ" part of the LZMA compression scheme spends less time finding matches, in the chosen configuration for Zip-Ada.


A backup script could look like this (here for Windows' cmd):

rem --------------------------
rem Nice date YYYY-MM-DD_HH.MM
rem --------------------------

set year=%date:~-4,4%

set month=%date:~-7,2%
if "%month:~0,1%" equ " " set month=0%month:~1,1%

set day=%date:~-10,2%
if "%day:~0,1%" equ " " set day=0%day:~1,1%

set hour=%time:~0,2%
if "%hour:~0,1%" equ " " set hour=0%hour:~1,1%

set min=%time:~3,2%

set nice_date=%year%-%month%-%day%_%hour%.%min%

rem --------------------------

set audacity_project=The Cure - A Forest

zipada -ep2 "%audacity_project%_%nice_date%" "%audacity_project%.aup" "%audacity_project%_data\e08\d08\*.au"

GWindows: Desktop shortcuts and Explorer context menu

29 September 2020 at 10:13

Just in time to celebrate the 25th anniversary of Windows as we know it (ouch!), here is a gadget-ish contribution to the GWindows library, the open-source Ada library for MS Windows, available here and here.

In there gwindows/contrib directory, there is gwin_util.ads (spec.) and gwin_util.adb (body), and in gwindows/contrib/test, there are demos. All that is available comfortably through the gwindows_contrib.gpr project file in the gwindows directory.

  1. test_shortcut.adb:


  2. test_explorer_context_menu.adb:




HAC v.0.075: time functions: goodies for scripting tasks

20 October 2020 at 19:44
Today, HAC has a few more functions, from Ada.Calendar. I have added them in order to translate a Windows cmd script to Ada (with HAC_Pack). More precisely, it's "save.cmd", which takes a snapshot of the sources of the HAC system and other key files. This snapshot is a Zip archive and has a time stamp in its name, like "hac-2020-10-20-20-27-36-.zip". Hence the addition of standard functions like Year, Month, etc. The script is very practical for making backups between commits via subversion or git, and for other purposes. Now the script is called "save.adb" and does the same job, but not only on Windows, but also on Linux or other Operating Systems. Since the Zip compression is also programmed in Ada (Zip-Ada), you have in that script example a cool situation of Ada invading your computer 😊.

Here, a screenshot of the added functions running from the LEA editor (hum, also a full Ada software, by the way!):

HAC 0.075 running from LEA. Click to enlarge.

More to come soon with some subprograms stemming from Ada.Directories.

HAC is free and open-source, you can find it here and here.

HAC v.0.076: Ada.Directories-like subprograms

24 October 2020 at 07:12

After Ada.Calendar-like subprograms, here are now Ada.Directories-like subprograms which facilitate shell scripting with HAC in a portable way.

As usual, the easiest way to see the full set of additions is to look into HAC_Pack's specification, hac_pack.ads:

      function Current_Directory return VString;

procedure Set_Directory (Directory : String) renames Ada.Directories.Set_Directory;
procedure Set_Directory (Directory : VString);

procedure Copy_File (Source_Name : String; Target_Name : String);
procedure Copy_File (Source_Name : VString; Target_Name : String);
procedure Copy_File (Source_Name : String; Target_Name : VString);
procedure Copy_File (Source_Name : VString; Target_Name : VString);

procedure Delete_File (Name : String) renames Ada.Directories.Delete_File;
procedure Delete_File (Name : VString);

function Exists (Name : String) return Boolean renames Ada.Directories.Exists;
function Exists (Name : VString) return Boolean;

procedure Rename (Old_Name : String; New_Name : String) renames Ada.Directories.Rename;
procedure Rename (Old_Name : VString; New_Name : String);
procedure Rename (Old_Name : String; New_Name : VString);
procedure Rename (Old_Name : VString; New_Name : VString);
HAC is free and open-source, you can find it here and here.

The HAC scripts invasion

27 October 2020 at 12:42

Perhaps you were already confronted to this problem:

  • You have "housekeeping" shell scripts for cleaning files, building tools, listing results, etc. . 
  • You would like to have the project, that these scripts are serving, running on multiple systems: Linux, MacOS, Windows, ... Especially for highly portable Ada projects, it is almost a must.
  • But in the end, you have lots of duplicate scripts: for each script one version for Linux, one version for Windows.
The solution: use HAC (the HAC Ada Compiler).

One practical example of script simplification can be found in the Zip-Ada project.
In the test directory, there were test_za.cmd and test_za.sh, meant to do the same thing: testing the compression side of the library. But the scripts were out of sync, and it was a pain to make them converge. So it was a perfect opportunity to switch to HAC, which has since its 0.076 version standard subprograms for file management. The unified script is test_za.adb, can be run with the hac test_za.adb command.
Now test_rz.cmd and test_rz.sh (for testing the Zip archive recompression tool, ReZip) are also unified, and so are make_za.cmd and make_za.sh for building everything.

More generally HAC scripts have tremendous advantages:
  • They are plain Ada, so there is no need to learn a new language.
  • If you need it, they can be compiled with an Ada compiler. It can be for different reasons:
    • You need performance (nested loops, for instance). You'll get C-level performance, at least with the GNAT compiler.
    • You need more functionalities that are not present in HAC.
    • You are afraid HAC is not developed or supported further.
Here are a few screenshots:



The screenshots are taken from TeXCAD and LEA - other Ada projects 😏...

Some research with LZMA...

28 November 2020 at 19:54

A rare case where Zip-Ada's LZMA encoder is much better than LZMA SDK's. Rare but still interesting, and with standard LZMA parameters (no specific tuning for that file):


The compressed size with current revision (rev.#882) of Zip-Ada is slightly worse (42,559 bytes).

The file is part of the classic Canterbury Corpus compression benchmark data set.

Advent of Code 2020 with HAC and LEA

2 December 2020 at 20:27

First use of HAC, via the LEA editor, for the famous Advent of Code contest.

LEA screenshot: a parser for Day 2 Advent of Code's puzzle

In my (of course biased) opinion, LEA is perfect (among other tasks...) for developing quickly Ada solutions to the Advent of Code problems.

After the rush, I tidy up the source code with GNAT's style checks. Hence the presence of a GNAT project file, aoc_2020.gpr .

Then I post my solutions as HAC examples, here and here


HAC built with ObjectAda 10.2

6 December 2020 at 14:31

When you think that your software is highly compiler- and operating-system-independent, it is only a guess until you can verify it.

For HAC (the HAC Ada Compiler), the OS-independence is easy to verify thanks to GNAT, the well-known free Ada compiler.

Regarding the full independence, it is a bit trickier. There are two items (which are subprograms in the HAC_Pack package), that are intrinsically non-portable and not covered by the standard Ada libraries whose authors bear the burden of finding implementations:

  package Non_Standard is
    procedure Sys (Command : String; Result : out Integer);
    function Directory_Separator return Character;
  end Non_Standard;

Two subprograms in 12595 lines of code spanning over 59 source files (revision #306) - it's not a such a big deal.

So a real test was to build HAC with the ObjectAda64 for Windows development environment.

Surprise (but with Ada, it was still a bit expected...): the build went completely seamlessly once I had selected "Ada 2012" in the project settings (HAC's source use a few Ada 2012 features).

Zero error, and the real surprise: zero warning.

The ObjectAda implementation for the above package Non_Standard actually required more work than building the Ada sources (basically, a few mouse clicks). For Directory_Separator, it was easy since we could hardcode '\' given the Windows target. For the procedure Sys, we were able to use the same C function (system) as for the C library that comes with GNAT since the Microsoft run-time imitates some Unix (and then GNU) functionalities. Then, having the linker finding system was the real challenge. Basically if you reference the Win32 library in the project, the linker somehow finds system. Don't ask me how, it's part of the mysteries of the tools that emulate modularity for C (to say things politely).

Enough dirty details, here is a screenshot:

ObjectAda's Integrated Development Environment, right after a complete build of HAC. Click to enlarge.

HAC is free and open-source, sources can be found here and here.


HAC at work with shiny gold bags (Advent of Code, Day 7)

7 December 2020 at 14:13

Day 7 of the Advent of Code, titled "Handy Haversacks" is nice pair of puzzles involving recursion.

The data is a set of rules, beginning with

wavy green bags contain 1 posh black bag, 1 faded green bag, 4 wavy red bags.

dotted chartreuse bags contain 1 light beige bag.

dark white bags contain 2 dotted white bags.

... 

There are hundreds of such rules.

The puzzles involve recursion, which makes them fun.

You can see below HAC at work on the problem, from the LEA editor.

There is also a "full Ada" version. I began with that one, because the current limitations of HAC would have been too time-consuming (in terms of development time) for submitting a solution quickly enough. The limitations are not around recursion, that HAC masters like a big one, but mostly around the enumeration type I/O which is currently non-existent in HAC (v.0.081).

Click to enlarge

Solutions will be soon be posted on the HAC repositories.

❌
❌