ada

Compare a string input to an Enumerated type

北战南征 提交于 2019-12-01 01:39:35
I am looking to do a comparison of a string to and enumeration. I have written a sample code of what I am attempting. Since a String and and Enumerated type are different, how do I go about doing this properly in Ada? WITH Ada.Text_IO; USE Ada.Text_IO; PROCEDURE ColorTest IS TYPE StopLightColor IS (red, yellow, green); response : String (1 .. 10); N : Integer; BEGIN Put("What color do you see on the stoplight? "); Get_Line (response, N); IF response IN StopLightColor THEN Put_Line ("The stoplight is " & response(1..n)); END IF; END ColorTest; First instantiate Enumeration_IO for StopLightColor

Non-contiguous ranges for subtypes in Ada?

随声附和 提交于 2019-12-01 01:35:32
问题 Totally as an Ada-type-system learning exercise, I was trying to make 3 types (or rather, a type and 2 subtypes): Month_Type , an enumeration of all months Short_Month_Type , a Month_Type subtype only having the months with 30 days February_Month_Type , a subtype with just February It seems that subtypes must use the range mechanism, correct? (Is there any other kind of subtype?) In order to get it to work with contiguous ranges, I had to put my Month_Type enumeration in this order: type

Why are there no (augmented assignment) operators like +=, -= or ++ in Ada? [closed]

雨燕双飞 提交于 2019-11-30 22:07:32
I'm wondering why there are no operators like += , -= , ++ , -= , <<= or x ? y : z (not an augmented assignment ...) in Ada? Many other languages (C, C++, C#, Java, Perl) have them. -- Example (C/C++/...): int a = 3; a += 4; /* A */ // long: a = a + 4 a++; /* B */ // long: a = a + 1 a = ( a > 3 ? 10 : 5 ); /* C */ // long: ' if a > 3 then a = 10 else a = 5' -- Example (Ada): a : integer := 3; a := a + 4; -- A -- a := a + 1; -- B -- if a > 3 then -- C -- a := 10; else a := 5; end if; ( Example doesn't make sense - only for demonstration ) Is it because ... Operator-overloading (but C++ has such

Compare a string input to an Enumerated type

≯℡__Kan透↙ 提交于 2019-11-30 20:33:36
问题 I am looking to do a comparison of a string to and enumeration. I have written a sample code of what I am attempting. Since a String and and Enumerated type are different, how do I go about doing this properly in Ada? WITH Ada.Text_IO; USE Ada.Text_IO; PROCEDURE ColorTest IS TYPE StopLightColor IS (red, yellow, green); response : String (1 .. 10); N : Integer; BEGIN Put("What color do you see on the stoplight? "); Get_Line (response, N); IF response IN StopLightColor THEN Put_Line ("The

Gnat for Mac Ada programming

情到浓时终转凉″ 提交于 2019-11-30 03:06:31
问题 I'm learning Ada 95 in my programming class, and I would like to install the gnat compiler on my MacBook. I have no clue as to where to get a good gnat to compile my code, and how to install it. I currently have gedit as my text editor, because that's what we're using in our lab environment. I'm new to the Mac world so any help would be greatly appreciated. 回答1: There's an excellent free Ada compiler for Mac OS X available from AdaCore. You should be OK with the GNAT GPL edition. Follow the

How can I overload the '=' operator in Ada without creating a recursive function?

跟風遠走 提交于 2019-11-29 14:31:43
FUNCTION "=" (lString1, lString2 : IN lString) RETURN boolean IS IF lString1 = NULL AND lString2 = NULL THEN RETURN true; ELSIF lString1 = NULL OR lString2 = NULL THEN RETURN false; END IF; I'm trying to overload the equality operator in Ada. Each time I use the operator '=' within the function it causes a recursion which leads to a stack overflow, rather than use the ada defined operator which I need. Is there a way to differentiate it from my overloaded operator? By introducing a non-overloaded utility function to do the access type comparisons, the OP's function definition, with the needed

Ada generics at run-time

狂风中的少年 提交于 2019-11-29 13:03:40
How would you instantiate a generic at runtime instead of at compile time. Example without using new. You cannot do this without use of new . You can do it in any declarative section, however that generic will only be extant for the duration of the scope of that declaritive section. for example (not compiled ada-like pseudocode): get(length) declare package stack is new stack_generic (max_stack_size => length); begin stack.push(); ... end; -- stack package no longer in scope. Does this help ? 来源: https://stackoverflow.com/questions/9630086/ada-generics-at-run-time

How can I overload the '=' operator in Ada without creating a recursive function?

只谈情不闲聊 提交于 2019-11-28 08:16:31
问题 FUNCTION "=" (lString1, lString2 : IN lString) RETURN boolean IS IF lString1 = NULL AND lString2 = NULL THEN RETURN true; ELSIF lString1 = NULL OR lString2 = NULL THEN RETURN false; END IF; I'm trying to overload the equality operator in Ada. Each time I use the operator '=' within the function it causes a recursion which leads to a stack overflow, rather than use the ada defined operator which I need. Is there a way to differentiate it from my overloaded operator? 回答1: By introducing a non

Ada generics at run-time

自作多情 提交于 2019-11-28 07:10:54
问题 How would you instantiate a generic at runtime instead of at compile time. Example without using new. 回答1: You cannot do this without use of new . You can do it in any declarative section, however that generic will only be extant for the duration of the scope of that declaritive section. for example (not compiled ada-like pseudocode): get(length) declare package stack is new stack_generic (max_stack_size => length); begin stack.push(); ... end; -- stack package no longer in scope. Does this

GDB errors on macOS Mojave

一曲冷凌霜 提交于 2019-11-28 01:45:03
Environment: Mac/Mojave and GDB 8.2.1 (via homebrew). I worked through instructions https://forward-in-code.blogspot.com/2018/11/mojave-vs-gdb.html i.e.: latest GDB via brew, which solves the executable format issue sign GDB with new entitlements Additionally, I've also modified SIP to allow debugging (in Recovery OS terminal: csrutil enable --without debug ). However, I still can’t get gdb to work: (gdb) file main Reading symbols from main...done. (gdb) run Starting program: /Users/joubertold/code/Rhodus/obj/debug/main [New Thread 0x1a03 of process 5082] [New Thread 0x2803 of process 5082]