comp.lang.ada
 help / color / mirror / Atom feed
* reference to a name variable
@ 2009-07-23 19:08 Pablo
  2009-07-23 20:02 ` Hibou57 (Yannick Duchêne)
  2009-07-24 11:03 ` Stephen Leake
  0 siblings, 2 replies; 7+ messages in thread
From: Pablo @ 2009-07-23 19:08 UTC (permalink / raw)


Hi all,
I have an integer variable which I'd like to set dinamically equal to
a value of a variable that I don't know at priori. Say as:
I want to set My_Integer = IntegerValue(MyString), and MyString is the
name of a (existing in the code) variable set in run-time. For
instance, wonder if I have var1 and var2 which maybe I want the values
in run-time, but I have just one editbox, so during execution I wanna
set a string called MyString="var1" (or the other) and read the value
of var1 in My_Integer. How do I do this?
Thanks.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-23 19:08 reference to a name variable Pablo
@ 2009-07-23 20:02 ` Hibou57 (Yannick Duchêne)
  2009-07-23 20:26   ` Dmitry A. Kazakov
  2009-07-24 11:03 ` Stephen Leake
  1 sibling, 1 reply; 7+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-07-23 20:02 UTC (permalink / raw)


Hello Pablo,

What you are looking for seems to be a kind of metaprogramming,
something like handling the code as if it was data (Lisp back once
again in the Ada world ?)

I do not know any built-in of this kind in Ada, so I will suggest to
design the application so that variables which would have to be
accessible this way, would be registered in a list of string <->
access associations (just an example implementation, and standard Ada
containers would be well suited here).

You may also think about a kind of simple interpreter for your input
and create an interpretation function in the application. If the input
language is as simple as a set of string interpreted as requests for
some value, you may have a function taking a string as argument and
returning either a reference to an object an explicitely typed value.

If you need this kind of access for introspection, then perhaps access
to debug informations would be nice.

This is all providing I've undertood what you want (if not, I
apologize)

Why do you need this explicitely ? Most of time, solving something
requires to solve an initial requirement not to solve a derivative
problem which is temporaly supposed to be a solution (that's the
reason of the latter question).

Best wishes for your project



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-23 20:02 ` Hibou57 (Yannick Duchêne)
@ 2009-07-23 20:26   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2009-07-23 20:26 UTC (permalink / raw)


On Thu, 23 Jul 2009 13:02:25 -0700 (PDT), Hibou57 (Yannick Duch�ne) wrote:

> What you are looking for seems to be a kind of metaprogramming,
> something like handling the code as if it was data (Lisp back once
> again in the Ada world ?)

> I do not know any built-in of this kind in Ada, so I will suggest to
> design the application so that variables which would have to be
> accessible this way, would be registered in a list of string <->
> access associations (just an example implementation, and standard Ada
> containers would be well suited here).

A map would be even better suited for that.

(What was requested is not a variable, a named scoped object.)

> You may also think about a kind of simple interpreter for your input
> and create an interpretation function in the application. If the input
> language is as simple as a set of string interpreted as requests for
> some value, you may have a function taking a string as argument and
> returning either a reference to an object an explicitely typed value.

Yes, it is a right idea not to mix these two languages keeping them apart.

