logs archiveBotHelp.net / Freenode / #ada / 2015 / July / 21 / 6
darkestkhan
Shark8: I still wonder about that example I gave...
for private types it results in circular dependency
Shark8
darkestkhan: The Opened_ and Closed_File types?
darkestkhan
yes
I can upload dummies to github
jk4
usually its dummies uploading to github
darkestkhan
jk4: true
Shark8: https://github.com/darkestkhan/file_types
premature usage of type ;)
Shark8
Ah... give me a moment to type something up.
darkestkhan
I also wonder how you would define: procedure Close (File : in out Open_File); -- File_Type'Class instead?
k
there is gpr file there too ;)
I can't just with Closed_File due to, later on, withing Open_File from Closed_File...
*and that one can't just simply with it too
jk4
would suggest more specificity of open
how about Writable_Open_File
Readable_Open_File
enforce it all with types
darkestkhan
jk4: that too, but first have just compilable dummy for Open_File and Closed_File
once we find a way to do this it can be easily expanded into Read_Only_File, Write_Only_File, Read_Write_File and Append_File
Shark8
I was thinking something like this: https://pastebin.mozilla.org/8840176
darkestkhan
Shark8: that can work just fine too
Shark8: what does that (<>) box do? (line 19)
jk4
is discriminated private type
Shark8
It says that the actual type may have discriminants.
(And that those are private.)
You could make them public:
Type X( Length : Natural ) is limited private; -- like this
darkestkhan
don't see that often enough to memorize that
jk4
this works
package Dis is
type A(<>) is private;
private
type A is null record;
end Dis;
but i don't know what it means /o\
or how to use A
wtp
jk4: It means that publicly A is assignable. BUT you cannot create an object of A since you don't know what discriminants, if any there may be. Thus, the only way to create the object is if the package provided some sort of factory method to create one.
jk4
i guess that's what Shark8 said
but i see now
thanks. good strategy for maintainability
Shark8
You could use such items to control flow -- Given A, B, C, D and F1(A) return B, F2(B) return C ...
you could guarantee that F3(F2(F1(A))) is the only way to get a proper call to F3.
... though usually you'd want to have your data types to be more than mere 'state markers'.
darkestkhan
Shark8: your example was close... but fixes where trivial
["compiles" with -gnatc -gnatwa -Wall -gnata]
Shark8
Close to what? // (TASK makes a better state-control / protocol-definition structure than using types as state-markers.)
darkestkhan
Shark8: close to passing compilation phase
TASK for state-control / protocol-definition structure??
this sounds crazy, but I would like to see how that would be done
Shark8: now you don't think that you can make Open_File and Closed_File types.. you know it now :)
also, how do use TASK for state-control / protocol-definition structure??
I know task can be used as finite state machine (why bother writing it entirely on your own?)
Shark8: I made mine example of Open_File, Closed_File types compile just fine...
Shark8
https://pastebin.mozilla.org/8840192
^-- There's how you can make TASK work for a protocol. (Or a state; just think of Entry as an Event.)
darkestkhan
Shark8: I see, by protocol you finite state machine
I think state control (w/o any fsm capability) is also nicely done by protected objects
jk4: how would you do inductive definition using contracts?
Shark8
Well, kind of; you could also make it model something like, say, an internet protocol where HANDSHAKE, {XMIT}+, CLOSE is done. (Of course that's a small/trivial example, but you can [often] directly model the [networking] protocol with it.)
darkestkhan
Shark8: true
btw. doesn't this gets close to abuse of features?
Shark8
The open_/closed_file thing? Or the TASK/PROTECTED thing?
« prev 1 2 3 4 5 6 next »