New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

functionalscript

Package Overview
Dependencies
Maintainers
1
Versions
452
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functionalscript

FunctionalScript is a functional subset of JavaScript

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
167
decreased by-76.21%
Maintainers
1
Weekly downloads
 
Created
Source

FunctionalScript

FunctionalScript is a pure functional programming language and a subset of ECMAScript/JavaScript. It's inspired by

  • JSON, as a subset of JavaScript; FunctionalScript is a superset of JSON.
  • asm.JS/WebAssembly, as a subset of JavaScript;
  • TypeScript, as a superset of JavaScript.

Try FunctionalScript here.

Create a new FunctionalScript repository on GitHub here.

JSON

jsonFile = expression
expression = primitive | array | objects
primitive = 'true' | 'false' | 'null' | number | string
array = '[' (() | items) ']'
items = expression (() | ',' items)
object = '{' (() | properties) '}'
properties = propertyId ':' expression (() | ',' properties)
propertyId = string

Stage 0

This stage can be used as an intermediate-code for VMs.

fjsFile = expression
expression = primitive | array | object | func | id | propertyAccessor
func = ('()' | id) '=>' body
body = '{' statements 'return' expression ';' '}'
statements = () | (statement statements)
statement = decl | ifStatement
decl = `const` id `=` expression `;`
ifStatement = `if` `(` expression `)` body
propertyAccessor = expression `[` expression `]`
call = expression `(` ( expression | ()) `)`

Stage 0.1. Node.js

nodeFile = statements 'module.exports' '=' expression ';'

Stage 0.2.

Operators
expression = ... | 'undefined' | groupingOperator | binaryOperatorExpression | unaryOperator | conditionalOperator
groupingOperator = '(' expression ')'
binaryOperatorExpression = expression binaryOperator expression
binaryOperator = comparisonOperator | arithmeticOperator | bitwiseOperator | logicalOperators | '??'
comparisonBinaryOperator = '===' | '!==' | '>' | '<' | '>=' | '<='
arithmeticBinaryOperator = '+' | '-' | '*' | '/' | '%' | '**'
bitwiseBinaryOperator = '&' | '|' | '^' | '<<' | '>>' | '>>>'
logicalBinaryOperator = '&&' | '||'
unaryOperator = '-' | '~' | '!'

Note: the syntax should be fixed to reflect operator precedents.

No ==, !=, =... operators.

Function Expression
func = ('()' | id) '=>' (('{' statements 'return' expression ';' '}') | expression)
PropertyAccessor
propertyAccessor = expression (('[' expression ']') | ('.' id))
propertyId = string | id
BigInt

For example 42n.

Additional Operators
typeOfOperator = 'typeof' expression
inOperator = expression 'in' expression

Stage 0.3. Syntax sugar

Hex, binary and octal literals Functions with multiple parameters. Spread syntax. For example ...object. Destructing assignments. For example const {a,b} = exp;, const [a, b] = exp. Property Id expression { [exp]: exp }. Allow no semicolons. Optional comma in arrays and objects. Template literals const r= `onst r = ${exp}`;. An if statement if (exp) { ... return exp } Multiline strings

'sss\
   wwww'

Regular expressions.

Stage 1

Typing using JSDoc and TypeScript types.

Stage 2

Mutable types with exclusive ownership (similar to Rust mutability).

  • let, for, while etc. Note: let can work as an object name reuse. In this case, let objects can't be used in nested functions. It means we can't reference let object.
    let x = 5 // ok
    f(x)
    x = 'hello!' // ok
    f(x)
    const r = () => {
       return x // compilation error
    }
    
    Translated into
    const x0 = 5
    f(x0)
    const x1 = 'hello!'  
    f(x1)
    
  • Generators function*(){ ... yield ... }.
  • Async async () => f(await exp()).
  • hopefully, we will have ES pipe operator at this time.
  • pattern matching

Controversial ideas:

  • Import and export import x from "...", export const x = ..., export default = e.t.c. This may break new Function runners.
  • Functional-TypeScript as a subset of TypeScript. Note: FunctionalScript doesn't require an additional build step in contrast to TypeScript.

FAQs

Package last updated on 13 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc