Code Monkey home page Code Monkey logo

Comments (5)

marcusklaas avatar marcusklaas commented on September 26, 2024

For example, (cond (zero? x) 5 (cond (zero? x) 1 2)) should be reduced to (cond (zero? x) 5 2).

from lisp-interpreter.

marcusklaas avatar marcusklaas commented on September 26, 2024

This should speed up the prelude implementation of mult a bit, for example.

from lisp-interpreter.

marcusklaas avatar marcusklaas commented on September 26, 2024

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.

marcusklaas avatar marcusklaas commented on September 26, 2024

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.

marcusklaas avatar marcusklaas commented on September 26, 2024

This has kind of been addressed in #51.

from lisp-interpreter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.