โŒ About FreshRSS

Normal view

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

Advent of Code 2023, day 10

10 December 2023 at 17:12

The puzzle: https://adventofcode.com/2023/day/10

My Ada solution: here.

In a picture (generated by the program linked above)...

Click to enlarge

ย 

It is always a pleasure to display the data created by Eric Wastl.

Here, an improved representation with the five cases (outside tile, inside tile, inside pixel on a path tile, outside pixel on a path tile, path pixel) in shown different colors:

Click to enlarge


LEA, a tiny but smart editor

14 October 2023 at 13:39

Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.


LEA, the Lightweight Editor for Ada, is based on the Scintilla text editor widget, which excels at colouring syntactic elements and letting the user rework his or her programs very swiftly, including manipulating rectangular selections and adding text on multiple points (usually vertically aligned).
But until recently, the cool features were limited to automatic indentation, adding comment delimiters (--) at the right column, or highlighting portions of text that match a selection.
Users were frustrated by not finding in LEA programming helpers (commonly grouped under the term "smart editor" or "intellisense") that they enjoy in their programming "studios".
An excuse would have been to dismiss such features as out of the scope of a "lightweight" editor.
But we know we can make of LEA a powerful mini-studio, with the ease of use of a simple editor, thanks to its "projectless" mode and the integrated HAC compiler.
So now, it happened.
From revision 385 of LEA (and revision 886 of HAC), you have now a good sense of intellisense:

  • mouse-hover tips: when you let the mouse pointer on an identifier for a little while, a tip appears about that identifier (typically, where it was declared)
  • context menu with a go-to-declaration entry, when applicable
  • call tips: on typing '(' after a subprogram name, a tip appears with the subprogram's parameters
  • auto-complete: on typing characters that belong to identifiers, a list of possible declared identifier appears; that list depends on where in the source code the text cursor is: declarations below the cursor are invisible and local declarations, possibly within multiple nested subprograms.ย 

Some screenshots will help illustrate the above points. Let's start with the sudoku_sample.adb example shipped with the HAC project. What's that "Sudo_Strings" type, for instance?
Just let the mouse pointer hang out around an occurrence of that keyword.

Mouse hover tip - Click image to enlarge it

Want to know more about that declaration? Right-click on it...

Go to declaration - Click image to enlarge it

...and here you go.

Declaration in the Sudoku package - Click image to enlarge it

That's it, so far, for features enabling navigation within existing code.
For writing code, here are two other key helpers. First, the call tips.
If we type '(' after a subprogram's name, we see the parameters list appear:


Call tip - Click image to enlarge it

If we type the beginning of an identifier, a list of possible completions appears:

Auto-complete - Click image to enlarge it

A few remarks about the present state of LEA's "smart editor" features:
  • Currently, LEA only supports the HAC subset - it was the first priority. GNAT and other Ada compilers have their own editors and navigation features, so there is a lesser pressure to support them in LEA.
  • The "smart editor" features are quite new and still under test and development. If you want to have them, you need to build LEA on a fresh clone (instructions are given in lea.gpr), then set (via regedit) the registry key SMART_EDITOR, in the branch HKEY_CURRENT_USER\SOFTWARE\LEA\, to "true", before starting LEA.
  • You will notice a few missing things, like a list of fields on typing '.' after a record variable. They are not forgotten and just still "under construction".
  • The "smart editor" features work on incomplete Ada sources. They might be just less present after the point of an error, especially a syntax error.

In order to develop the last point, here are a few examples on how LEA understands your program "on the fly", while you are typing it:

Smart editor on an incomplete piece of code - Click image to enlarge it

Smart editor on an incomplete piece of code, sample 2 - Click image to enlarge it

Smart editor on an incomplete piece of code, sample 3 - Click image to enlarge it

One more thing: the Windows version of LEA is contained in a single executable holding in currently 4.2 MiB, including data such as code samples and templates, and runs as a portable application (no installation required).

Some Web links:

LEA

Web site: http://l-e-a.sf.net/
Sources, site #1: https://sf.net/p/l-e-a/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/lea
Alire Crate: Alire - LEA

HAC

Web site: https://hacadacompiler.sourceforge.io/
Sources, site #1: https://sf.net/p/hacadacompiler/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/hac
Alire Crate: Alire - HAC

Enjoy!

LEA: first steps as a "smart editor"

2 September 2023 at 19:53

Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.


Spot the "tool tip" on the following screenshot...

Click to enlarge

Translation: cross-references and source code navigation in LEA are becoming a reality since this evening!

ย 


Some Web links:

LEA

Web site: http://l-e-a.sf.net/
Sources, site #1: https://sf.net/p/l-e-a/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/lea
Alire Crate: Alire - LEA


Since LEA embeds the HAC compiler, here are a few links about HAC as well:

HAC

Web site: https://hacadacompiler.sourceforge.io/
Sources, site #1: https://sf.net/p/hacadacompiler/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/hac
Alire Crate: Alire - HAC

New colour theme with LEA: Solarized Light

7 May 2023 at 21:19
Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.

Today, a topic that is guaranteed frivolous: a new colour theme for LEA (a Lightweight Editor for Ada).

Actually, it is a serious subject if you spend a large share of your time at programming (for work, for fun, or both...). For the theoretically brighter season (spring and summer), some prefer to give up the trendy Dark Side mode (which not so long ago was considered as horribly old-fashioned):

...and use a dark-font-bright-background scheme.

However, the contrast is a bit violent. A convincing and carefully designed low-contrast theme is called Solarized Light (which can be turned, with an astute swap within the same 8-colours palette for base colours, into a dark-backgrounded Solarized Dark). The theme is described here.

The Solarized Light theme is incorporated since today in LEA.

Enjoy!


LEA, a Lightweight Editor for Ada, aims to provide an easy, script-world-like, "look & feel" for developing Ada projects of any size and level, while enabling access to full-scale development tools like GNAT.

  • Quick start and reactivity
  • Uses the Scintilla editor widget (like Notepad++)
  • Multi-document
  • Multiple undo's & redo's
  • Multi-line edit, rectangular selections
  • Color themes, easy to switch
  • Duplication of lines and selections
  • Syntax highlighting
  • Parenthesis matching
  • Bookmarks
  • Free, Open-Source
  • Programmed in Ada
  • Includes HAC, the HAC Ada Compiler
  • Includes numerous examples of Ada programs, ready to be run
  • Single executable, runs without installation




Advent of Code 2022 in pictures

14 January 2023 at 09:25

Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.


Just as a teaser for the next Advent of Code in 10 1/2 months, we would like to show a few pictures related to last edition. The 25 puzzles, data and solutions can be found here and here. They are programmed with HAC (the HAC Ada Compiler), thus in a small subset of the Ada language. The HAC compiler is very fast, so you run your program without noticing it was ever compiled, which is perfect for completing a programming puzzle.

Day 22 run with HAC (here, embedded in the LEA environment)

However, the program will run substantially slower than compiled with a native, optimizing compiler like GNAT.
This is not an issue for most Advent of Code puzzles, but for some, it is, especially on the later days. Fortunately, changing from HAC to GNAT is trivial (just switch compilers), unlike the traditional reprogramming of Python prototypes in C++, for instance.

The pictures

Day 8's data is a map representing the height of trees. Once the puzzle was solved, I was curious how the forest looked like. Note that different users get different data, so you are unlikely to find a visualisation of exactly your data on the internet.


Day 12's puzzle is a shortest path problem with specific rules and a nice data - a terrain with a hill - which seems designed to trap depth-first-search algorithms into an almost infinite search. The yellowish path is the shortest from the green dot, elevation 'a', to blue dot, elevation 'z'.
The pinkish path is the shortest from the blue dot to any dot with elevation 'a'. Fortunately Dijkstra's algorithm (and perhaps others) allows for such a special criterion regarding the end point.

Click to enlarge


