comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using a string as a binary operator
Date: Tue, 14 Oct 2008 19:05:40 +0200
Date: 2008-10-14T19:05:43+02:00	[thread overview]
Message-ID: <1p57jbf1um2x8.1mk21y75746rt$.dlg@40tude.net> (raw)
In-Reply-To: 8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com

On Tue, 14 Oct 2008 08:35:23 -0700 (PDT), Joe wrote:

> I'm trying to build a simple stack the evaluates expressions in
> postfix notation (i.e. "1 2 +").  I can't find a way to use the
> operator directly when I get to it.  When I get to the  "+", but how
> do I apply this string to 1 and 2?  The best I can do is make a case
> statement that has a case for each binary operator, but this seems
> very klunky.  I know you can write "+"(1,2) to return 3 but how do I
> get Ada to recognize the string as an operator?  Here's a short
> example of what I would like to do:
> 
> with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;
> procedure Operators is
>    Plus : String := "+";
> begin
>    Put( Plus(1,2));
> end Operators;

with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;
procedure Operators is
   function Plus (L, R : Integer) return Integer renames "+";
begin
   Put (Plus (1, 2));
end Operators;

P.S. I am quite sure that this is not what you need. You don't need strings
in order to evaluate an expression. Evaluation of an expression /= parsing
an expression. It is unclear which one you actually want, or maybe both.

P.P.S. Ada does not "recognize strings as operators." "+" when used to
declare or reference + is technically not a string. It is a string literal.

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



  reply	other threads:[~2008-10-14 17:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-14 15:35 Using a string as a binary operator Joe
2008-10-14 17:05 ` Dmitry A. Kazakov [this message]
2008-10-14 18:51 ` Jeffrey R. Carter
2008-10-15 15:22   ` Adam Beneschan
2008-10-15 17:23     ` Jeffrey R. Carter
2008-10-15 19:32     ` sjw
2008-10-16  8:14     ` Dmitry A. Kazakov
2008-10-14 22:01 ` george.priv
2008-10-15  3:51 ` Gene
2008-10-15  5:45 ` anon
2008-10-15 12:18   ` Joe
2008-10-15 13:43     ` John McCormick
replies disabled

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