However, a need in some interpreted domain-specific languages is very
overestimated. In the automation area, customers are frequently asking for
this. We promptly supply them with a tailored scripting language they want,
knowing in advance that they will never ever use it. That would be just too
expensive for them, requiring personal training, permanent use, just mental
efforts nobody wanted to invest. But they are always certain that they
utterly need it... (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-23 19:08 reference to a name variable Pablo
  2009-07-23 20:02 ` Hibou57 (Yannick Duchêne)
@ 2009-07-24 11:03 ` Stephen Leake
  2009-07-28 13:51   ` Chrono
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2009-07-24 11:03 UTC (permalink / raw)


Pablo <pablittto@gmail.com> writes:

> I have an integer variable which I'd like to set dinamically equal to
> a value of a variable that I don't know at priori. Say as:
> I want to set My_Integer = IntegerValue(MyString), 

My_Integer := Integer'Value (MyString); 

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-24 11:03 ` Stephen Leake
@ 2009-07-28 13:51   ` Chrono
  2009-07-28 18:25     ` Ludovic Brenta
  0 siblings, 1 reply; 7+ messages in thread
From: Chrono @ 2009-07-28 13:51 UTC (permalink / raw)


On 24 jul, 08:03, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> Pablo <pablit...@gmail.com> writes:
> > I have an integer variable which I'd like to set dinamically equal to
> > a value of a variable that I don't know at priori. Say as:
> > I want to set My_Integer = IntegerValue(MyString),
>
> My_Integer := Integer'Value (MyString);
>
> --
> -- Stephe

Stephe, the idea is this really, instead of MyString is not a number
string, it's a string whose name is the name of a integer variable,
and it's the value of this variable what I want. This would work if I
had a string like "123", so Integer'Value("123") would give me 123.
When I try with a real naming string (instead of a number string),
program keeps waiting for an entry so it suspends itself...



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-28 13:51   ` Chrono
@ 2009-07-28 18:25     ` Ludovic Brenta
  2009-07-30 14:37       ` Chrono
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2009-07-28 18:25 UTC (permalink / raw)


On Jul 28, 3:51 pm, Chrono <pablit...@gmail.com> wrote:
> On 24 jul, 08:03, Stephen Leake <stephen_le...@stephe-leake.org>
> wrote:
>
> > Pablo <pablit...@gmail.com> writes:
> > > I have an integer variable which I'd like to set dinamically equal to
> > > a value of a variable that I don't know at priori. Say as:
> > > I want to set My_Integer = IntegerValue(MyString),
>
> > My_Integer := Integer'Value (MyString);
>
> > --
> > -- Stephe
>
> Stephe, the idea is this really, instead of MyString is not a number
> string, it's a string whose name is the name of a integer variable,
> and it's the value of this variable what I want. This would work if I
> had a string like "123", so Integer'Value("123") would give me 123.
> When I try with a real naming string (instead of a number string),
> program keeps waiting for an entry so it suspends itself...

Like Dmitry said, a map (i.e. a container of name-value pairs, where
names are Strings and values are integers) seems the best solution.
See Ada.Containers.Hashed_Maps.

However I'm curious to know why you need this? What is the higher-
level problem you're trying to solve?

--
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reference to a name variable
  2009-07-28 18:25     ` Ludovic Brenta
@ 2009-07-30 14:37       ` Chrono
  0 siblings, 0 replies; 7+ messages in thread
From: Chrono @ 2009-07-30 14:37 UTC (permalink / raw)


On 28 jul, 15:25, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> On Jul 28, 3:51 pm, Chrono <pablit...@gmail.com> wrote:
>
>
>
> > On 24 jul, 08:03, Stephen Leake <stephen_le...@stephe-leake.org>
> > wrote:
>
> > > Pablo <pablit...@gmail.com> writes:
> > > > I have an integer variable which I'd like to set dinamically equal to
> > > > a value of a variable that I don't know at priori. Say as:
> > > > I want to set My_Integer = IntegerValue(MyString),
>
> > > My_Integer := Integer'Value (MyString);
>
> > > --
> > > -- Stephe
>
> > Stephe, the idea is this really, instead of MyString is not a number
> > string, it's a string whose name is the name of a integer variable,
> > and it's the value of this variable what I want. This would work if I
> > had a string like "123", so Integer'Value("123") would give me 123.
> > When I try with a real naming string (instead of a number string),
> > program keeps waiting for an entry so it suspends itself...
>
> Like Dmitry said, a map (i.e. a container of name-value pairs, where
> names are Strings and values are integers) seems the best solution.
> See Ada.Containers.Hashed_Maps.
>
> However I'm curious to know why you need this? What is the higher-
> level problem you're trying to solve?
Basically I need test run time variables (thousands!) of a real-time
program machine..
>
> --
> Ludovic Brenta.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-07-30 14:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-23 19:08 reference to a name variable Pablo
2009-07-23 20:02 ` Hibou57 (Yannick Duchêne)
2009-07-23 20:26   ` Dmitry A. Kazakov
2009-07-24 11:03 ` Stephen Leake
2009-07-28 13:51   ` Chrono
2009-07-28 18:25     ` Ludovic Brenta
2009-07-30 14:37       ` Chrono

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox