❌ About FreshRSS

Reading view

There are new articles available, click to refresh the page.

Creating custom Sax reader

There's something about polymorphism in Ada that I don't understand. (Or maybe it's the package naming?) I'm trying to parse an XML file using xmlada library and I followed the example I found in tests for this library that uses Debug_Reader. Below is the problematic code:

--  cog_cli-xml.adb
with Ada.Strings.Unbounded;
with Sax.Readers;
with Input_Sources.Strings;
with Unicode.CES.Basic_8bit;
with Cog_Cli.Xml_Reader;
with Cog_Cli_Doc;

package body Cog_Cli.Xml is
   package Asu renames Ada.Strings.Unbounded;
   package Ccxr renames Cog_Cli.Xml_Reader;
   package Sr renames Sax.Readers;
   package Iss renames Input_Sources.Strings;
   package Ccd renames Cog_Cli_Doc;
   package U8bit renames Unicode.CES.Basic_8bit;

   function Cli_Help (Command : String) return String is
      Doc_Reader : Ccxr.Reader;
      Input      : Iss.String_Input;
      Cli_Help   : constant Ccd.Content_Type := Ccd.Get_Content ("cli.xml");
      Iss.Open (Cli_Help.Content.all,
                Encoding => U8bit.Basic_8bit_Encoding,
                Input => Input);
      Ccxr.Set_Command (Doc_Reader, Command);

      Sr.Set_Feature (Doc_Reader, Sr.Namespace_Prefixes_Feature, False);
      Sr.Set_Feature (Doc_Reader, Sr.Namespace_Feature, False);
      Sr.Set_Feature (Doc_Reader, Sr.Validation_Feature, False);

      Sr.Parse (Doc_Reader, Input);

      Iss.Close (Input);

      return Asu.To_String (Doc_Reader.Help);
   end Cli_Help;

end Cog_Cli.Xml;
--  cog_cli-xml_reader.ads
with Sax.Readers;
with Unicode.CES;
with Sax.Attributes;
with Ada.Strings.Unbounded;

package Cog_Cli.Xml_Reader is
   package Asu renames Ada.Strings.Unbounded;

   type Reader is new Sax.Readers.Reader with private;

   procedure Start_Element
     (Handler       : in out Reader;
      Namespace_URI : Unicode.CES.Byte_Sequence := "";
      Local_Name    : Unicode.CES.Byte_Sequence := "";
      Qname         : Unicode.CES.Byte_Sequence := "";
      Atts          : Sax.Attributes.Attributes'Class);

   procedure End_Element
     (Handler       : in out Reader;
      Namespace_URI : Unicode.CES.Byte_Sequence := "";
      Local_Name    : Unicode.CES.Byte_Sequence := "";
      Qname         : Unicode.CES.Byte_Sequence := "");

   procedure Characters
     (Handler : in out Reader;
      Ch      : Unicode.CES.Byte_Sequence);

   procedure Set_Command (Handler : in out Reader; Command : String);

   procedure Set_Help (Handler : in out Reader; Help : String);
   type Reader is new Sax.Readers.Reader with record
      Command : Asu.Unbounded_String;
      Help    : Asu.Unbounded_String;
   end record;

end Cog_Cli.Xml_Reader;
with Ada.Text_IO;
with Ada.Strings.Unbounded;

package body Cog_Cli.Xml_Reader is
   package Ati renames Ada.Text_IO;
   package Asu renames with Ada.Strings.Unbounded;

   procedure Start_Element
     (Handler       : in out Reader;
      Namespace_URI : Unicode.CES.Byte_Sequence := "";
      Local_Name    : Unicode.CES.Byte_Sequence := "";
      Qname         : Unicode.CES.Byte_Sequence := "";
      Atts          : Sax.Attributes.Attributes'Class) is
   end Start_Element;
   procedure Characters
     (Handler : in out Reader;
      Ch      : Unicode.CES.Byte_Sequence) is
   end Characters;
   procedure End_Element
     (Handler       : in out Reader;
      Namespace_URI : Unicode.CES.Byte_Sequence := "";
      Local_Name    : Unicode.CES.Byte_Sequence := "";
      Qname         : Unicode.CES.Byte_Sequence := "") is
   end End_Element;

   procedure Set_Command (Handler : in out Reader; Command : String) is
      Handler.Command := Asu.To_Unbounded_String (Command);
   end Set_Command;

   procedure Set_Help (Handler : in out Reader; Help : String) is
      Handler.Help := Asu.To_Unbounded_String (Help);
   end Set_Help;

end Cog_Cli.Xml_Reader;

The problem is that Sr.Set_Feature doesn't believe that Doc_Reader is the right type... I have no idea why. The literal error I'm getting is:

cog_cli-xml.adb:27:09: error: no candidate interpretations match the actuals:
cog_cli-xml.adb:27:23: error: expected private type "Readers.Reader" defined at sax-readers.ads:778
cog_cli-xml.adb:27:23: error: found private type "Xml_Reader.Reader" defined at cog_cli-xml_reader.ads:10

Bridge returned error 404! (19699)

404 Page Not Found

RSS-Bridge tried to fetch a page on a website. But it doesn't exists.


Type: HttpException
Code: 404
Message: https://www.youtube.com/feeds/videos.xml?channel_id=UCOC7qHXMYZe-w1737_Vv7Yg resulted in 404 Not Found
File: lib/contents.php
Line: 106


#0 index.php(11): RssBridge->main()
#1 lib/RssBridge.php(113): DisplayAction->execute()
#2 actions/DisplayAction.php(71): DisplayAction->createResponse()
#3 actions/DisplayAction.php(106): YoutubeBridge->collectData()
#4 bridges/YoutubeBridge.php(198): YoutubeBridge->collectDataInternal()
#5 bridges/YoutubeBridge.php(111): YoutubeBridge->ytGetSimpleHTMLDOM()
#6 bridges/YoutubeBridge.php(465): getSimpleHTMLDOM()
#7 lib/contents.php(157): getContents()
#8 lib/contents.php(106)


Query: action=display&bridge=Youtube&context=By channel id&c=UCOC7qHXMYZe-w1737_Vv7Yg&duration_min=&duration_max=&format=Atom
Version: 2023-09-24
OS: Linux
PHP: 8.2.7

Go back

No maintainer

Ada VS Code extension 24.0.3

🎉 We have just published new vscode extension version 24.0.3 🎁 with experimental Mac OS M1 💻 native support! Don't hesitate sharing the feedback! Does it work for you? I hope

for Target use "aarch64-darwin"; 

isn't needed any more for native compiler (despite README says this). Also Linux ARM64 native support was added in 24.0.2, which wasn't published on Marketplace (but it's available on open vsx), so you can try it with remote mode is you have ARM64 server ⌨.

24.0.2 and 24.0.3 have many other improvements. Happy coding! 🔨

submitted by /u/max_rez
[link] [comments]

Square root of Big_Real in Ada

I am trying to calculate the square root of big numbers (around 16 digits) using the Big_Reals package. I have the following square root function which uses the Newton-Raphson method

pragma Ada_2022;
with Ada.Numerics.Big_Numbers.Big_Reals;
use Ada.Numerics.Big_Numbers.Big_Reals;

function Big_Sqrt(X: Big_Real) return Big_Real is
    package Converter is new Float_Conversions(Float);
    use Converter;
    Z: Big_Real := X;
    Big_Half: Big_Real := To_Big_Real(0.5);
    for I in 1..32 loop
        Z := Big_Half * (Z+X/Z);
    end loop;
    return Z;
end Big_Sqrt;

The output with input 1813789079679324 is


raised STORAGE_ERROR : Ada.Numerics.Big_Numbers.Big_Integers.Bignums.Normalize: big integer limit exceeded

I'm assuming this happens because although the whole part of the number is getting smaller there is too much space being used for the decimal part but I can't find a way to reduce the precision of the decimal part.

Is there a good way to handle exceptioins in the declarative region of a function

While working on day 6 of AoC, I found myself breaking a larger calculation into parts and saving them as constants in the declarative region of the function. This was super clean for reading and let me document all my steps nicely. I also knew that if any of the steps failed, then my result should be 0. So I figured I would put an exception handler in the function and return 0 (Note that the case where exceptions happen would be pretty rare based on some really edge case inputs that weren’t practical to the problem):

The problem I ran into is if the early steps raised an exception, then the exception handler wouldn’t catch them as they were in the declarative region. See mock up below:

function Calculate(Inputs : Input_Type) return Integer is
   Step_1 : constant Integer := Some_Function(Stuff);
   Step_2 : constant Integer := Some_Other_Function(Stuff);
   return Final_Function(Step_1, Step_2);
   when others => return 0;  -- doesn't catch Step_1 or Step_2 exceptions!!!
end Calculate;

Any suggestions on a clean way to catch those declarative exceptions? I don’t like putting them in a declare block in the function body because that just indents everything needlessly. Currently I renamed my original function to old_name_unhandled and call it a new wrapper function named the original name, but that does feel kinda silly.

I was hoping there is an aspect or pragma maybe?

6 posts - 5 participants

Read full topic

Where is Ada safer than Rust?

Hi, this is my first post in /r/ada, so I hope I'm not breaking any etiquette. I've briefly dabbled in Ada many years ago (didn't try SPARK, sadly) but I'm currently mostly a Rust programmer.

Rust and Ada are the two current contenders for the title of being the "safest language" in the industry. Now, Rust has affine types and the borrow-checker, etc. Ada has constraint subtyping, SPARK, etc. so there are certainly differences. My intuition and experience with both leads me to believe that Rust and Ada don't actually have the same definition of "safe", but I can't put my finger on it.

Could someone (preferably someone with experience in both language) help me? In particular, I'd be very interested in seeing examples of specifications that can be implemented safely in Ada but not in Rust. I'm ok with any reasonable definition of safety.

submitted by /u/ImYoric
[link] [comments]

Overloaded Subprograms in Ada

Our Programming Languages professor told us that:

"In Ada, the return type of an overloaded function can be used to disambiguate calls (thus two overloaded functions can have the same parameters)"

So this implies that in Ada, we could do something like this:

function Func (Var : Integer) return Integer;
function Func (Var : Integer) return Float;

And then create different implementations of these two functions, therefore overloading them.

This does not make much sense to me, how can the return type alone be sufficient to distinguish between overloaded subprograms? How would we even go about deciding which one of these functions we meant to call when we do decide to use them?

Did my professor make a mistake?

Day 5: If You Give A Seed A Fertilizer

@JeremyGrosser hasn’t posted on today’s puzzle yet; I hope he won’t mind if I do.

There’s always at least one puzzle with ginormous numbers, though I don’t recall their appearance in as early as Day 5!

The first speed bump I encountered is that gnat defaults (?) to 32-bit integers for Natural, so my machine choked, though nearly 12 hours later I can’t remember whether it choked on the input proper or during the tracing. Very well, then: spoiler

Is 32-bits a fixed standard for Ada’s Natural? Since 64-bit numbers are not uncommon in these puzzles (at least 2 or 3 puzzles will go there), should I by default define a numeric type and use that? (Isn’t that arguably the Ada way anyway? I’ve always wished the puzzle master would be more specific about the data we might encounter in these puzzles.)

The second speed bump is that solving Part 2 the natural, “brute-force” way takes the computer while, and I mean a while. It is doable! It took my machine “only” about 15 minutes. (I’ve paid for those gigahertz; might as well use them, right?)

So, while I was able to solve Part 2 via brute force – not usually possible when we start to see 6-digit numbers, let alone 9-digit ones! – I decided to spoiler.

My solution is here. I’d be interested to know if anyone took a different approach.

17 posts - 5 participants

Read full topic

Webinar | SPARK Pro for Embedded and Systems Programming

SPARK Pro brings formal methods to industrial scale and delivers unbeatable security, correctness and proven memory safety for industrial-scale embedded and native applications.

In this webinar, Yannick Moy outlines key features of SPARK Pro, including demos on pointer ownership, function contracts and safe type casting.

Watch this session to learn more about:
- The rich possibilities for data representation in SPARK
- Available contracts on data types
- The ownership principle for tracking pointers to data
- Available contracts on functions
- Handling of bindings with C libraries, safe type casting, software-hardware interactions
- Specializing the analysis for a given target platform

This is the first in a series of webinars on SPARK Pro - learn more about our SPARK for Proven Memory Safety webinar: https://bit.ly/3TaCjaD

Volatile records containing an array

svd2ada generates volatile arrays.

e.g. IMR_MR_Field_Array

There are two other options that I believe will work easily with spark. The .Val Hal.UInt32 or a record of booleans with different names instead of the array.

The array makes for simpler code. So before I switch to the value. Could anyone suggest how the Spark compatibility error may be avoided. Editing the svds isn’t ideal but possible. A function or procedure local instantiation would be ideal. Any ideas?

IMR1.MR.Arr(Var) := True;

error: volatile object cannot appear in this context. Spark RM 7.1.3 (10).


2 posts - 1 participant

Read full topic

Installing GTKAda to Synology

I want to install Max! home automation SW from Dmitry to my Synology NAS. This SW uses GTK ADA and I want to be sure about some things.http://www.dmitry-kazakov.de/ada/max_home_automation.htm

My NAS is Synology DS215j with Marvel Armada CPU.

Is this the right repository to install GTKADA from?

Which platform should I use ? ARM ELF 32 bit for Linux?

How to proceed then? I never compiled from source...

submitted by /u/frikovc
[link] [comments]