- 1
- 2
- 3
- 4
- 5
- 6
- 7
data Pitch = Pitch Integer
pitch t o = Pitch (o*12 + t)
freq (Pitch p) = a4 * 2**(i/12) where
i = fromIntegral (p - 57)
a4 = 440
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+117
data Pitch = Pitch Integer
pitch t o = Pitch (o*12 + t)
freq (Pitch p) = a4 * 2**(i/12) where
i = fromIntegral (p - 57)
a4 = 440
+23
typedef const AbstractParameter ConstAbstractParameter;
class Parameter: public ConstAbstractParameter{
GCC это не компилирует, но в 2008 ms vs компилируется без предупреждений. Я это как увидел, так сразу переписал на
class Parameter: public AbstractParameter{
+119
public static Tuple<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" tuple=""><t8>> Create<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" t8="">(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) {
return new Tuple<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" tuple=""><t8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<t8>(item8));
Int32 IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
// We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
ITuple t = (ITuple) m_Rest;
if(t.Size >= 8) { return t.GetHashCode(comparer); }
// In this case, the rest memeber has less than 8 elements so we need to combine some our elements with the elements in rest
int k = 8 - t.Size;
switch(k) {
case 1:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 2:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 3:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 4:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 5:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 6:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
case 7:
return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
}
Contract.Assert(false, "Missed all cases for computing Tuple hash code");
return -1;
}
Int32 ITuple.GetHashCode(IEqualityComparer comparer) {
return ((IStructuralEquatable) this).GetHashCode(comparer);
}
public override string ToString() {
StringBuilder sb = new StringBuilder();
sb.Append("(");
return ((ITuple)this).ToString(sb);
}
string ITuple.ToString(StringBuilder sb) {
sb.Append(m_Item1);
sb.Append(", ");
sb.Append(m_Item2);
sb.Append(", ");
sb.Append(m_Item3);
sb.Append(", ");
sb.Append(m_Item4);
sb.Append(", ");
sb.Append(m_Item5);
sb.Append(", ");
sb.Append(m_Item6);
sb.Append(", ");
sb.Append(m_Item7);
sb.Append(", ");
return ((ITuple)m_Rest).ToString(sb);
}
Давно заприметил в C# кортежи. За них отвечаёт чудесный класс System.Tuple
http://msdn.microsoft.com/en-us/library/system.tuple.aspx
Вот стало интересно - как они там это дело реализовали, ведь постоянно вводит новые плюшки в язык.
Посмотрел и ужаснулся - решили "в лоб" и кортежи обошлись в 1000 строк.
http://reflector.webtropy.com/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/clr/src/BCL/System/Tuple@cs/1305376/Tuple@cs
Хотел запостить в #12129. Но он утонул.
+9
class A
{
public:
A () : p (new SomeType)
{
assert ("It must be non-zero" && p);
}
~A ()
{
Box <SomeType> deleter (p);
p = 0;
}
private:
SomeType *p;
};
А вот и применение класса Box
+22
class ClassA
{
};
class ClassB : private ClassA
{
public:
ClassA& AsClassA()
{
return *this;
}
};
+22
template<class T>
class Box
{
private:
explicit Box(const Box&);
Box& operator = (const Box&);
public:
explicit Box()
: m_value(0)
{}
explicit Box(T* value)
: m_value(value)
{}
~Box()
{
std::auto_ptr <T> toDelete(m_value);
}
T* Release()
{
T* const result(m_value);
m_value = 0;
return result;
}
void Reset(T* value)
{
std::auto_ptr <T> toDelete(m_value);
m_value = value;
}
private:
T* m_value;
};
−119
1С::Функторы::АппликативныйФунктор::Монад 1С::Монада::НаЭкран -> 1С::Монада::Символ,1С::Монада::СимволСлед
| Пустота = Отчёт.Откат()
| 1С::Буква = 1С::МонадаМир::ВводВывод::Печать 1С::Буква
Многие интересуются, существует ли в 1С метод вывода монады на экран? Оказывается, существует!
Данный аппликативный функтор не требует теор.ката, хотя и не без улыбки, выводит квантовое состояние функциональной монады в виде стрелок и морфизмов.
PS Автор не я, а мой коллега, который, ковыряясь в 1С, обнаружил в нём "Функциональный режим"
+139
<div class="slogan">
<table>
<tbody>
<tr>
<td>В</td>
<td class="r"> </td>
<td>с</td>
<td class="r"> </td>
<td>ё</td>
<td> </td>
<td class="r"> </td>
<td>ч</td>
<td class="r"> </td>
<td>т</td>
<td class="r"> </td>
<td>о</td>
<td> </td>
<td class="r"> </td>
<td>д</td>
<td class="r"> </td>
<td>в</td>
<td class="r"> </td>
<td>и</td>
<td class="r"> </td>
<td>ж</td>
<td class="r"> </td>
<td>е</td>
<td class="r"> </td>
<td>т</td>
<td class="r"> </td>
<td>с</td>
<td class="r"> </td>
<td>я</td>
</tr>
</tbody>
</table>
</div>
Разрядка слогана "ВСЁ ЧТО ДВИЖЕТСЯ" на motor.ru
+157
<SCRIPT language=JavaScript> <!--#### Подпрограммы (скрипты) для вывода фотографий составных частей ПК #### -->
function picture1(){
window.open("P4P800.jpg", "newwindow01", config="width=460, height=515, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture2(){
window.open("CPU.jpg", "newwindow02", config="width=355, height=380, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture3(){
window.open("Video.jpg", "newwindow03", config="width=475, height=380, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture4(){
window.open("Syst.jpg", "newwindow04", config="width=220, height=220, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture5(){
window.open("audio.jpg", "newwindow05", config="width=315, height=200, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture6(){
window.open("Seti.jpg", "newwindow06", config="width=190, height=120, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture7(){
window.open("hdd.jpg", "newwindow07", config="width=725, height=425, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture8(){
window.open("dvd.jpg", "newwindow08", config="width=520, height=205, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture9(){
window.open("korpus.jpg", "newwindow09", config="width=820, height=435, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture10(){
window.open("monitor.jpg", "newwindow10", config="width=320, height=320, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture11(){
window.open("Klava.jpg", "newwindow11", config="width=510, height=250, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture12(){
window.open("Mouse.jpg", "newwindow12", config="width=340, height=285, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture13(){
window.open("print.jpg", "newwindow13", config="width=467, height=295, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
function picture14(){
window.open("RAM.jpg", "newwindow14", config="width=530, height=135, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}
</script> <!--#### Конец скриптов ####-->
−117
Часто проскальзывают темы, что 1С часто отказывает в монадах.
Я вот этого вообще не понимаю, как такое может выглядеть???
Я со своей восьмёрочкой 2 года, в любой момент, когда я захочу монад, он будет.
Если он скажет, нет, я не хочу, я показываю ему С++, показываю что я недоволен и говорю, почему ты не хочешь монаду?
Ты любишь кресты? Когда монады встречаются в 1С, они должны преобразовываться по первому же желанию программиста.