Comments (6)
Also better prefer standalone translation units over embedded code in test cases.
from asteria.
As we speak there are quite a few standard library components left unimplemented (std.math
, std.io
etc.) but most of the core language features are almost complete. There will be examples once these are finished.
At the moment, the only output functions are std.debug.print()
and std.debug.dump()
(which write the standard error stream); no input functions are available. A few samples are:
// hello world
std.debug.print("hello world!");
// calculate the sum of integers 1, 2, ..., 100
var sum = 0;
for(var i = 1; i <= 100; ++i) {
sum += i;
}
std.debug.print("sum = ", sum);
// sort an array from smallest to largest
var data = [ 5, 2, 9, 7, 3, 1, 6, 4, 8, 0 ];
data = std.array.sort(data);
std.debug.print("sorted = ", data);
// sort an array from largest to smallest
var data = [ 5, 2, 9, 7, 3, 1, 6, 4, 8, 0 ];
data = std.array.sort(data,
/* closure function */ func(x, y) { return y <=> x; }
/* alternatively: func(x, y) = (y <=> x) */
);
std.debug.print("sorted = ", data);
// object-oriented programming
/* struct foo {
* integer value = 42;
* integer get() { return this.value; }
* void inc() { this.value += 1; }
* }
*/
func foo_new() {
return {
value = 42,
get = func() { return this.value; },
inc = func() { this.value += 1; },
};
}
var p = foo_new();
std.debug.print("p = ", p);
std.debug.print("p.get() = ", p.get()); // 42
std.debug.print("p.inc() = ", p.inc()); // null
std.debug.print("p.get() = ", p.get()); // 43
// exception handling
func times_1000(x) {
return x * 1000;
}
try {
var y = times_1000(12345678901234567);
std.debug.print("y = ", y);
} catch(e) {
std.debug.print("caught exception: ", e);
std.debug.print(" backtrace: ", __backtrace);
}
from asteria.
https://github.com/lhmouse/asteria/blob/master/asteria/doc/examples.txt
PRs are welcome.
from asteria.
Those are not feasible until the REPL is finished.
from asteria.
I like the examples. Thank you
from asteria.
I will create a new issue for the REPL then.
from asteria.
Related Issues (20)
- Bad assignment to references HOT 1
- De-uglify `Argument_Reader` HOT 1
- Use PCRE2 to replace `std::regex`
- spurious backtrace frame of proper sibling calls
- Use `Reference_Stack` to pass function arguments around
- Any Documenation? HOT 3
- How to compile on Mac HOT 5
- Segfaullt
- Merge name lookups with in a whole expression HOT 7
- Missing high-level plan of optimization HOT 3
- `assert !!0||1` fails HOT 1
- Output something more helpful in case of unmatched brackets
- Disable implicit global names
- Standard library functions should have parameters if they are stringified
- Add zlib and MD5/SHA-1/SHA-2 from OpenSSL
- C stack overflows
- `catch` operator? HOT 2
- Add INI library
- Add CSV library HOT 1
- Autoconf error! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asteria.