For day 22โ€™s puzzle, a walk on a cubeโ€™s surface is involved, so it is helpful to sketch it on a piece of paper, cut it and glue the faces. A banana skin of that puzzle is that the exampleโ€™s layout may be different from the dataโ€™s layout. We slipped on that one and ended up gluing and programming the face-to-face transitions for two layoutsโ€ฆ


Click to enlarge

Other Adaistsโ€™ solutions, discussions and pictures can be found here and in the "2022 Day x" threads in the same forum.

LEA 0.85 - the Tabs are here!

20 November 2022 at 20:05
Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.

The 0.85 version of LEA (the Lightweight Editor for Ada) is available!

Web site: http://l-e-a.sf.net/
Source repository #1: https://sf.net/p/l-e-a/code/HEAD/tree/
Source repository #2: https://github.com/zertovitch/lea

The new version has two main new features:
ย  - Tabs (screenshot below)
ย  - LEA doesn't write scilexer.dll as a file; thus, it runs as a portable application (in the sense: you can run it from a read-only drive directly, without installation)

Click to enlarge

Enjoy!

LEA 0.84 - the Build & Run button!

12 November 2022 at 11:43

ย 

Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.


The 0.84 version of LEA (the Lightweight Editor for Ada) is available!


Web site: http://l-e-a.sf.net/
Source repository #1: https://sf.net/p/l-e-a/code/HEAD/tree/
Source repository #2: https://github.com/zertovitch/lea

This version is essentialy a rework of LEA's ergonomy - we had recently the chance of having a group of young first-time programmers and first-time LEA users to test it!

The main addition is the green Build & Run button, which matches a (less intuitive) menu entry and the F9 key.

Click screenshot to enlarge

Another addition is a dedicated box for the "User_Abort" internal Virtual Machine exception, so that the LEA user doesn't take the exception message for an actual error (which would be the case for any other exception).

Before:


Now:

Enjoy!


Ann: HAC v.0.1

14 May 2022 at 12:19

HAC (HAC Ada Compiler) is a quick, small, open-source Ada
compiler, covering a subset of the Ada language.
HAC is itself fully programmed in Ada.

Web site: http://hacadacompiler.sf.net/
From there, links to sources and an executable for Windows.

Source repositories:
ย  #1 svn: https://sf.net/p/hacadacompiler/code/HEAD/tree/trunk/
ย  #2 git: https://github.com/zertovitch/hac

* Main improvements since v.0.0996:

ย  - packages and subpackages are now supported
ย  - modularity: packages and subprograms can be standalone
ย ย ย ย ย  library units, stored in individual files with
ย ย ย ย ย  GNAT's naming convention, and accessed from other units
ย ย ย ย ย  via the WITH clause
ย  - validity checks were added for a better detection of
ย ย ย ย ย  uninitialized variables.

Package examples and modularity tests have been added.
Particularly, a new PDF producer package with a few demos
is located in the ./exm/pdf directory.


hakoch

Enjoy!

Gautier
__
PS: for Windows, there is an integrated editor that embeds HAC:
LEA: http://l-e-a.sf.net
PPS: HAC will be shown at the Ada-Europe conference (presentation + tutorial)
http://www.ada-europe.org/conference2022/

Ann: HAC v.0.0996

22 January 2022 at 09:53

HAC (HAC Ada Compiler) is a small, quick, open-source Ada compiler,
covering a subset of the Ada language.
HAC is itself fully programmed in Ada.

Web site: http://hacadacompiler.sf.net/

Source repositories:
#1 svn: https://sf.net/p/hacadacompiler/code/HEAD/tree/trunk/
#2 git: https://github.com/zertovitch/hac

Main improvements since v.0.095:

  • range checks on discrete subtype assignment (:=) and conversion
  • short-circuit logical operators: "and then", "or else"
  • for S = Scalar subtype: S'First, S'Last, S'Succ, S'Pred, S'Pos, S'Val, S'Image, S'Value, S'Range attributes
  • for A = array object or array subtype: A'First [(N)], A'Last [(N)], A'Range [(N)], A'Length [(N)] attributes
  • "&", "<", ">", "=", "/=" operators defined for the String type (additionally to HAL.VString type)
  • CASE choices admit ranges
  • forward declarations for subprograms


