WeixiangYan/CodeTransOcean huggingface dataset:
Task: Window creation




Go: package main

import (
    "github.com/mattn/go-gtk/glib"
    "github.com/mattn/go-gtk/gtk"
)

func main() {
    gtk.Init(nil)
    window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
    window.Connect("destroy",
        func(*glib.CallbackContext) { gtk.MainQuit() }, "")
    window.Show()
    gtk.Main()
}








Ada: with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;

with Gtk.Handlers;
with Gtk.Main;

procedure Windowed_Application is
   Window : Gtk_Window;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Show (Window);

   Gtk.Main.Main;
end Windowed_Application;
Task: Window creation





Java: import javax.swing.JFrame;

public class Main {
     public static void main(String[] args) throws Exception {
         JFrame w = new JFrame("Title");
         w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         w.setSize(800,600);
         w.setVisible(true);
     }
}







Ada: with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;

with Gtk.Handlers;
with Gtk.Main;

procedure Windowed_Application is
   Window : Gtk_Window;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Show (Window);

   Gtk.Main.Main;
end Windowed_Application;
Task: Window creation







Python:   import Tkinter
  
  w = Tkinter.Tk()
  w.mainloop()





Ada: with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;

with Gtk.Handlers;
with Gtk.Main;

procedure Windowed_Application is
   Window : Gtk_Window;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Show (Window);

   Gtk.Main.Main;
end Windowed_Application;
Task: Window creation








VB: Option Explicit

Sub InsertForm()
Dim myForm As Object, strname As String
    Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
    strname = myForm.Name
    VBA.UserForms.Add(strname).Show
End Sub




Ada: with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;

with Gtk.Handlers;
with Gtk.Main;

procedure Windowed_Application is
   Window : Gtk_Window;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Show (Window);

   Gtk.Main.Main;
end Windowed_Application;
Task: Window creation

C: 

#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"

int main()
{
  SDL_Surface *screen;
  
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    return 1;
  }
  atexit(SDL_Quit);
  screen = SDL_SetVideoMode( 800, 600, 16, SDL_SWSURFACE | SDL_HWPALETTE );
  
  return 0;
}
Task: Window creation



C#: using System;
using System.Windows.Forms;

public class Window {
    [STAThread]
    static void Main() {
        Form form = new Form();
        
        form.Text = "Window";
        form.Disposed += delegate { Application.Exit(); };

        form.Show();
        Application.Run();
    }
}
Task: Window creation


C++: #include <QApplication>
#include <QMainWindow>

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 QMainWindow window;
 window.show();
 return app.exec();
}
Task: Window creation





Java: import javax.swing.JFrame;

public class Main {
     public static void main(String[] args) throws Exception {
         JFrame w = new JFrame("Title");
         w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         w.setSize(800,600);
         w.setVisible(true);
     }
}
Task: Window creation








VB: Option Explicit

Sub InsertForm()
Dim myForm As Object, strname As String
    Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
    strname = myForm.Name
    VBA.UserForms.Add(strname).Show
End Sub
Task: Window creation




Go: package main

import (
    "github.com/mattn/go-gtk/glib"
    "github.com/mattn/go-gtk/gtk"
)

func main() {
    gtk.Init(nil)
    window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
    window.Connect("destroy",
        func(*glib.CallbackContext) { gtk.MainQuit() }, "")
    window.Show()
    gtk.Main()
}
Task: Window creation







Python:   import Tkinter
  
  w = Tkinter.Tk()
  w.mainloop()
Task: Read entire file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var fileContents = File.ReadAllText("c:\\autoexec.bat");  
        
    }
}









Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
  char *buffer;
  FILE *fh = fopen("readentirefile.c", "rb");
  if ( fh != NULL )
  {
    fseek(fh, 0L, SEEK_END);
    long s = ftell(fh);
    rewind(fh);
    buffer = malloc(s);
    if ( buffer != NULL )
    {
      fread(buffer, s, 1, fh);
      
      fclose(fh); fh = NULL;
      
      
      fwrite(buffer, s, 1, stdout);

      free(buffer);
    }
    if (fh != NULL) fclose(fh);
  }
  return EXIT_SUCCESS;
}











Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file


