Skip to content

Instantly share code, notes, and snippets.

@mamcx
Created September 24, 2012 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamcx/3777791 to your computer and use it in GitHub Desktop.
Save mamcx/3777791 to your computer and use it in GitHub Desktop.
My language (work in progres)
# My pet language
int: Int32 #Start at 0
int: Int64 #Start at 0
int: Float #Start at 0.0
num: Num #Start at 0.0, DECIMAL / default number type
name: Str # UTf8
IsTrue: Bool #Start at false
today: Date = 2002-08-10 #Start at 0000-00-00
hour: Hour = 10:00:00 #24 H format #Start at 00:00:00
todayHoue: DateTime = 2002-08-10-10:00:00
path: Path = /root #Start at /
range: [1..2] #Se debe incializar explicitamente
data: Dict = {num:name} #Start at {}
dataTyped: Dict<Number,String> = {num:name}
things: List = [num, name, IsTrue] #Start at []
thingsTyped: List<String> = [name]
error?: ERROR #? say is nullable. Start at NULL
PI = 3.1416 #All CAPS means CONSTANT
#Looping
for thing in things:
print(thing)
for i in range(1,10):
print(i)
for IsTrue: #Reemplaza while.
print("Yep forever!")
break
for: #While forecer
print("Infinite!")
if IsTrue:
print("Yep")
text:
Just text %(IsTrue)s
#Inline function
doubleMe x : x + x
#Private function. Start with "_" mean private
def _sample:
print("hi")
#Public function with return value.
def sample : String
var:
IsOk:Bool
body:
return "hi"
#Public function with multiple return values
def sample : Str, Error?
input:
param1:Str
param2:Number
params: *List
body:
return text:
Hola [param1] [param2] [params]
None
class Person:
name:Str
def print: Str
text:
Documentacion
input:
times:Int32
body:
for i in range(1,times):
print(self.name)
#Herencia
class Moderator:
embed: Person
mamcx = Moderator()
mamcx.print() #Los metodos de Person se invocan
#PowerType. Similar to declare a field in a RDBMS
type Mayuscula:Str
#Ejecuta al asignar el valor
def transform: Str
return self.raw.toUpper()
def require:Bool,Error?
return assert(len(self.value)>0,Error("[self.name] no puede estar vacio")
miNombre:Mayuscula = "mario"
print(miNombre)
>> MARIO
miNombre = "" #RuntimeError: miNombre can't be empty
#Funcion con PowerType
def sample:
input:
nombre:Mayuscula
body:
print(nombre)
sample("") #RuntimeError: miNombre can't be empty
#Function hook
def startDef:
self.cache['start'] = now
def endDef:
performance.register(self.function.__name,'time', now - self.cache['start'])
hook(sample,pre = startDef, post = endDef)
#Instrument
server= instrument.Attach('/c:/Proyecto/Programa.exe', ApiKey= '****')
server.hook(sample,pre = startDef, post = endDef)
print performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment