Open-source News

Intel Meteor Lake's VPU Linux Driver Updated, UMD Code Posted

Phoronix - Mon, 01/09/2023 - 20:46
Back in July Intel engineers published the initial open-source driver code around the new Versatile Processing Unit "VPU" coming with Meteor Lake. This VPU block with 14th Gen Core CPUs is intended for AI inference acceleration for deep learning software...

Blender 3.5 Boasts Working Apple Metal Backend, Vulkan Still In Early Stages

Phoronix - Mon, 01/09/2023 - 19:51
In addition to Blender's back-ends for NVIDIA CUDA and OptiX, Intel oneAPI, and AMD HIP, Blender 3.5 is set to have a working Apple Metal back-end for that proprietary graphics/compute API with accelerated UI/viewport handling to complement the Metal Cycles support...

XFS Progressing On Defragmenting Free Space - Needed For Online Shrinking

Phoronix - Mon, 01/09/2023 - 19:03
As part of a New Year's Eve patch deluge, XFS developer Darrick Wong sent out patches working on free space defragmenting support, among other work for further enhancing this mature open-source file-system...

Dynamic Triple Buffering Hopefully Will Land For GNOME 44

Phoronix - Mon, 01/09/2023 - 18:48
For over two years Canonical has been working on dynamic triple buffering for the GNOME desktop with the Mutter compositor. This triple-buffering-when-needed can dramatically boost the desktop performance especially in cases like Intel integrated graphics and Raspberry Pi boards. The triple buffering work hasn't been upstreamed yet but the hope is that it may finally be ready for upstream inclusion with GNOME 44...

RISC-V Hibernation Support / Suspend-To-Disk Nears The Linux Kernel

Phoronix - Mon, 01/09/2023 - 18:24
While the open RISC-V processor architecture has proven to be highly successful, one of the features that it hasn't yet supported with the Linux kernel to this point has been system hibernation / suspend-to-resume, but that support is now on the way...

Learn the Ada programming language by writing a simple game

opensource.com - Mon, 01/09/2023 - 16:00
Learn the Ada programming language by writing a simple game Moshe Zadka Mon, 01/09/2023 - 03:00

When you want to learn a new programming language, it's good to focus on the things programming languages have in common:

  • Variables
  • Expressions
  • Statements

These concepts are the basis of most programming languages. Once you understand them, you can start figuring out the rest. Because programming languages usually share similarities, once you know one language, you can learn the basics of another by understanding its differences.

A good way to learn new languages is practicing with a standard program. This allows you to focus on the language, not the program's logic. I'm doing that in this article series using a "guess the number" program, in which the computer picks a number between one and 100 and asks you to guess it. The program loops until you guess the number correctly.

This program exercises several concepts in programming languages:

  • Variables
  • Input
  • Output
  • Conditional evaluation
  • Loops

It's a great practical experiment to learn a new programming language.

Install Ada

The Ada programming language is a unique and highly structured language with a dedicated developer base. The toolchain for Ada is the GNU Ada Development Environment, better known as GNAT.

You can install GNAT on Linux using your distribution's package manager. On Fedora, CentOS, or similar:

$ sudo dnf install gcc-gnat

On Debian, Linux Mint, and derivatives:

$ sudo apt install gnat

On macOS and Windows, you can download an installer from the Adacore website (choose your platform from the drop-down menu).

Guess the number in Ada

Create a file called game.adb.

The two built-in Ada libraries this program uses are Text_IO and Numerics.Discrete_Random:

with Ada.Text_IO;

use Ada.Text_IO;

with Ada.Numerics.Discrete_Random;Procedure head

The name of the procedure must match the name of the file. The first part is defining the variables.

Note that the discrete_random is specialized to a specific range. In this case, the range of numbers allowed:

procedure Game is
   type randRange is range 1..100;
   package Rand_Int is new ada.numerics.discrete_random(randRange);
   use Rand_Int;
   gen : Generator;
   num : randRange;
   incorrect: Boolean := True;
   guess: randRange;

Programming and development Red Hat Developers Blog Programming cheat sheets Try for free: Red Hat Learning Subscription eBook: An introduction to programming with Bash Bash shell scripting cheat sheet eBook: Modernizing Enterprise Java An open source developer's guide to building applications Procedure logic

The logic starts by reset(gen). This initializes the random number generator, ensuring the number, initialized with random(gen), will be different each time you run the program.

The next step is to run the loop:

  • Output the instructions for a guess
  • Read the line
  • Convert it to randRange
  • Check it against the number

If the number matches, incorrect is set to False, causing the next iteration of the loop to exit.

Finally, the program prints a confirmation of the guess correctness before exiting:

begin
   reset(gen);
   num := random(gen);
   while incorrect loop
       Put_Line ("Guess a number between 1 and 100");
       declare
          guess_str : String := Get_Line (Current_Input);
       begin
          guess := randRange'Value (guess_str);
       end;
       if guess < num then
           Put_line("Too low");
       elsif guess > num then
           Put_line("Too high");
       else
           incorrect := False;
       end if;
   end loop;
   Put_line("That's right");
end Game;Build the program

The easiest way to compile an Ada program is to use gnatmake:

$ gnatmake game.adb
aarch64-linux-gnu-gcc-10 -c game.adb
aarch64-linux-gnu-gnatbind-10 -x game.ali
aarch64-linux-gnu-gnatlink-10 game.ali

This generates a binary called game.

Run the program

Each run of the program will be a little different. This is one example:

$ ./game 
Guess a number between 1 and 100
50
Too low
Guess a number between 1 and 100
75
Too low
Guess a number between 1 and 100
82
Too low
Guess a number between 1 and 100
90
Too high
Guess a number between 1 and 100
87
Too low
Guess a number between 1 and 100
88
That's rightLearn Ada

This "guess the number" game is a great introductory program for learning a new programming language because it exercises several common programming concepts in a pretty straightforward way. By implementing this simple game in different programming languages, you can demonstrate some core concepts of the languages and compare their details.

Do you have a favorite programming language? How would you write the "guess the number" game in it? Follow this article series to see examples of other programming languages that might interest you!

This "guess the number" game is a great introductory program for learning a new programming language because it exercises several common programming concepts in a pretty straightforward way.

Image by:

Opensource.com

Programming What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Pages