Coder Social home page Coder Social logo

Comments (6)

FrankHB avatar FrankHB commented on May 30, 2024 1

Also better prefer standalone translation units over embedded code in test cases.

from asteria.

lhmouse avatar lhmouse commented on May 30, 2024

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.

lhmouse avatar lhmouse commented on May 30, 2024

https://github.com/lhmouse/asteria/blob/master/asteria/doc/examples.txt

PRs are welcome.

from asteria.

lhmouse avatar lhmouse commented on May 30, 2024

Those are not feasible until the REPL is finished.

from asteria.

DanteFalzone0 avatar DanteFalzone0 commented on May 30, 2024

I like the examples. Thank you

from asteria.

lhmouse avatar lhmouse commented on May 30, 2024

I will create a new issue for the REPL then.

from asteria.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.