Re: Statement on Schildt submitted to wikipedia today



On 8 Sep, 14:37, spinoza1111 <spinoza1...@xxxxxxxxx> wrote:
On Sep 8, 8:47 pm, NickKeighley<nick_keighley_nos...@xxxxxxxxxxx>
wrote:
On 8 Sep, 12:24,spinoza1111<spinoza1...@xxxxxxxxx> wrote:
On Sep 8, 2:28 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
In
<56f42de3-cab6-4f75-8393-e589c6b1a...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
spinoza1111wrote:

You still must emulate the stack in code.

No need. You *can*, but there's no "must" about it. The functionality
we're after is that of placing a bunch of parameters in a place where
the called function can find them, and providing the called function
with the necessary knowledge. This can easily be done using
practically any kind of searchable data structure - BSTs, B+-trees,
hash tables... There is no need whatsoever for it to be a stack, or

BSTs accessed as a stack.

B+-trees accessed as a stack.

Hash tables accessed as a stack.

these are what I call "logical stacks"

ie. not a stack in the sense of contiguous memory

<snip>

OK, the caller will pass the callee an index to a table.

Oops. Where does the callee get the index? To fall into the language
of the typical incompetent programmer, "duh the caller will put it in
a buffer".

OK, how does the callee know where to look?

it's a global. You could call it _current_activation_environment
or something. Or you could keep it in a register. R7 is a common
choice.

If its a "scalar" global then there must be a "vector" somewhere else,
and this "vector" is a...stack.

but only to the CAE. The CAE in turn has a way of finding the previous
CAE
like a pointer (or something fancier in the case of languages that
don't have
C's simple LIFO usage pattern).


In a non-threaded environment, it is undecidable (a Halting Problem)
how many activation records will need to exist at any one time for any
given function.

why does threading make this problem any easier?

It makes it harder, Reading Rainbow.

You use the term a lot. If you want me to understand how I've been
insulted
you'll have to explain this (Americanism?).

So why'd you mention threading then? It adds nothing to your sentence,
apart from bulk. Maybe that was the intent.

<snip>

Any given procedure on entry has to find its activation record. At a
minimum it needs to know where to branch back on exit. Even if we do
something really, really stupid, and allocate a separate area for each
function, that function has no way of knowing which of n>0 activation
records it needs in the course of execution: it has no "key", since
the "key" would be part of the activation record itself.

it's a global at a fixed location.

It is a mark of incompetence to speak of globals at fixed locations.
It's Cobol psychology.

putting it in a register makes it a global. C has quite a few globals
like
stdin. Most programs, even good ones, have a few globals.


<snip>

C can do this but languages (eg. Scheme) that have things called
"continuations" (an abilty to resume at a previously saved location
and environment) cannot. Even C has messy things like longjmp and
signal.

Exceptions.

quite

Seebach was forbidding Schildt to speak clearly <elide nonsense>.

On the contrary he was trying to get him to speak clearly. It's
important
people don't walk away thinking recursion won't work ("but you've
already
used the memory for the parameters once!") but also important they
don't
get the mindset that causes them to ask

   int a [2];
   int j;

   /* it's ok to access j like this isn't it?
      beecause it's next to a on the stack */

   a[2] = 99;

or a fascination with whether the stack "goes up or goes down".

This is nuts. You're afraid the students will create mental models and
metaphorical maps, so you don't tell 'em jack.

no, don't give them incorrect mental models.

It's just bad practise to index past one variable in an activation
record and expect to see the "next" parameter.

trust me, clc does get questions like that

You might in 99% of
cases, but it's still bad style, and it is no fault of the stack. It's
the fault of C.

I will concede that students can confuse accidental with necessary
elements when you create pictures in their minds,

ok

and the stack is a
vivid visual metaphor. It was probably invented by two geeks in the
company cafeteria, marveling at the fact that upper trays, the most
accessible, were also the warmest and wettest since the stack of trays
is accessed only at one end.

I was told it was a stack of plates with spring under it so the stack
rose slightly (popped up) as the top plate was removed. Such things
do
exist in some cafeteria. Probably banned now 'cos the bottom plate
only
gets washed once a year.

But it was realized soon enough that
implementing a stack as a contiguous vector was not necessary.

<snip>

An interest in implementaion is good (I like to know how things
work) but can become unhealthy.

True.

My first reaction on reading the Ada spec. was "that's never going to
work". Because I couldn't see how exceptions (they were called
exceptions?) could be coded in Z80 assembler. Cheaply.

But perhaps my scepticism was warrented. "Ada is fine on VAX 11/780;
we just can't get a Vax in the cockpit of a fighter aircraft".

Good, because fighter aircraft are primarily used today to kill
civilians on the ground, especially by Israel.

the technology then goes into todays fly-by-wire civilian aircraft.

"Ada's rendevous mechanism is fine; if you don't want real time
performance". "Compiler generators come in four sizes; small, medium,
large- and Ada". But Moore's Law fixed all that.

Indeed it did, except perhaps in the murderer's "cockpit".

the VAX went on chip long ago. I've got orders of magnitude more
memory in my phone that the original VAX had.

<snip>
.


Quantcast