Enjoy!

Gautier

PS: for Windows there is an integrated editor that embeds HAC:
LEA: http://l-e-a.sf.net

News about GWindows.Scintilla

21 November 2021 at 17:25

ย 

Some news about the GWindows Ada programming framework, more specifically, the GWindows.Scintilla package.

Scintilla is a powerful text editor widget that is behind, among others, LEA and Notepad++.

  • The Scintilla notifications work now on 64 bit platforms. Of course the compatibility is kept for 32 bit, so if you need to build your application for a 32 bit target, the Scintilla widgets will continue to work as before.
  • Method names are now "de-camel-cased". For instance you have now: "Move_Caret_Inside_View" instead of a cryptic "MoveCaretInsideView". The naming convention is now consistent with the rest of the GWindows framework, GNAT's run-time and most Ada libraries.

GWindows can be found on SourceForge here and on GitHub here.

Finally, here is a cute screenshot of the Scintilla sample (gwindows\samples\scintilla\sci_example.adb) running, with its source code shown by LEA - so again, GWindows.Scintilla in action!



The HAC scripts invasion (follow-up)

26 July 2021 at 18:18

As a follow-up of another post about converting bash (Linux) or cmd (Windows) scripts to HAC scripts, here is a fresh example.

I needed to improve an existing cmd script for benchmarking compression software, with the possibility of switching various subsets separately: that is re-run this subset of methods, or that other subset, or the full tests (long!), etc.

Of course, if you use a real language instead of command-line interpreter ones, there is an obvious solution: you can define a set and you can programmatically flip the membership switches.

In Ada, it looks like

ย  type Category is (
ย ย ย  Reduce_Shrink,
ย ย ย  Deflate,
ย ย ย  Deflate_External,
ย ย ย  BZip2_External,
ย ย ย  PPMd_External,
ย ย ย  LZMA_7z,
ย ย ย  LZMA_3,
ย ย ย  TAR,
ย ย ย  Preselection
ย  );

ย  cat_set : array (Category) of Boolean;
The good news is that you can run an Ada program exactly like a script by using HAC (the HAC Ada Compiler). That is, it runs immediately (with HAC), and HAC doesn't drop .ali, .o, .bexch, .tmp, .exe files which are too much waste for the sake of running a small script-like job.

Below are screenshots of the quick development of bench.adb using the LEA editor, where you can punch F4 to check eventual errors. If there is one, you get instantly to the offending line / column point.

This script is part of the Zip-Ada project and is very helpful for developing and testing new compression methods.

ย 

Click to enlarge


Click to enlarge


HAC v.0.095

7 April 2021 at 20:13

A bit of brush-up after our last post about the new modularity features of HAC (the HAC Ada Compiler), we can announce the release of version 0.095.

We have tested since then parameters to units, and the use of functions instead of procedures as units.

All that with the LEA editor, in order to experiment the behaviour of compile-time errors and run-time errors. In contrast to the command-line tool called "hac" where everything is forgotten once the command is run, whatever the outcome, in an integrated editor the compiler needs to close files properly in every case - also on errors, because the editor will open them to show the error locations. Similarily, the builder needs to clear the library information between two builds. The improvements to be made to HAC for a smooth functioning were straightforward. Just a couple of statements to add here and there.

A demo of HAC's current modularity support, in one picture:

Click to enlarge

HAC (HAC Ada Compiler) is a small, quick, open-source Ada compiler,
covering a subset of the Ada language.
HAC is itself fully programmed in Ada.

HAC web site: http://hacadacompiler.sf.net/


Source repositories:
ย #1 svn: https://sf.net/p/hacadacompiler/code/HEAD/tree/trunk/
ย #2 git: https://github.com/zertovitch/hac

Enjoy!

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.

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.ย 


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 ๐Ÿ˜...

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.
โŒ
โŒ