zhanzhenzhen / futurescript Goto Github PK
View Code? Open in Web Editor NEWA future-style language.
Home Page: https://futurescript.org/
License: Other
A future-style language.
Home Page: https://futurescript.org/
License: Other
Thought it would be cool if comments were passed through for documentation and usage such as enabling Flow type annotations, perhaps as an extension or plugin. Well, ideally I'd suggest support via a version line keyword flow
. Could version keyword be enabled via extension!?
Flow/TS style arguments with default values and (optional) entry/exit types
const fn = ({ name = 'John Doe', age? : number }: Data): Data => ({
name,
age,
});
fn: ({name: 'John Doe', age}) -> ...
could become fn: ({name: 'John Doe', age? <number> }) <Data> ->
We could start with limited flow support for function args and variable declarations
c: "hello" <string>
What do you think?
Would be nice with a small guide on creating a custom manifest file.
I see the lodash one from fus-ext
includes the following to first import lodash into _
variable, then some adds all those functions to ..
_: import "lodash"
..'export: x ->
# Use lodash to receive all `..`.
_
A more elegant/intelligent approach where functions available are added depending on type of last return value (I assume). Ie. could be used to add underscore.string
functions when x is a string, otherwise lodash etc. Perhaps even Math functions for Number and so on.
..'export: x ->
if x is String
feString
else
_
For now I'd like to use my powerdash instead of lodash :)
Cheers!
How do I use fus-ext in my project? I tried to follow your guide
npm i -S fus-ext
Copied lodash manifest file to my project root folder as manifest.fus
.
I also upgraded fus version from 2.2.0 to 2.4.0
fus 2.4.0
{
loop
repeat
....
}
My main file first.fus
fus 2.3.0
import "./manifest" all
loop(10, i ->
console.log "This is \(i) time"
)
Compile works just fine, but running it gives strange output
19:57 $ fus c first.fus
✔ ~/repos/futurejs-projs/abc
19:58 $ node first.js
/Users/kristianmandrup/repos/futurejs-projs/abc/first.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";import {loop as loop} from "./manifest";import {repeat as repeat} from "./manifest";import {break as var_573300145710716007_0} from "./manifest";import {enum as var_573300145710716007_1} from "./manifest";import {fail as fail} from "./manifest";import {compose as compose} from "./manifest";import {assert as assert} from "./manifest";import {spread as spread} from "./manifest";import {eventField as eventField} from "./manifest";import {setImmediate as setImmediate} from "./manifest";import {clearImmediate as clearImmediate} from "./manifest";import {Timer as Timer} from "./manifest";import {IntervalTimer as IntervalTimer} from "./manifest";import {Observer as Observer} from "./manifest";import {Point as Point} from "./manifest";import {sys as sys} from "./manifest";import {web as web} from "./manifest";import {cmath as cmath} from "./manifest";import {feNumber as feNumber} fro
SyntaxError: Unexpected token import
I'm on latest Node 7.7.1
Ah, this is because Node doesn't yet support import.
Please allow for usage with Node.js as well using require
instead.
Cheers :)
Ah, I found this hint:
Here we used the "batch import" feature. Note that the export of manifest.fus should match the import of yours. If you want to use node instead of es, then you'll need to make corresponding changes in the version line of the two files.
However I can't seem to find any docs on how to set the version correctly to work with Node.
or do I need to set up Babel for this to work?
Ah, now I found it on version line section of https://futurescript.org
Could be a little more clear. Please add this hint on fus-ext documentation site.
2.4.0, node modules
Thanks!
I now get:
20:13 $ cat first.js
"use strict";var loop,repeat,fail,compose,assert,spread,eventField,setImmediate,clearImmediate,Timer,IntervalTimer,Observer,Point,sys,web,cmath,feNumber,feNumberStatic,feString,feObject,feArray,feMath,feJson,feDate,feConsole,feUint8Array,feUint8ArrayStatic,fePromiseStatic,dotDot_573300145710716007,global,var_573300145710716007_0,var_573300145710716007_1;loop=require("./manifest").loop;repeat=require("./manifest").repeat;var_573300145710716007_0=require("./manifest").break;var_573300145710716007_1=require("./manifest").enum;fail=require("./manifest").fail;compose=require("./manifest").compose;assert=require("./manifest").assert;spread=require("./manifest").spread
But there is no manifest.js
file so I obviously get:
20:12 $ node first.js
module.js:472
throw err;
^
Error: Cannot find module './manifest'
Ah, so I need to compile the manifest.fus
file as well ;)
Is there a gulp task for futurescript compilation?
I'd like to use it with Polymer using a custom build pipeline, here the one for es6 via babel
I guess I'd have to create my own little gulp task for futurescript! :)
gulp-marko-compile could be a good baseline with this guide
Btw, can/does FutureScript classes compile to ES6 compatible classes with extends
?
Ie. can it generate something akin to this ES6 class based syntax for Polymer 2?
// Subclass existing element
class MyElementSubclass extends MyElement {
static get is() { return 'my-element-subclass'; }
static get properties() { return { /* properties metadata */ } }
static get observers() { return [ /* observer descriptors */ ] }
constructor() {
super();
...
}
...
}
// Register custom element definition using standard platform API
customElements.define(MyElementSubclass.is, MyElementSubclass);
dp.fus:
0.5.0
export: f->
cache: new Map()
arg->
if cache.has arg then
cache.get arg
|
result: f arg
cache.set(arg, result)
result
示例:
0.5.0
import "./dp.fus" as dp
count: dp n->
if n=1 or n=2 then
1
|
count(n-1)+count(n-2) #斐波纳契数列
console.log count 1 #1
console.log count 2 #1
console.log count 3 #2
console.log count 4 #3
console.log count 5 #5
console.log count 6 #8
console.log count 7 #13
console.log count 8 #21
console.log count 9 #34
Since hardly anyone is yet using FutureScript!? I'd suggest removing all versions < 1
I see you only expose fus as a binary expecting args bin
With compile function defined using let
but not exported. Please improve the internals to allow for better composability and for tools such as gulp to use the API/library directly without involving the shell.
I might send you a PR for this. Just cloned the repo to play around...
Or perhaps this is the locked-api.js
with export let generateOutput = function(input) {
??
I will try my luck. Better use const and improve/document the internal API.
Would be nice with a "keep comments mode" in the version line, to turn it on add comments
keyword or maybe keep comments
which could be extended to other keep modes fx.
I think version line should be optional. If no version line, default settings will be used. Furthermore, version line should be a (special) comment, something like:
#fus 2.0.5
Something like encoding settings in ruby.
Thank you for futurescript.
What about a chat room about futurescript (in English)? It's easy to create a Gitter chat and I think it's useful.
Thank you.
Any roadmap? Which will the next futurescript features be?
Thank you again.
基于定位,大家才能针对性地提议。
在CodeVS见过类似的实现,感觉黑魔法太多,平板完全没法用。
建议化简,把光标放进透明的<textarea>
,再在底下放一个内容一样、上了色的。斜体什么的是不是太繁琐了?
Since our code should be as clear and concise as possible and avoid boilerplate!
So I'd like to use polymer decorators with FutureScript for beautiful, efficient frontend dev.
@customElement('test-element')
export class TestElement extends Polymer.Element {
@property({notify: true})
aNum: number = 42;
@property({notify: true})
aString: string = 'yes';
I see that @
symbol is already used for args but always on its own or with number coming after, so I don't see a conflict :) Where would I add this?
Oh wait, I see it used in hanoi.fus
example?
hanoi: <>
if @count = 1
move[@from, @to]
Does it mean this.from
I thought that would be me.from
according to docs?
建议教程正文使用<html>
的卷轴,这样更符合语义,也方便iOS用户使用惯性。
作为模式使用时要么全是or,要么全是and,两个不能在一个模式中一起出现,否则编译器会无法判断。括号内的无此限制。
注意or else是一种特殊的合并写法,并不属于or模式,所以or else可以和and一起出现。
???
"These containers and blocks:" should be "These containers are blocks:"
Several small grammatical errors also... since in Asia you don't have all those stupid "fill words" like in our stupid European languages :P
Are the docs on github so I can make PRs?
a ifnull: 8
equivalent to a = a || 8
or a ||= 8
in ruby.
For fus
it could be a: self | 8
or perhaps a: ? 8
In general null
is known as the billion dollar mistake
For a ifvoid: 8 # if (a === undefined) {a = 8;}
could be a: ! 8
ie. must be 8 if not defined.
b: a ifvoid 8 # b = a !== undefined ? a : 8;
could then be b: a ! 8
set b
to a
and must be 8 if a
not yet defined
I tried the following:
a: 1
b: "b"
x: {
a,
b
}
console.log x
And got {"a":true,"b":true}
when I would have like the ES6 equivalent {a: 1,b: "b"}
is this really intended behaviour?
++
、+=
这种运算的最大问题是功能不分离;另,我觉得FutureScript还是挺乱的,虽然看起来整齐了些。有如下代码:
1.0.1
{a:b, c:d e, f:g(h+i), j:k (l+m), n:[o p q, r, s(t u, v)]}
废除逗号分隔符后变得简洁:
?
{a:b (c:d e) f:g(h+i) (j:k (l+m)) n:[(o p q) r s((t u) v)]}
For FRP, look at various frp solutions
I suggest using a pipe equivalent +>
for working with streams (piping). +>
Could perhaps just be an alias for .
but be used to make it more clear we are operating on a stream (or whatever other special construct we like to clearly differentiate from "normal" function call)
const source = getAsyncStockData();
const subscription = source
.filter(quote => quote.price > 30)
.map(quote => quote.price)
.subscribe(
price => console.log(`Prices higher than $30: ${price}`),
err => console.log(`Something went wrong: ${err.message}`)
);
/* When we're done */
subscription.dispose();
Could become
source: getAsyncStockData()
subscription: source
+>filter quote -> quote.price > 30
+>map quote -> quote.price
+>subscribe
price -> console.log `Prices higher than $30: \price",
err -> console.log "Something went wrong: \err.message
# When we're done
subscription.dispose()
Would be awesome to be forced to use immutable objects and const
only, perhaps by scope?
An extension could allow choosing which immutable library to use similar to how ..
is handled via manifest. Just another idea ;)
Use ?
to indicate function returning boolean
admin?: x -> x.role = 'admin'
admin? user
Use !
to indicate function with side effect
write-user!: user ->
write-file user
write-user! current-user
Is yield
on the roadmap? If so, soon or much later?
Is types on the roadmap?
I can translate your FAQ from Chinese to English if desired, just let me know where I should submit the pull request (the source of the FAQ page doesn't appear to be in this github repo). I've translated a few of them below:
问:为啥没有位操作符?
答:首先,FutureScript作为高级语言,没必要支持。其次,JavaScript的位操作是专门针对32位数字的,这本身就不合理。
Q: Why are there no bitwise operators?
A: First, FutureScript is a high-level language, so there is no need to support them. Second, JavaScript's bitwise operations are specifically targeted towards 32-bit numbers, which is unreasonable.
问:为啥没有保留字?
答:很多语言都有很多保留字,但我觉得你设计语言的时候预先定义好未来的功能,那未来有可能是你没料到的。我们在版本行使用版本号,也达到了“安全”的目的,因为可以保证只要你不修改版本号,就不会出现兼容性问题。
Q: Why are there no keywords reserved for future use?
A: Many languages have many reserved keywords, but I think that if you try to predict future features when you design the language, then you might not predict them correctly. In FutureScript, the version number achieves the goal of "safety", because so long as you do not change the version number, there will not be any compatibility issues.
问:保留旧版本的编译器,那岂不越来越庞大?好恐怖!
答:其实也没那么恐怖,我们在做FutureScript的时候会采取一些手段,使增量不那么大。
Q: If we keep versions of the compiler, won't it become increasingly large? Sounds scary!
A: Actually it's not that scary, while building FutureScript I adopted some techniques to ensure that the increase in size is not so large.
For async I suggest you have a look at rq by Douglas Crawford as presented in this video
This elegantly solves complex async flows without promises and try/catch/finally :)
respond = RQ.fallback([
RQ.sequence([
getId,
getPreference,
RQ.parallel([
getNav,
RQ.race([
getAd(adnet.klikHaus),
getAd(adnet.inUFace),
getAd(adnet.trackPipe)
]),
RQ.fallback([
fetch("weather", localCache),
fetch("weather", localDB),
fetch("weather", remoteDB)
]),
getMessageOfTheDay
], [
getHoroscope,
getGossip
], 50),
construct(['nav', 'ads', 'weather', 'message', 'horoscope', 'gossip']),
buildPage
], 100),
planB
]};
Would it make sense to incorporate this directly!?
x: ~.. [
~|| [
getNav
~1 [
getAd adnet.klikHaus
getAd adnet.inUFace
]
~:o [
rescue
]
]
]
I know this is likely too specific for your taste? Would love to learn how to add my own additions like this! Cheers!
Perhaps be inspired by most fantasyland and static-land for true Functional power using Monoids! Used by PureScript to great effect (from Haskell)
Would be pretty simple reusing tailored also used by elixirscript
greet: guard({age: age}) when kid?(age) -> "just a kid"
greet: guard(_) -> "regular person"
The when
would just become the first line in the function and do an early return if not passed
const tailored = require('tailored');
const _ = tailored.wildcard();
const $ = tailored.parameter();
let fact = tailored.defmatch(
tailored.clause([0], () => 1),
tailored.clause([$], (n) => n * fact(n - 1))
);
let response = fact(0); //1
response = fact(10); //3628800
Would also be nice with an easier way to operate with Map
Set and Symbol
I'd suggest these improvements
# assigning a Map
%{a: 2, b: 3}
# assigning a set
&{a: 1, b: 4}
Assigning and referencing a symbol
:a: 2
z = :a
b: {:a: 2 :b: 3} or {:a => 2 :b => 3}
# Object.assign (get rid of << and >> for indentation, are they ever useful?)
Object.assign(a, b, c)
a << b << c
Alternative to 'wait (similar to yield or await in async/await)
personId <- findPerson 8
a <- getAds personId
Just some idea ;)
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.