sminnee / dysphasia Goto Github PK
View Code? Open in Web Editor NEWToy programming language as a learning exercise.
Toy programming language as a learning exercise.
Although mutable variables are something I'd like to stay away from initially, single-assignment variables should be supported, to do stuff like this:
main {
x = [1,4,9,5];
for(i in x) {
printf("x[%i] = %i", i, x[i]);
}
}
Once compiled, the printf should probably still refer directly to a const array.
IntelliJ sanity inspector gives all red squiggly lines.
Amend the range synax to use [
and ]
. It will make chaining easier. Implement array.map, using a lambda as a function argument.
main {
for(i in [1..5].map(x | x*x)) puts(i);
}
Add support for lambdas, as a first step towards adding array.map. Could use arrow or guard syntax. While we're add it, allow single-statement for loops, for the example below :-)
main {
int(int) square = (x) => x * x;
int(int) cube = (x | x * x * x);
for(i in 1..5) puts(square(i));
for(i in 1..5) puts(cube(i));
}
Don't worry about closure variable binding for now.
In the following example:
main {
for(x in [1..5]) {
puts(square(x));
}
}
square(x) => x*x;
The following type inferences should be made:
Conflicts should throw a syntax error.
In this example:
main {
puts(square(2));
puts(square(3.5));
}
}
square(x) => x*x;
The following type inferencing should occur:
square(x)
should first be inferred to be int(int)
float(float)
Internally the the code should get transformed to something like this:
main {
puts(int square<int>(2));
puts(float square<float>(3.5));
}
}
T square<T>(T x) => x*x;
// expanded
int square<int>(int x) => x*x;
float square<float>(float x) => x*x;
Note: It might be easier if all method calls have type suffixes added to them, regardless of whether there are multi-type calls.
Let's add a companion to array.map and we can bask in our functional goodness.
main {
square = (x) => x*x;
sum = (x) => x+x;
sumSquares = a => a.map(square).reduce(sum);
puts(sumSquares([1,2,3])); // 14
}
Ideally, the output of map can be piped into reduce without first creating an intermediary array, so that the compiled code is more of this form:
sumSquares(a) {
for(i in a) {
mapped = i*i;
reduced = reduced+mapped;
}
return reduced;
}
Two features:
The following script:
x = [1, 2, 3, 5];
y = x * 2;
z = y * y;
for(i in z) {
puts(i);
}
Should output:
4
16
36
100
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.