C++: #include <iostream>
#include <fstream>
#include <string>
#include <iterator>

int main( ) 
{
    if (std::ifstream infile("sample.txt"))
    {
        
        std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>());

        cout << "File has " << fileData.size() << "chars\n";

        
        return 0;
   }
   else 
   {
      std::cout << "file not found!\n";
      return 1;
   }
}










Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file




Go: import "io/ioutil"

data, err := ioutil.ReadFile(filename)
sv := string(data)








Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file





Java: static Byte[] contentsOf(File file)
    {
    return file.contents;
    }







Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file







Python: open(filename).read()





Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file








VB: dim s
s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall
wscript.echo s




Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Read entire file

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
  char *buffer;
  FILE *fh = fopen("readentirefile.c", "rb");
  if ( fh != NULL )
  {
    fseek(fh, 0L, SEEK_END);
    long s = ftell(fh);
    rewind(fh);
    buffer = malloc(s);
    if ( buffer != NULL )
    {
      fread(buffer, s, 1, fh);
      
      fclose(fh); fh = NULL;
      
      
      fwrite(buffer, s, 1, stdout);

      free(buffer);
    }
    if (fh != NULL) fclose(fh);
  }
  return EXIT_SUCCESS;
}
Task: Read entire file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var fileContents = File.ReadAllText("c:\\autoexec.bat");  
        
    }
}
Task: Read entire file


C++: #include <iostream>
#include <fstream>
#include <string>
#include <iterator>

int main( ) 
{
    if (std::ifstream infile("sample.txt"))
    {
        
        std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>());

        cout << "File has " << fileData.size() << "chars\n";

        
        return 0;
   }
   else 
   {
      std::cout << "file not found!\n";
      return 1;
   }
}
Task: Read entire file








VB: dim s
s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall
wscript.echo s
Task: Read entire file




Go: import "io/ioutil"

data, err := ioutil.ReadFile(filename)
sv := string(data)
Task: Read entire file





Java: static Byte[] contentsOf(File file)
    {
    return file.contents;
    }
Task: Read entire file







Python: open(filename).read()
Task: Read entire file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var fileContents = File.ReadAllText("c:\\autoexec.bat");  
        
    }
}








Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file


C++: #include <iostream>
#include <fstream>
#include <string>
#include <iterator>

int main( ) 
{
    if (std::ifstream infile("sample.txt"))
    {
        
        std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>());

        cout << "File has " << fileData.size() << "chars\n";

        
        return 0;
   }
   else 
   {
      std::cout << "file not found!\n";
      return 1;
   }
}









Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
  char *buffer;
  FILE *fh = fopen("readentirefile.c", "rb");
  if ( fh != NULL )
  {
    fseek(fh, 0L, SEEK_END);
    long s = ftell(fh);
    rewind(fh);
    buffer = malloc(s);
    if ( buffer != NULL )
    {
      fread(buffer, s, 1, fh);
      
      fclose(fh); fh = NULL;
      
      
      fwrite(buffer, s, 1, stdout);

      free(buffer);
    }
    if (fh != NULL) fclose(fh);
  }
  return EXIT_SUCCESS;
}










Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file





Java: static Byte[] contentsOf(File file)
    {
    return file.contents;
    }






Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file







Python: open(filename).read()




Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file








VB: dim s
s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall
wscript.echo s



Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file






PHP: file_get_contents($filename)





Fortran: program read_file
    implicit none
    integer :: n
    character(:), allocatable :: s
    
    open(unit=10, file="read_file.f90", action="read", &
         form="unformatted", access="stream")
    inquire(unit=10, size=n)
    allocate(character(n) :: s)
    read(10) s
    close(10)
    
    print "(A)", s
end program
Task: Read entire file






