Giter Site home page Giter Site logo

dysphasia's People

Contributors

bnolan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bnolan

dysphasia's Issues

Single-assignment variables

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.

array.map

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);
}

Lambdas

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.

Better type inferencing

In the following example:

main {
   for(x in [1..5]) {
    puts(square(x));
   }
}

square(x) => x*x;

The following type inferences should be made:

  • x is int because it's used to iterate on an int array
  • square takes and int argument because it's called with an int argument
  • square returns an int because it's x*x return operation is an int

Conflicts should throw a syntax error.

Inferred generic function

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)
  • It should secondly be inferred to be float(float)
  • A separate copy of the function should be generated for each argument signature

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.

array.reduce

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;
}

array literals and operations

Two features:

  • Array literals that don't simply get inlined as constants
  • Array operations: multiplication with a similarly sized array, or with a scalar

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

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.