Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created December 22, 2011 19:30
Show Gist options
  • Save takeshik/1511532 to your computer and use it in GitHub Desktop.
Save takeshik/1511532 to your computer and use it in GitHub Desktop.
Dynamic Type Generating with Yacq
(newtype MyType:[Object (type "System.IDisposable")]
(public member X:Int32 get set)
(public member Y:Int32 get set)
(public member Z:Int32 get set)
(public member Sum:Int32 get (\ [self]
(+ self.X self.Y self.Z)
))
(public method new [] (\ [self]
self.(Randomize)
))
(public method new [Int32 Int32 Int32] (\ [self x y z]
($
(= self.X x)
(= self.Y y)
(= self.Z z)
)
))
(public method Randomize [] (\ [self]
($ [rand (type "System.Random").(new)]
(= self.X rand.(Next -1000 1000))
(= self.Y rand.(Next -1000 1000))
(= self.Z rand.(Next -1000 1000))
)
))
(public method Dispose [] (\ [self]
"X = \$(self.X), Y = \$(self.Y), Z = \$(self.Z).".(print)
))
).(new).(let _ _.Sum.(print) _.(Dispose))
; output:
; 545
; X = -653, Y = 639, Z = 559.
using System;
using System.Runtime.CompilerServices;
public class MyType : IDisposable
{
[CompilerGenerated]
private class :Impl
{
internal static void :Prologue(MyType myType)
{
}
internal static int <get_Sum>:Impl(MyType self)
{
return self.X + self.Y + self.Z;
}
internal static void ctor>:Impl(MyType self)
{
self.Randomize();
}
internal static void ctor>:Impl(MyType self, int x, int y, int z)
{
self.X = x;
self.Y = y;
self.Z = z;
}
internal static void <Randomize>:Impl(MyType self)
{
Random random = new Random();
self.X = random.Next(-1000, 1000);
self.Y = random.Next(-1000, 1000);
self.Z = random.Next(-1000, 1000);
}
internal static void <Dispose>:Impl(MyType self)
{
Console.WriteLine(string.Format("X = {0}, Y = {1}, Z = {2}.", self.X, self.Y, self.Z));
}
}
[CompilerGenerated]
private int <X>:Field;
[CompilerGenerated]
private int <Y>:Field;
[CompilerGenerated]
private int <Z>:Field;
public override int X
{
get
{
return this.<X>:Field;
}
set
{
this.<X>:Field = num;
}
}
public override int Y
{
get
{
return this.<Y>:Field;
}
set
{
this.<Y>:Field = num;
}
}
public override int Z
{
get
{
return this.<Z>:Field;
}
set
{
this.<Z>:Field = num;
}
}
public override int Sum
{
get
{
return MyType.:Impl.<get_Sum>:Impl(this);
}
}
public MyType()
{
MyType.:Impl.:Prologue(this);
MyType.:Impl.<.ctor>:Impl(this);
}
public MyType(int x, int y, int z)
{
MyType.:Impl.:Prologue(this);
MyType.:Impl.<.ctor>:Impl(this, x, y, z);
}
public override void Randomize()
{
MyType.:Impl.<Randomize>:Impl(this);
}
public override void Dispose()
{
MyType.:Impl.<Dispose>:Impl(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment