GithubHelp home page GithubHelp logo

featurist / pogoscript Goto Github PK

View Code? Open in Web Editor NEW
128.0 128.0 9.0 5.6 MB

A readable, DSL friendly programming language with excellent concurrency primitives

Home Page: http://pogoscript.org/

License: BSD 2-Clause "Simplified" License

Makefile 0.07% Ruby 0.16% JavaScript 72.54% PogoScript 27.19% HTML 0.04%

pogoscript's People

Contributors

joshski avatar paulcampbell avatar refractalize avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pogoscript's Issues

Passing async blocks to non-async functions gets weird

Problem happens when the block is called without a callback, and the block tries to call it. Instead of seeing something like gen1_callback is not a Function, we should see, async block called without a callback. We could check for this at the beginning of the function too, you get a better stack trace then.

pogoscript maturity, reliability

I was really happy when I found Pogoscript while searching the internet for nice async flow control for Node.js. I really like its generality, flexibility and purity.
I would like to inquire how mature this tool is. Is it recommended to rely on Pogoscript in larger projects?

nested comments shouldn't nest, but they do

These three lines:

one
// /*
two

Should be the same as these two lines:

one
two

But they aren't. The // /* comment in the middle seems to start a new comment with the /*, even though it is within a comment itself.

Seems like a funny thing to do, but I did find myself commenting a line that contained a common unix path glob pattern, lib/*.js.

Three contiguous stars in multi-line comments confuse compiler

/*
 *** comment
*/

Gives this compiler error:

node_modules\pogo\lib\parser\jisonParser.js:147
    throw new Error(str);
          ^
Error: Parse error on line 3:
*/** comment
----------------^
Expecting ',', 'operator', '!', '(', '@', '=>', '[', '{', 'float', 'integer', 'identifier', 'string', 'reg_exp', '...', '@{', 'start_interpolated_string', got ' eof'

optional arguments cannot be initialised with async expressions

Consider this:

n = 0

f! = ++n

o! (a: f!) = a

console.log (o!)
console.log (o!)

This compiles into something you wouldn't expect, that is, the definition of o is made after an asynchronous call to f, so the first invocation of o comes out as you'd expect with a result of 1, but the second also comes out as 1, whereas you'd expect it to run f again to yield a result of 2.

splat arguments to async method calls

obj = {
    fn () = console.log (arguments)
}

obj.fn! ([1], ...)

Should produce { '0': 1, '1': [Function] } but instead produces { '0': 1 }.

Regular function calls do work correctly however.

community, management

It would be really nice if PogoScript has a greater number of collaborators.

  1. Are there any plans for building the community?
  2. What branching model are you using now?

async functions with futures don't call callback

There are various flavours of this:

f! () =
    x?
    y!

Only calls the callback if 'y' returns an error.

f! () =
    x?
    y

Just 'return's y, but doesn't call the callback.

f! () =
    x?

Doesn't return or call the callback.

f! () =
    x?
    z = y!
    z

Does work as expected however.

Cannot return from inside for/in loop

myFunc() =
    result = false
    for @(item) in (self.someItems)
        return (true)

    false

becomes

myFunc: function() {
    for (item in self.someItems) {
        (function(item) {
            return true;
        })(item);
    }
    return false;
}

String interpolation windows vs nix

If you have a multiline string with interpolation, like this:

hello()=
 greeting = 'world'
 "hello
 #(greeting)
 "

and you compile it on linux you will get:

hello = function() {
    var greeting;
    greeting = "world";
    return "hello\n " + greeting + "\n ";
};

when you compile it on windows you will get:

hello = function() {
    var greeting;
    greeting = "world";
    return "hello\r\n " + greeting + "\r\n ";
};

Notice the \r\n line breaks. Ideally both platforms would output the same JS

object with comments raises parse error

The following code cannod be parsed because of the second comment.

// comment 1
a = {
    b = 1 // comment 2
}

Error:

Uncaught Error: Parse error on line 4:
... b = 1 // comment 2}
----------------------^
Expecting 'operator', '!', '(', '@', '=>', '[', '{', 'float', 'integer', 'hex', 'identifier', 'string', 'reg_exp', '...', '^', '@{', 'start_interpolated_string', got '}'

Is this supposed to work?

Hi. PogoScript looks great. I'm trying the examples from the front page of pogoscript.org .

The second example for "Blocks that have parameters"

primes = [1, 2, 3, 5, 7, 11, 13]
for each item @(prime) and index @(index) in (primes)
    console.log "Prime number #(index + 1) is #(prime)"

for each item and index in (list, block) =
    for (index = 0, index < list.length, ++index)
        block (list.(index), index)

this results in

C:\Users\Bobi\Downloads\node_modules\pogo\bin\pogo:45
    throw error;
          ^
TypeError: undefined is not a function
    at Object.<anonymous> (C:\Users\Bobi\Downloads\test.txt:5:5)
    at Object.<anonymous> (C:\Users\Bobi\Downloads\test.txt:15:4)
    at Module._compile (module.js:456:26)
    at Object.exports.runFileInModule (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\commandLine.js:91:23)
    at Object.exports.runMain (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\commandLine.js:105:17)
    at Object.<anonymous> (C:\Users\Bobi\Downloads\node_modules\pogo\bin\pogo:39:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Also tab is not working as indentation character and makes pogo crash.

Also should this work?

loop (times) times (block) =
    for (n = 1, n <= times, ++n)
        block (n, times)


loop 2 times @(a){
  console.log ("hello")
}

If I change @(a) to @ it is fine, but like this I get

C:\Users\Bobi\Downloads\node_modules\pogo\bin\pogo:45
    throw error;
          ^
TypeError: Object [object Object] has no method 'hashEntry'
    at terms.term.hashEntry (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\operatorExpression.js:130:46)
    at Object.anonymous (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\jisonParser.js:18:25)
    at Object.parse (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\jisonParser.js:233:36)
    at Object.parse (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\parser.js:27:31)
    at Object.exports.compile (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\compiler.js:39:29)
    at compileFromFile (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\commandLine.js:151:24)
    at Object.exports.runFileInModule (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\commandLine.js:90:14)
    at Object.exports.runMain (C:\Users\Bobi\Downloads\node_modules\pogo\lib\parser\commandLine.js:105:17)
    at Object.<anonymous> (C:\Users\Bobi\Downloads\node_modules\pogo\bin\pogo:39:17)
    at Module._compile (module.js:456:26)

"bare" option

It would be nice to have a "bare" option when compiling, like CoffeeScript.

09 is generated as 0

> `09`
0

Think it has to do with the fact that parseInt('09') == 0. Instead pass in the radix explicitly parseInt('09', 10).

Example Fix

render each in (list, render) if none (none) =
    if (list.length > 0)
        content = ''

        for each @(item) in (items)
            content := content + render (item)

        content
    else
        none ()

mountains = ['Everest', 'La Tournette', 'Valuga']

render each @(mountain) in (mountains)
    "<li>#(mountain)</li>"
if none
    "<li>no mountains...</li>"

scoped assignments aren't recognised as async

E.g.

ask for users name! () = "jeff"

name =
    ask for users name! ()

console.log "hello, #(name)"

Fails miserably, because the ask for users name! () call isn't picked up as being async in the main statements. However, this does work:

ask for users name! () = "jeff"

name = ask for users name! ()

console.log "hello, #(name)"

async docs are outdated

Wiki and Cheat Sheet is also outdated: for example the text = fs.read file! ('myfile.txt', 'utf-8') syntax completely omits the callback. As long as I am right, a ^ is missing there.

Array getAt compilation fails with variable

fib = [0, 1, 1, 2, 3, 5]
small number = 5
console.log (fib.small number)

compiles to:

fib = [ 0, 1, 1, 2, 3, 5 ];
smallNumber = 5;
console.log(fib.smallNumber);

when it should compile to or it should be possible achieve.

fib = [ 0, 1, 1, 2, 3, 5 ];
smallNumber = 5;
console.log(fib[smallNumber]);

async return on if statements

This doesn't work:

f! () =
    if (false)
        6

console.log ('f is', f!())

Because the then branch calls the callback, but the else branch doesn't, because there isn't one.

x @or x = expr

x @or x = expr

Doesn't work, nor does

x @or (x = expr)

Because the parens are removed during compilation.

Method chaining docs seems to be incorrect

Pogo examples (http://featurist.github.io/pogo-examples/) say the . when chaining methods should be preceding, but that way it fails to compile. However if the . is at the end of the line than it works.

This does not work:

self.svg
.attr("width", self.window.innerWidth)
.attr("height", self.window.innerHeight)

but this does:

self.svg.
attr("width", self.window.innerWidth).
attr("height", self.window.innerHeight)

Probably worth fixing the docs.

interactive: variables are not assigned from async expressions

This doesn't work:

> config = JSON.parse(fs.read file! 'dev.json' 'utf-8')
> config
ReferenceError: config is not defined
    at repl:1:21
    at REPLServer.exports.repl.evalPogo [as eval]
    at Interface.<anonymous> (repl.js:250:12)
    ...

Think its because there is a var config = ...; in the callback. Should be config = ...;.

Catch Compile Exceptions

It would be awesome if instead of throwing exceptions, they could be caught and reported in a nice way. Maybe even a beep sound like CoffeeScript.

could you think about that variables can support unicode?

first of all, your idea is really good.i am a Chinese, and other countries in the Chinese language which, if it can support the international coding programmers from other countries will be able to be able to write freely in accordance with their national language program, which will definitely make people excited, do you think it ?

list comprehensions don't close over variables

Common JS problem: for loops modify the iteration variables in-place, so when used with functions, the functions return the last iteration.

fs = [x <- [1, 2, 3], @{ x }]
console.log [f <- fs, f ()]

Will produce [ 3, 3, 3 ]

async return doesn't call callback

f! =
    return "result"

console.log (f!)

This doesn't do what you think it does. Return just returns from the function, it doesn't call the callback. Return needs to be rewritten into the callback.

return ! (result)

I find myself often implementing functions with async interfaces, but a synchronous implementation:

count (cb) = cb(null, 123)

Is there a pogo feature that "returns a value" asynchronously without calling another function, so I can get rid of the callback argument?

If not, I was thinking using the return keyword might work:

count () = return ! 123

http = {
   get (url) = return ! { status = 418 }
}

interscope variable name collision?

This code

init camera () =
  camera = 1

camera = init camera ()

throws

bug.pogo:2
  camera = 1
  ^^^^^^^^^^
variable camera is already defined, use := to reassign it

when changed to this

init camera () =
  camera = 1

camera := init camera ()

throws

bug.pogo:4
camera := init camera ()
^^^^^^^^^^^^^^^^^^^^^^^^
variable camera is not defined, use = to define it

Bug? Bug!

Order of parameters not preserved

The following PogoScript generates the following JS. Shouldn't the second underscore example pass the parameters in a way which preserves the order? strangely its passing the function as first parameter.

_ = require 'underscore'

_.each ([ 1, 2, 3 ]) @(num)
  console.log (num)

_.each (one : 1, two : 2, three : 3) @(num, key)
  console.log ( "#(num) #(key)" )

-------- Javascript follows

(function() {
    var self = this;
    var _;
    _ = require("underscore");
    _.each([ 1, 2, 3 ], function(num) {
        return console.log(num);
    });
    _.each(function(num, key) {
        return console.log(num + " " + key);
    }, {
        one: 1,
        two: 2,
        three: 3
    });
}).call(this);

Unexpected token: keyword (debugger)

This compiles with an error:

request.post '/games' {size = gameSize} @(error) @(res)
  gameId = res.text
  debugger

Unexpected token: keyword (debugger)

But this does not:

request.post '/games' {size = gameSize} @(error) @(res)
  debugger
  gameId = res.text

Treat callback argument specially

When mixing regular non-pogo async code with pogo async code, I often get in confused, i.e. consider the following:

wait (callback) =
    wait duration = parse int (fs.read file! (filename, 'utf-8'))
    set timeout (callback, wait duration)

wait!

We're passing callback, but we're also using the async operator in the function. Pogoscript then adds another parameter for the callback, and nothing works.

Instead, lets allow access to the pogo callback argument, say with a keyword, or other syntax, like the async op ! on the argument, e.g.:

wait (callback!) =
    wait duration = parse int (fs.read file! (filename, 'utf-8'))
    set timeout (callback, wait duration)

wait!

REPL doesn't work in Node 0.10

On windows at least...

C:\...\node_modules\pogo\bin\pogo:45
    throw error;
          ^
Error: An options Object, or a prompt String are required
    at new REPLServer (repl.js:96:11)
    at Object.exports.start (repl.js:312:14)
    at Object.exports.repl (C:\...\node_modules\pogo\lib\parser\commandLine.js:143:25)
    at Object.<anonymous> (C:\...\node_modules\pogo\bin\pogo:37:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

Wanted, anonymous function syntax with parameters

In Scala you can write.

scala> (1 until 1000).filter(n => n % 3 == 0 || n % 5 == 0).foldLeft(0)(_ + _)
res2: Int = 233168

n => n % 3 == 0... this is a function with parameter n.

Could

_.each (abc) @(num, key)
  console.log ( "#(num) #(key)" )

Be written more concisely as something like:

_.each (abc) @{console.log ( "#(_.1) #(_.2)")}

I do not have any good suggestion for syntax.

Improved error message when using promise keyword inapropriately

Sometimes I've used the name promise for a variable forgetting it's a keyword, e.g:

promise = getStuffAsync(...)

//later
promise!

The pogo compiler says "TypeError: Cannot read property '0' of undefined" with no trace of where the problem is. Takes me a while to remember what this means.

JSHint compatibility

When the return value of an async operation is not assigned to a variable, then the result translates into a single expression and it raises a JSHint error.

set timeout! ^ 1000
log "Hello World!"

translates to

(function() {
    var Promise = require("bluebird");
    var gen1_promisify = function(fn) {
        return new Promise(function(onFulfilled, onRejected) {
            fn(function(error, result) {
                if (error) {
                    onRejected(error);
                } else {
                    onFulfilled(result);
                }
            });
        });
    };
    var self = this;
    var gen2_asyncResult;
    new Promise(function(gen3_onFulfilled) {
        gen3_onFulfilled(gen1_promisify(function(gen4_callback) {
            return setTimeout(gen4_callback, 1e3);
        }).then(function(gen2_asyncResult) {
            gen2_asyncResult; // <===== the JSHint error is here
            return log("Hello World!");
        }));
    });
}).call(this);

JSHint error on line 20:

20: Expected an assignment or function call and instead saw an expression

cannot call blocks

You'd expect this shorthand to work:

@{ console.log 'hi' } ()

But it doesn't. It gets compiled to something like:

function () {
    console.log('hi');
}()

The function just needs to be wrapped in parens:

(function () {
    console.log('hi');
})()

unexpected parse error

Why is this a parse error?

  self.reactComponent = React.createClass {
      render () =
        R.div (
          null
          buttonLine {handleClick = self.handleClick}
          /* pointerLine {buttonClicked = self.state.buttonClicked} */
          /* buttonSquare {handleClick = self.handleClick} */
          /* pointerSquare {buttonClicked = self.state.buttonClicked} */
          /* buttonGlider {handleClick = self.handleClick} */
          /* pointerGlider {buttonClicked = self.state.buttonClicked} */
        )
   }

error:

Error: Parse error on line 92:
... = self.handleClick}          /* pointe...
-----------------------^
Expecting ',', ':', '=', ':=', ')', ']', got '}'

Moving comment outside of object definition fixes it

  self.reactComponent = React.createClass {
      render () =
        R.div (
          null
          buttonLine {handleClick = self.handleClick}
        )
   }

          /* pointerLine {buttonClicked = self.state.buttonClicked} */
          /* buttonSquare {handleClick = self.handleClick} */
          /* pointerSquare {buttonClicked = self.state.buttonClicked} */
          /* buttonGlider {handleClick = self.handleClick} */
          /* pointerGlider {buttonClicked = self.state.buttonClicked} */

require in repl

echo "exports.x = 'x';" > local.js
pogo
> console.log (require './local')

doesn't work.

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.