Blombly
A simple programming language for reusable dynamic interfaces. Quickly produce sufficiently good solutions for many tasks.
Lists
Functions
Inlining
Resources
Graphics
Science
Terminal
A = 1,2,3,4;
A << 5; // push
sum = 0;
while(i in A) sum += i;
print("First: !{A[0]}");
print("Sum: !{sum}");
// | calls functions of one argument
print("Len: !{A|len}");
adder(x, y) = {
default xscale = 1;
default yscale = 1;
return x*xscale + y*yscale;
}
add = adder; // code as value
// acess finals of running scope
final xscale = 10;
print(add(1,2));
// move values after :: to the function
print(add(1,2 :: xscale=2;yscale=2));
Point = {
// => translates to = {return ...}
norm() => (this.x^2+this.y^2)^0.5;
str() => "(!{this.x},!{this.y})";
}
// inline code with :
p = new{Point:x=1;y=2}
print(p.norm());
// overloaded str operation
print(p);
g = graphics("MyApp", 800, 600);
logo = new{
x = 350;
y = 250;
angle = 0;
path = "docs/blombly.png";
img() => this.path,this.x,this.y,100,100,this.angle;
}
dt = 0;
prev_t = time();
while(events as g|pop) {
// treat :: as one character, like an underscore
while(e in events) if(e.io::type=="key::down") {
if(e.io::key=="A") logo.angle -= 360*dt;
if(e.io::key=="D") logo.angle += 360*dt;
}
g << logo.img();
dt = time()-prev_t;
prev_t = time();
}
// control permissions
!access "https://"
f = file("https://www.google.com");
// from the standard library
contents = f|bb.string.join("\n");
print("Len: !{contents|len}");
// apply x = x<<i*0.01 across several i
x = !gather(list(), <<){while(i in range(100)) yield i*0.01;}
x |= vector; // shorthand for x = vector(x);
y = (x-0.5)^2;
canvas = new{bb.sci.Plot:} // from the standard library
canvas.plot(x, y :: color=255,0,0,255; title="y=(x-0.5)^2");
canvas.plot(x, x :: color=0,255,0,255; title="y=x");
canvas.show(width=800; height=600);
# prints if no semicolons
./blombly 'log(3)+1'
2.098612
# directly run code
./blombly 'n=10; fmt(x)=>x[".3f"]; print(fmt(2.5^n))'
9536.743
# the standard library is there too
./blombly 'bb.string.md5("this is a string")'
b37e16c620c055cf8207b999e3270e9b