comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian_drummond@btconnect.com>
Subject: Re: initialize an array (1-D) at elaboration using an expression based on the index?
Date: Sun, 31 Oct 2010 21:26:21 +0000
Date: 2010-10-31T21:26:21+00:00	[thread overview]
Message-ID: <ghkrc6dvo8419iiij4duoha84uv9o89sq6@4ax.com> (raw)
In-Reply-To: d779c161-3199-45ca-87ae-d0501c74e219@26g2000yqv.googlegroups.com

On Sun, 31 Oct 2010 12:00:20 -0700 (PDT), Shark8 <onewingedshark@gmail.com>
wrote:

>> ... having been raised on Algol-W I am delighted to see them come back.
>>
>> Is it their unfamiliarity that disturbs you?
>
>No, not so much.
>I don't see how they are [strictly-speaking] necessary, given that we
>have declare-blocks (which can be arbitrarily-nested).
>Granted, they would make it a lot less verbose in many cases. {BTW, if
>we're going to allow if/then statements inside expressions &
>assignments/initializations then what's keeping us from using case-
>statements too?}

Nothing, as long as we can escape from expecting that all languages should look
like C...

>> They don't appear to have the same possibility for disaster as your C example,
>> and have been around in some form in VHDL for decades.
>
>That's quite true. However, I've learned to be careful around C/C++;
>they are full of little inconsistencies that the compiler will happily
>consume, 

Absolutely ... aaah, perhaps you have C's :? syntax in mind...
That makes me uncomfortable too, and it took me a long time to figure out why.

It's psychological; given the additional circumstances that booleans are
integers in C, I am strongly conditioned to expect the choices to be in
ascending order ( i.e. 0, 1, ... yet they are in descending order). 

Given that, I have always regarded C's ?: conditional operator as a poor
relation to if-expressions.
(I can still never read it correctly without stopping and thinking.)

Algol-W allows if- and case-expressions; as you suggest, there is no reason to
allow one and prohibit the other.

(approximate Ada syntax - untested!)

days := case month is
            feb => if leap(year) then 29 else 28;
            apr, jun, sept, nov =>30;
            others => 31;

>
>> (In the combinatorial/parallel part of the language. VHDL2008 reintroduces them
>> to the sequential part, inside processes)
>
>Interesting; what is the VHDL syntax for them, if I might ask?

A 2-way multiplexer can be written as

S <= A when SEL_A else B;

(A, B, SEL_A, S are signals, SEL_A is of type Boolean)
For this example I am using capitals for labels, lower case for keywords, but
VHDL is case-insensitive like Ada.

A 4-way multiplexer can be written as 

with SEL select
	S <= 	A when 0,
		B when 1,
		C when 2,
		D when 3,
		'Z' when others;

In this example, SEL is an integer signal. S and A..D are signals of a type
(std_logic) which allows a value 'Z' which means tristate or high impedance.
This means that S is undriven in the "others" case, and may be driven by some
other entity (not shown). Otherwise the example could have ended at 
"		D when others; " or even 
"		D when 3;" 
for which SEL should be an appropriately ranged integer type!

Signals in VHDL are (slightly) similar to Occam channels, or rendezvous between
Ada tasks, which are likewise similar to VHDL processes.

Thus the 2-way mux above is shorthand for

process (A,B,SEL_A);
begin
    if SEL_A then
      S <= A;
   else
      S <= B;
   end if;
end process;

This process wakes up on any event on any signal in its sensitivity list
(A,B,SEL_A, entries in Ada terms) and executes its sequential code until either
completion or a "wait" statement.

 In this case, the sequential code is merely a conditional statement and one of
two possible signal assignments. However it could use almost any sequential code
construct familiar from Ada. 

<= here denotes signal assignment, which can wake up other processes sensitive
to S. Processes can also have variables with the familiar := assignment; these
are only visible within the process, while signals connect between processes.

VHDL2008 allows the "when" and "select" forms in expressions within the
sequential code in processes. Why "when" and "select" when it uses "if" and
"case" to denote the equivalent statements, is a mystery to me...

- Brian       



  parent reply	other threads:[~2010-10-31 21:26 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-15 23:03 initialize an array (1-D) at elaboration using an expression based on the index? Nasser M. Abbasi
2010-10-15 23:31 ` Vinzent Hoefler
2010-10-16  0:16   ` Adam Beneschan
2010-10-16  0:29     ` Nasser M. Abbasi
2010-10-16  1:47       ` Robert A Duff
2010-10-16  1:01     ` Randy Brukardt
2010-10-16 10:08     ` Phil Clayton
2010-10-18 15:03       ` Adam Beneschan
2010-10-19  6:29         ` Randy Brukardt
2010-10-20 20:01         ` Phil Clayton
2010-10-19 16:34     ` Britt Snodgrass
2010-10-19 18:05       ` Jeffrey Carter
2010-10-19 19:00         ` Vinzent Hoefler
2010-11-10 14:33     ` Georg Bauhaus
2010-11-10 15:51       ` Adam Beneschan
2010-11-10 17:19         ` Dmitry A. Kazakov
2010-11-10 18:03           ` Adam Beneschan
2010-11-11  1:07         ` Georg Bauhaus
2010-11-11  8:30           ` Dmitry A. Kazakov
2010-11-11 12:02           ` Robert A Duff
2010-11-11 14:19             ` Georg Bauhaus
2010-10-16  0:52 ` Jeffrey Carter
2010-10-16  0:54 ` Gene
2010-10-16  1:11   ` Vinzent Hoefler
2010-10-21 13:44 ` Chad  R. Meiners
2010-10-24 16:40   ` Shark8
2010-10-24 22:48     ` Phil Clayton
2010-10-25  2:23       ` Shark8
2010-10-29 23:26         ` Phil Clayton
2010-10-31 18:47           ` Shark8
2010-10-31 21:59             ` Georg Bauhaus
2010-11-01  0:45             ` Phil Clayton
2010-11-01  1:55               ` Shark8
2010-10-30  6:34         ` Brian Drummond
2010-10-31 19:00           ` Shark8
2010-10-31 18:09             ` (see below)
2010-10-31 19:35               ` Shark8
2010-10-31 22:47                 ` (see below)
2010-11-01  0:07                   ` Shark8
2010-10-31 23:21                     ` (see below)
2010-10-31 21:26             ` Brian Drummond [this message]
2010-11-12 18:10             ` Randy Brukardt
replies disabled

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