Git Product home page Git Product logo

Comments (6)

leepike avatar leepike commented on September 23, 2024

Thanks. Yes, please do; I'll merge.

from ivory.

stelleg avatar stelleg commented on September 23, 2024

OK, I have two solutions. One is a quick fix that does an explicit zero check for the for and times functions. This has the downside that it adds a conditional every time these functions are used. I'm also not sure if you allow zero length arrays, but if you do then it could be a problem there as well.

The other solution that I've implemented is a more thorough solution that adds parameters for whether or not to be inclusive with the end value to the LoopIncr constructors. This change required a fair amount of modification, and broke a couple of tests that I haven't had a chance to look into further.

Let me know which you'd prefer.

from ivory.

leepike avatar leepike commented on September 23, 2024

Can you post the more thorough solution? It is likely close to what we've been considering--- @jameysharp discovered an issue a while ago we still haven't fixed in which (0 :: Ix 1) passed to for results in a bug. We might as well fix this once and for all. Don't worry about breaking old tests.

from ivory.

stelleg avatar stelleg commented on September 23, 2024

OK, I've created a pull request.

I believe the issue existed for for and times, and should be fixed for both.

Also, thanks for the talk on Wednesday, it was swell.

from ivory.

jameysharp avatar jameysharp commented on September 23, 2024

In case anyone wonders, discussion of this issue continued over on pull request #30.

from ivory.

elliottt avatar elliottt commented on September 23, 2024

OK, I've implemented a few changes as of 9d2d186 to deal with this:

  • The loop function in Ivory.Language.Loop now takes IxRep arguments for the bounds of the loop instead of Ix n, allowing for the indexes to be computed before the call to loop
  • for and times now use loop directly, instead of via upTo or downTo
  • for and times compute the loop bounds at IxRep instead of Ix n, which avoids the underflow in the case that n is 0

Additionally, I've made loop no longer exported from the Ivory.Language.Loop module, and similarly cleaned up the export list for Ivory.Language.Ix.

The downside to this fix is that if you do give an argument of type Ix 0 to times, you'll likely introduce either garbage data, or divide-by-zero. The fix for this is to always use the div-zero pass when generating code, which should catch cases like that.

from ivory.

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.