featurist / pogoscript Goto Github PK
View Code? Open in Web Editor NEWA readable, DSL friendly programming language with excellent concurrency primitives
Home Page: http://pogoscript.org/
License: BSD 2-Clause "Simplified" License
A readable, DSL friendly programming language with excellent concurrency primitives
Home Page: http://pogoscript.org/
License: BSD 2-Clause "Simplified" License
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.
Do async commands work in the repl? (as documented here: http://www.featurist.co.uk/blog/2012/10/26/async-pogo/)
I get ellipses after typing an async command:
bash-3.2$ pogo
> fs = require 'fs', nil
undefined
> fs.read file! 'stuff.txt' 'utf-8'
...
Can I do something to see the result?
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?
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
.
/*
*** 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'
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
.
Also, imo, new website no longer looks like it is a "a programming language for lazy sunday afternoons" :)
Is this possible?
@new PouchDB(url, ^)!
Doesn't work
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.
It would be really nice if PogoScript has a greater number of collaborators.
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.
operator followed by indented section doesn't work as expected:
a +
b
Doesn't behave like
a + b
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;
}
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
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 '}'
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)
It would be nice to have a "bare" option when compiling, like CoffeeScript.
This expression:
"+#(difference.value)".green
Compiles to
"+" + difference.value.green
But it should compile to
("+" + difference.value).green
> `09`
0
Think it has to do with the fact that parseInt('09') == 0
. Instead pass in the radix explicitly parseInt('09', 10)
.
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>"
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)"
Open a pogo REPL and type "typeof (foo)"
$ pogo
typeof (foo)
ReferenceError: continuation is not defined
at repl:1:1
outerAsyncFunc(innerAsyncFunc()!, "another argument")
becomes
outerAsyncFunc($21$2c(innerAsyncFunc(), "another argument"))
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.
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]);
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
Doesn't work, nor does
x @or (x = expr)
Because the parens are removed during compilation.
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.
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 = ...;
.
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.
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 ?
Does pogo have a switch statement?
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 ]
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.
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 }
}
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!
The following script is not detected to be async:
for each @(item) in (items)
do stuff with! (item)
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);
Optional parameters aren't in scope, so they don't trigger rules about :=
and =
.
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
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!
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)
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.
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.
or = ' or '
TypeError: Object [object Object] has no method 'generateTarget'
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
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');
})()
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} */
echo "exports.x = 'x';" > local.js
pogo
> console.log (require './local')
doesn't work.
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.