-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
Stardust D.L edited this page Jan 18, 2018
·
2 revisions
This is a dynamic object.
func{
a=class{},
a.name="name",
print(a.name)
}
This is just like a class constructor.
func{
my=(_)=>class{
this.name="my name"
},
p=my(),
print(p.name)
}
You need to define current
and next
.
This is an iterator that return the Fibonacci numbers
func{
it=iter{
this.current=0,
f0:=0,
f1:=1,
this.next=(_)=>func{
this.current=f0+f1,
f0=f1,
f1=this.current,
return this.current<100
}
},
print(list(it))
}
Usually define a module in a file.
Like this:
module.es
module("calPI","author","1.0"){
this.getpi=(x)=>func{
f:=(n)=>((-1)**n)/(2**(10*n))*(
0-(32)/(4*n+1)
-(1)/(4*n+3)
+(256)/(10*n+1)
-(64)/(10*n+3)
-(4)/(10*n+5)
-(4)/(10*n+7)
+(1)/(10*n+9)),
pi:=0,
for(i:=0,i<x,i:=i+1){
pi=pi+f(i)
},
pi=pi/64,
return pi
}
}
Then use import
in other files.
func{
print(import("module.es")),
print(calPI.getpi(20))
}