PHP: file_get_contents($filename)
Task: Read entire file






PHP: file_get_contents($filename)






Ada: with Ada.Directories,
     Ada.Direct_IO,
     Ada.Text_IO;

procedure Whole_File is

   File_Name : String  := "whole_file.adb";
   File_Size : Natural := Natural (Ada.Directories.Size (File_Name));

   subtype File_String    is String (1 .. File_Size);
   package File_String_IO is new Ada.Direct_IO (File_String);

   File     : File_String_IO.File_Type;
   Contents : File_String;

begin
   File_String_IO.Open  (File, Mode => File_String_IO.In_File,
                               Name => File_Name);
   File_String_IO.Read  (File, Item => Contents);
   File_String_IO.Close (File);

   Ada.Text_IO.Put (Contents);
end Whole_File;
Task: Undefined values



C#: string foo = null;









Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;
Task: Undefined values

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
  int junk, *junkp;

  
  printf("junk: %d\n", junk);

  
  junkp = malloc(sizeof *junkp);
  if (junkp)
    printf("*junkp: %d\n", *junkp);
  return 0;
}











Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;
Task: Undefined values


C++: #include <iostream>

int main()
{
    int undefined;
    if (undefined == 42) 
    {
        std::cout << "42";
    }
    
    if (undefined != 42)
    {
        std::cout << "not 42";
    }
}










Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;
Task: Undefined values




Go: package main

import "fmt"

var (
    s []int
    p *int
    f func()
    i interface{}
    m map[int]int
    c chan int
)

func main() {
    fmt.Println("Exercise nil objects:")
    status()

    
    s = make([]int, 1)
    p = &s[0] 
    f = func() { fmt.Println("function call") }
    i = user(0) 
    m = make(map[int]int)
    c = make(chan int, 1)

    fmt.Println("\nExercise objects after initialization:")
    status()
}

type user int

func (user) m() {
    fmt.Println("method call")
}

func status() {
    trySlice()
    tryPointer()
    tryFunction()
    tryInterface()
    tryMap()
    tryChannel()
}

func reportPanic() {
    if x := recover(); x != nil {
        fmt.Println("panic:", x)
    }
}

func trySlice() {
    defer reportPanic()
    fmt.Println("s[0] =", s[0])
}

func tryPointer() {
    defer reportPanic()
    fmt.Println("*p =", *p)
}

func tryFunction() {
    defer reportPanic()
    f()
}

func tryInterface() {
    defer reportPanic()

    
    
    
    switch i.(type) {
    case nil:
        fmt.Println("i is nil interface")
    case interface {
        m()
    }:
        fmt.Println("i has method m")
    }

    
    i.(interface {
        m()
    }).m()
}

func tryMap() {
    defer reportPanic()
    m[0] = 0
    fmt.Println("m[0] =", m[0])
}

func tryChannel() {
    defer reportPanic()
    close(c)
    fmt.Println("channel closed")
}








Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;
Task: Undefined values





Java: String string = null;        
System.out.println(string);           
System.out.println(string.length());  







Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;
Task: Undefined values







Python: 
try: name
except NameError: print "name is undefined at first check"


name = "Chocolate"


try: name
except NameError: print "name is undefined at second check"


del name


try: name
except NameError: print "name is undefined at third check"


name = 42


try: name
except NameError: print "name is undefined at fourth check"



print "Done"





Ada: pragma Initialize_Scalars; 
with Ada.Text_IO;  use Ada.Text_IO;

procedure Invalid_Value is
   type Color is (Red, Green, Blue);
   X : Float;
   Y : Color;
begin
   if not X'Valid then
      Put_Line ("X is not valid");
   end if;
   X := 1.0;
   if X'Valid then
      Put_Line ("X is" & Float'Image (X));
   end if;   
   if not Y'Valid then
      Put_Line ("Y is not valid");
   end if;
   Y := Green;
   if Y'Valid then
      Put_Line ("Y is " & Color'Image (Y));
   end if;
end Invalid_Value;