Comments (2)
Also, this:
case data do
:ok ->
Logger.info("info")
Todo.add(data)
:error ->
nil
end
instead of becoming this:
(function(){
if(Kernel.match__qmark__(Atom('ok'), data)){
Logger.info('info');
return Todo.add(data);
}else if(Kernel.match__qmark__(Atom('error'), data)){
return null;
}
}.call(this));
should become this
(function(){
const ok = 'ok';
const error = 'error';
switch (data) {
case ok:
break;
case error:
break;
}
})
from elixirscript.
- After taking a look at the current implementation, why we use
Atom('ok')
instead of justconst
Originally atoms were implemented as ES6 Symbols (before I understood how they work), but when I started working on pattern matching, I thought at the time they wouldn't work out well.
Fast forward to this weekend when I saw how Symbol.for
worked, I decided to use that instead. So now Atom("ok")
returns a Symbol by doing Symbol.for("ok")
. I left the function call to create it as so that if for some reason down the line Symbols don't work out, its just a matter of changing the implementation and not the interface.
- we use
List(1, 2, 3, 4, 5)
instead of an array literal?[1, 2, 3, 4, 5]
?
This is pretty recent as well. It used to translate to standard arrays, but to prevent any mutation, List wraps a frozen array. Same idea as above, the implementation could change, but the interface stays the same. Also Lists have an iterator (basically just using the underlying array's iterator) so it gets the benefit of being able to be used in for..of loops as well as array destructuring.
- Also, why we explicitly call this function with
this
?
That is so that when using this
inside of the function closures for translating case
, cond
, and for
expressions. It uses the this
of the outer scope. Since in Elixir they are part of the current scope it makes sure they act that way.
Also in the code example in your last message, yes that could work even with Symbols, but the Kernel.match?
function implements a lot of the current pattern matching algorithm and is more generic.
There are still some optimizations that can be done. I've thought about using the Google Closure Compiler, but it didn't look like they supported all of the ES6 features yet.
from elixirscript.
Related Issues (20)
- Track the modules a module uses
- Build failure with macOS 10.13 and Xcode 9 HOT 2
- ElixirScript Test Assertions HOT 1
- Create compiler manifest HOT 2
- Create manifests function in Mix compiler
- Create clean function in mix compiler HOT 1
- Use manifest to see if a module should be compiled or not HOT 1
- Regex functions throw errors HOT 3
- Is it possible to compile quoted or string? HOT 3
- Enum.map does not work in 0.32 HOT 2
- comprehensions/generators HOT 1
- in-browser Elixir parser / interpreter HOT 3
- Beginner Tutorial HOT 2
- FFI - Support npm modules directly
- Elixir + Wasm HOT 9
- Pragmatic question: working with JS Object HOT 3
- Elixir Script as ClientLibrary Framework to Interface with Elixir/Phoenix
- Still alive? HOT 2
- String.slice(str, 0, -1) raises FunctionClauseError HOT 1
- Inactive project HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixirscript.