在Matlab中,如何获得包含"GRUMPY"以下声明的String :
GRUMPY = 500;
Run Code Online (Sandbox Code Playgroud)
这通常在其他编程语言中称为反射,但我在Matlab中找不到它的一个例子.
简而言之,为什么这不起作用:
generic
Max : in Positive;
package Modular_Gen_Issue is
procedure Foo;
private
type Mod_Thing is mod Max; -- NOK
type Int_Thing is new Integer range 0 .. Max; -- OK
end Modular_Gen_Issue;
Run Code Online (Sandbox Code Playgroud)
编译:
$ gnatmake modular_gen_issue.ads
gcc-4.4 -c modular_gen_issue.ads
modular_gen_issue.ads:6:26: non-static expression used for modular type bound
modular_gen_issue.ads:6:26: "Max" is not static constant or named number (RM 4.9(5))
gnatmake: "modular_gen_issue.ads" compilation error
$
Run Code Online (Sandbox Code Playgroud)
如何传入单个数字并使用它来定义模块类型?
是的,它必须是模块化类型!
我正在编写一个Ada程序,它应该对字母字符进行大小写转换.该程序使用1,2或3个命令行参数.我几乎写了这个东西,但我不知道如何做参数.命令行参数是:
有帮助吗?
即使使用这个简单的例子,我也无法让动态调度工作.我相信问题在于我如何设置类型和方法,但看不到哪里!
with Ada.Text_Io;
procedure Simple is
type Animal_T is abstract tagged null record;
type Cow_T is new Animal_T with record
Dairy : Boolean;
end record;
procedure Go_To_Vet (A : in out Cow_T) is
begin
Ada.Text_Io.Put_Line ("Cow");
end Go_To_Vet;
type Cat_T is new Animal_T with record
Fur : Boolean;
end record;
procedure Go_To_Vet (A : in out Cat_T)
is
begin
Ada.Text_Io.Put_Line ("Cat");
end Go_To_Vet;
A_Cat : Cat_T := (Animal_T with Fur => True);
A_Cow : Cow_T := (Animal_T with Dairy => …Run Code Online (Sandbox Code Playgroud) 出于好奇,这里有一个问题,是否可以找到您所在方法的名称?像这样的东西Magic应该在"foo.bar.foobar"不诉诸字符串文字的情况下输出。
with ada.text_io;
package body foo.bar is
function foobar return boolean is
begin
ada.text_io.put_line ("I am in :" & Magic);
return true;
end foobar;
end foo.bar;
Run Code Online (Sandbox Code Playgroud)
我认为这是信息位于某处,因为堆栈跟踪、异常和分析工具等的输出类似,但我无法在任何地方找到它!
我有一个奇怪的内存泄漏,似乎库函数 to_unbounded_string 正在泄漏!
代码片段:
procedure Parse (Str : in String;
Run Code Online (Sandbox Code Playgroud)
... 做东西...
declare
New_Element : constant Ada.Strings.Unbounded.Unbounded_String :=
Ada.Strings.Unbounded.To_Unbounded_String (Str); -- this leaks
begin
Run Code Online (Sandbox Code Playgroud)
瓦尔研磨输出:
==6009== 10,276 bytes in 1 blocks are possibly lost in loss record 153 of 153
==6009== at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==6009== by 0x42703B8: __gnat_malloc (in /usr/lib/libgnat-4.4.so.1)
==6009== by 0x4269480: system__secondary_stack__ss_allocate (in /usr/lib/libgnat-4.4.so.1)
==6009== by 0x414929B: ada__strings__unbounded__to_unbounded_string (in /usr/lib/libgnat-4.4.so.1)
==6009== by 0x80F8AD4: syntax__parser__dash_parser__parseXn (token_parser_g.adb:35)
Run Code Online (Sandbox Code Playgroud)
其中 token_parser_g.adb:35 在上面列为“-- this Leaks”行。
其他信息:Gnatmake 版本 4.4.5。gcc 版本 4.4 valgrind 版本 …