Comments (5)
For example, (cond (zero? x) 5 (cond (zero? x) 1 2))
should be reduced to (cond (zero? x) 5 2)
.
from lisp-interpreter.
This should speed up the prelude implementation of mult
a bit, for example.
from lisp-interpreter.
This should probably be done as two separate passes: 1 that detects duplicate function calls in expressions and wraps them in a closure and 1 that detects very simple patterns like cond $x (...) (... (cond $x ...) ...)
and cond $x (... (cond $x ...) ...) (...)
.
The basic idea behind the first pass is that we only compute things once when we need them multiple times. For example, it should replace (add (add1 x) (add1 x))
by ((lambda y (add y y)) (add1 x))
. We should be careful to do this at the right level to avoid unnecessary work. See the snippet below:
(cond z (mult 5 3) (add (add1 x) (add1 x)))
the lambda should replace the second branch of the condition and not the top level expression, since (add1 x)
isn't used in the first branch. I believe the rule should be that the lambda replaces the expression closest to the root of which at least two descendents use the same expression. The order in which we do this operation doesn't matter too much (?) - think (add (add1 (add1 x)) (add1 (add1 x)))
. Extracting (add1 x)
first and then (add1 y)
later isn't as elegant and slightly less efficient, but the total work done should be similar.
from lisp-interpreter.
The rule on the extraction above isn't correct. Counter-example:
(add (cond x (add1 z) 1) (cond y (add1 z) 2))
Here, (add1 z)
should not be extracted by the rule described above since it's not guaranteed to be used in both 'descendents' of add
. The rule should state that it is always guaranteed to be used in at least two descendents, which is a lot more complicated to verify unfortunately...
from lisp-interpreter.
This has kind of been addressed in #51.
from lisp-interpreter.
Related Issues (20)
- Introduce more efficient instruction storage HOT 2
- Experiment with quickcheck?
- Add zip to prelude HOT 1
- Reverse lists HOT 1
- Walk instructions forward instead of backward HOT 2
- Do list splits more efficiently HOT 1
- Add FinalizedExpr type HOT 1
- Figure out proper implementation of CustomFunc HOT 1
- Fix shadowing issues HOT 1
- Restrict usage of define HOT 2
- Merge cond-zero branch
- Bug in argument recursion copy elision
- Unreverse bytecode execution order HOT 1
- Make it compile to javascript HOT 1
- Return analysis? HOT 1
- Upgrade parser zodat ook niet-calls geaccepteerd worden
- Update README
- Church numerals do not work HOT 1
- Ternary expressions won't return curried functions?
- Nightly rust version can not compile the code now HOT 2
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 lisp-interpreter.