Заметки о тестировании, программировании и прочий "поток сознания", который жалко писать "в стол"
пятница, 5 февраля 2016 г.
среда, 3 февраля 2016 г.
вторник, 2 февраля 2016 г.
#1190. Ссылка. Is it "compile-time injection" possible?
https://plus.google.com/u/0/+DavidBerneda/posts/WhyNCmdtzbe?cfem=1
"Is it "compile-time injection" possible? I was thinking on the ability to attribute for example a class with members that are defined outside that class, and the compiler will just accept them.
ie: type [Extend(TFooExtender)] TFoo=class end;
TFooExtender=class(TBaseExtender).... end;
TBar=record Num:Integer end;
To allow this at compile-time:
var foo : TFoo; foo.Bar.num:=42;
TFooExtender will return 'Bar' of type TBar as a valid member of TFoo, and the compiler will just accept it.
At runtime, TFooExtender is the one that "glues" foo and bar, so it will run just fine."
Я знаю, как сделать подобное с примесями. Только зачем?
"Is it "compile-time injection" possible? I was thinking on the ability to attribute for example a class with members that are defined outside that class, and the compiler will just accept them.
ie: type [Extend(TFooExtender)] TFoo=class end;
TFooExtender=class(TBaseExtender).... end;
TBar=record Num:Integer end;
To allow this at compile-time:
var foo : TFoo; foo.Bar.num:=42;
TFooExtender will return 'Bar' of type TBar as a valid member of TFoo, and the compiler will just accept it.
At runtime, TFooExtender is the one that "glues" foo and bar, so it will run just fine."
Я знаю, как сделать подобное с примесями. Только зачем?
понедельник, 1 февраля 2016 г.
суббота, 30 января 2016 г.
#1188. Ох функциональщина
USES params.ms.dict axiom_push.ms.dict core.ms.dict ElementsRTTI.ms.dict Generation.ms.dict ; kind_NormalClass . STRING FUNCTION ValueToKey ANY IN aValue RULES ( aValue IsString ) aValue ( aValue IsArray ) ( aValue .map> call.me strings:Cat ) ( ( aValue IsObj ) AND ( aValue Is class::TtfwWord ) ) ( VAR l_UID aValue .UID >>> l_UID if ( l_UID IsNil ) then begin aValue pop:Word:Name end // ( l_UID Is Nil ) else l_UID ) ( aValue IsIntf ) ERROR 'Невозможно построить ключ для интерфейса' ( aValue IsObj ) ERROR 'Невозможно построить ключ для абстрактного объекта' ( aValue IsBool ) ( aValue ToPrintable ) ( aValue IsInt ) ( aValue ToPrintable ) ( aValue IsNil ) '' DEFAULT ( aValue ToPrintable ) ; // RULES >>> Result ; // ValueToKey : A CONST UID 'xxxA' ; // A : B CONST UID 'xxxB' ; // B : C ; // C 'a' ValueToKey . true ValueToKey . false ValueToKey . [ true ] ValueToKey . [ false ] ValueToKey . [ false true ] ValueToKey . [ true false ] ValueToKey . [ 'a' true false 'b' ] ValueToKey . @ A ValueToKey . @ B ValueToKey . [ @ A ] ValueToKey . [ @ B ] ValueToKey . [ @ A @ B ] ValueToKey . [ @ A [ @ B ] ] ValueToKey . [ [ @ A @ B ] ] ValueToKey . 123 ValueToKey . kind_NormalClass ValueToKey . @ C ValueToKey . [empty] ValueToKey . [] ValueToKey . [ ] ValueToKey . @ () ValueToKey . @ ( ) ValueToKey . @ A .UID . @ B .UID .
"Если любящему ООП программисту дать машинку для закручивания крышек на банках с огурцами - не сомневайтесь: он выстроит иерархию из 25 наследников и приспособит её в качестве электрической зубной щётки.
Если вдруг этого не произойдёт - значит вам попался неправильный ООП-программист, видимо, он на самом деле - латентный функциональщик."
Латентный функциональщик.... Да...
#1187. Функциональщина
USES params.ms.dict core.ms.dict ElementsRTTI.ms.dict Generation.ms.dict ; kind_NormalClass . STRING FUNCTION ValueToKey ANY IN aValue RULES ( aValue IsString ) aValue ( aValue IsArray ) ( aValue .map> call.me strings:Cat ) ( ( aValue IsObj ) AND ( aValue Is class::TtfwWord ) ) ( aValue pop:Word:Name ) ( aValue IsIntf ) ERROR 'Невозможно построить ключ для интерфейса' DEFAULT ( aValue ToPrintable ) ; // RULES >>> Result ; // ValueToKey : A CONST UID 'xxxA' ; // A : B CONST UID 'xxxB' ; // B 'a' ValueToKey . true ValueToKey . false ValueToKey . [ true ] ValueToKey . [ false ] ValueToKey . [ false true ] ValueToKey . [ true false ] ValueToKey . [ 'a' true false 'b' ] ValueToKey . @ A ValueToKey . @ B ValueToKey . [ @ A ] ValueToKey . [ @ B ] ValueToKey . [ @ A @ B ] ValueToKey . [ @ A [ @ B ] ] ValueToKey . [ [ @ A @ B ] ] ValueToKey . 123 ValueToKey . @ A .UID . @ B .UID .
Подписаться на:
Сообщения (Atom)