Why is a variable of a predefined type included under "generic"? (Ada) -


i'm in college cs, , started data structures , algorithms class. professor prefers (practically forces us) use ada. in order ahead, started looking things , found snippet of code describing how generic stack might written:

generic   max: positive;    type element_t private; package generic_stack   procedure push (e: element_t);   function pop return element_t; end generic_stack; 

what stuck out me variable "max." since of type positive, didn't seem logical generic. perhaps i'm still new idea, thought idea behind generic empty shell , can interchanged different data types upon instantiating.

maybe don't understand generics enough. if not, please enlighten me?

having variable in formal part of generic way pass constant (at compile time) configure generic. such constant can used define other variables in data structures (like array (1..max)), cannot achieved passing value parameter subprogram. also, ensures both push , pop used same "max" constant (that not make sense pass such constant parameter both subprograms)


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -