Skip to content

Instantly share code, notes, and snippets.

View takeshik's full-sized avatar

Takeshi KIRIYA takeshik

View GitHub Profile
private static IEnumerable<Expression> TraverseImpl(Expression expression)
{
switch (expression.GetType().Name)
{
case "BinaryExpression":
return (expression as BinaryExpression).Let(e => new []
{
e.Conversion,
e.Left,
e.Right,
var dic = Enumerable.Range(char.MinValue, char.MaxValue)
.Select(i =>
{
Console.Clear();
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.Write((char) i);
return Console.CursorTop != 0 || Console.CursorLeft != 1
? Tuple.Create(i, Console.CursorLeft)
: null;
var cp932CharWidths = new Dictionary<Char, Byte>()
{
{'\u0007', 0},
{'\u0008', 0},
{'\u0009', 8},
{'\u000A', 0},
{'\u000D', 0},
{'\u00A2', 2},
{'\u00A3', 2},
{'\u00A7', 2},
void Main()
{
Make.Fix<int>(f => n => n < 2 ? 1 : f(n - 1) * n)(5).Dump(); // 120
}
public class Make
{
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func) { return Fun<T>.Fix(func); }
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func, T dummy) { return Fun<T>.Fix(func); }
private static class Fun<T>
@takeshik
takeshik / Error.cs
Created October 9, 2012 07:43
おかしい
public class ColumnData
{
public string Track;
public string Follow;
public string AccountName;
public string Tille;
public string Image;
public Column.StartType ColumnType;
public ColumnData Set(string _AccountName, string _Title, string _Track, string _Follow, Column.StartType Start)
{
@takeshik
takeshik / first.cs
Created September 19, 2012 15:02
複数のラムダ式から式木を構築する ref: http://qiita.com/items/438b845154c6c21fcba5
Expression<Func<int, int, bool>> expr1 = (x, y) => x * y < 20;
Expression<Func<int, int, bool>> expr2 = (x, y) => x + y == 8;
Expression<Func<int, int, bool>> expr = CombineLambda(expr1, expr2);
Console.WriteLine(expr.Compile()(3, 5)); // True
public static Expression<TDelegate> CombineLambda<TDelegate>(Expression<TDelegate> left, Expression<TDelegate> right)
{
// TODO: ここを埋めたい!
throw new NotImplementedException();
public IEnumerable<Expression> ReduceYield(SymbolTable symbols, Type expectedType)
{
Expression expression = this;
while (true)
{
Expression result;
if (expression is YacqExpression)
{
result = ((YacqExpression) expression).ReduceOnce(symbols, expectedType);
}
<expression z:Id="i1" i:type="Block" xmlns="http://yacq.net/schema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<Variables>
<Parameter z:Id="i2">
<Type z:Id="i3">
<Assembly z:Id="i4" />
<Name>System.Int32[]</Name>
</Type>
<Name>a</Name>
</Parameter>
</Variables>
Expression expr = YacqServices.Parse("Int32.(Parse '123').(ToString 'x2')");
SerializedExpression serializedExpr = YacqExpression.Serialize(expr);
var dumpedString = serializedExpr.SaveText();
SerializedExpression deserializedExpr = YacqExpression.LoadText(dumpedString);
expr = deserializedExpr.Reduce();
internal static Node Serialize(Expression expression)
{
switch (expression.NodeType)
{
case ExpressionType.Add:
return Add((BinaryExpression) expression);
case ExpressionType.AddChecked:
return AddChecked((BinaryExpression) expression);
case ExpressionType.And:
return And((BinaryExpression) expression);