New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutated Variable #455

Closed
nomicflux opened this Issue Dec 3, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@nomicflux

nomicflux commented Dec 3, 2015

I have run across a rather odd case where a named value gives a different result than its explicit numerical value. So in this code:

block : State -> Float -> Float -> Float -> Form
block settings basex index middle =
  let
    top = settings.collageSize.height
    (topColor, bottomColor) = getColors settings
  in
    rect (base |> Debug.log "Base") middle
         |> filled bottomColor
         |> deCenter settings middle
         |> moveX index

the Debug message displays 23.55638567754096 for the value of base, but the bars themselves display as about 1px. This occurs whether or not the Debug.log part is included, and even if the name is changed (to, say, basex), or if the base argument is calculated in the let block instead of passed in. By contrast,

rect 23.55638567754096 middle
     |> filled bottomColor
     |> deCenter settings middle
     |> moveX index

gives exactly the correct width.

The problem continues into the Javascript compilation:

   var block = F4(function (settings,
   base,
   index,
   middle) {
      return function () {
         var newBase = 23.55638567754096;
         console.log("In JS:", base, newBase, base == newBase, base === newBase);
         var $ = getColors(settings),
         topColor = $._0,
         bottomColor = $._1;
         var top = settings.collageSize.height;
         return $Graphics$Collage.moveX(index)(A2(deCenter,
         settings,
         middle)($Graphics$Collage.filled(bottomColor)(A2($Graphics$Collage.rect,
         base,
         middle))));
      }();
   });

The console message is:
"In JS:" 23.55638567754096 23.55638567754096 true true
So both base (given as a parameter) and newBase (assigned directly in the function) are considered fully equivalent. However, when I use base in the call to $Graphics$Collage at the end of the function, I get the weird 1px rectangles again; when I use newBase, I get the full-sized rectangles.

@rgrempel

This comment has been minimized.

Show comment
Hide comment
@rgrempel

rgrempel Dec 4, 2015

Contributor

Curious! The Javascript side of the problem is particularly hard to explain ... at first, I thought that it could possibly be a case of number primitive vs. Number object, but the === check rules that out.

You're more likely to get someone to play with this if you post a http://sscce.org -- I tried pasting your stuff into http://elm-lang.org/try for fun, but it's not very self-contained.

Contributor

rgrempel commented Dec 4, 2015

Curious! The Javascript side of the problem is particularly hard to explain ... at first, I thought that it could possibly be a case of number primitive vs. Number object, but the === check rules that out.

You're more likely to get someone to play with this if you post a http://sscce.org -- I tried pasting your stuff into http://elm-lang.org/try for fun, but it's not very self-contained.

@nomicflux

This comment has been minimized.

Show comment
Hide comment
@nomicflux

nomicflux Dec 4, 2015

I'm working on trying to produce an example which replicates the problem, and a simple example doesn't. If I just create a rectangle, there's no issue, and I'm creating the code for a proprietary concern, so I can't just link to a Github. Since a main point of Elm (and other functional languages) is that values are supposed to be immutable and I only have to think about inputs / outputs, I don't have the faintest clue where to start looking into what may be going wrong to continue the process besides a mess of compiled JavaScript, and I was hoping that someone would have some advice as to where to go to next. As soon as I have a SSCCE (and open source) example to post, I'll post it, but I don't yet and it seems like a serious enough issue to warrant an issue notification.

nomicflux commented Dec 4, 2015

I'm working on trying to produce an example which replicates the problem, and a simple example doesn't. If I just create a rectangle, there's no issue, and I'm creating the code for a proprietary concern, so I can't just link to a Github. Since a main point of Elm (and other functional languages) is that values are supposed to be immutable and I only have to think about inputs / outputs, I don't have the faintest clue where to start looking into what may be going wrong to continue the process besides a mess of compiled JavaScript, and I was hoping that someone would have some advice as to where to go to next. As soon as I have a SSCCE (and open source) example to post, I'll post it, but I don't yet and it seems like a serious enough issue to warrant an issue notification.

@evancz evancz added the no sscce label Dec 27, 2015

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 11, 2016

Member

If I understand correctly, this is an issue in Graphics.* so I am going to close and ask that it is reopened on evancz/elm-graphics if it is still a problem.

Member

evancz commented May 11, 2016

If I understand correctly, this is an issue in Graphics.* so I am going to close and ask that it is reopened on evancz/elm-graphics if it is still a problem.

@evancz evancz closed this May 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment