question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in pushing with tuples

See original GitHub issue

There is a bug when we work with multidimensional arrays. When we push an array to an empty array, we get not an array of a 1 length containing the pushed array, but the original pushed array.

This makes things like #677 very hard to do, 'cause we need to make the first contatenation by hand using $foo = $foo, $bar for the second push in a situation like this:

$array = ()
for $i in 1..3
  push($array, ($i $i))

.foo
  val: unquote(join(', ', $array))

The code above gives us val: 1, 1, 2 2,3 3; while we’d expect it to give us 1 1, 2 2, 3 3.

The only fix I found is to do so:

$array = ()
for $i, $index in 1..3
  $new = ($i $i)
  if $index == 1
    $array = $array, $new
  else
    push($array, $new)

.foo
  val: unquote(join(', ', $array))

So, this is obviously a bug. However, fixing it could bring troubles if someone had used this incorrect behaviour in his code.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
gavinmcfarlandcommented, May 7, 2015

So the only workaround that I can come up with with the fix applied is doing the following.

array = ""

for i in 1..3 {
    push(array, i i)
}

shift(array)

This produces

inspect: (1 1) (2 2) (3 3)

Maybe someone else might find this useful.

0reactions
gavinmcfarlandcommented, Jun 28, 2015

Sorry me again, but since working on a project that uses the push bif frequently I’ve come across some issues with the proposed fix. It’s difficult to explain so I’ll try to demonstrate it with an example.

With the fix it doubles up the parentheses which causes issues when iterating through the list, as you have to iterate through two layers, rather than one.

foo = (1 1) (2 2) (3 3)
bar = (a a) (b b) (c c)
foobar = ""

for foz in foo {
    for baz in bar {
        push(foobar, baz)
    }
}

// To remove the first item in the array
unusedVariable = shift(foobar)

p(foobar)

With the fix produces

inspect: ((a a)) ((b b)) ((c c)) ((a a)) ((b b)) ((c c)) ((a a)) ((b b)) ((c c))

Without the fix this produces

inspect: (a a) (b b) (c c) (a a) (b b) (c c) (a a) (b b) (c c)

I wish I could offer more help to contribute to a fix, but I’m not very familiar with the inner workings of Stylus.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pushing on array of tuple crashes Julia #33727 - GitHub
On Julia 1.1 1.2 1.3 function mean_foo(m) where {T} f = NTuple[] n = [1,1] for i in 1:2 x = ntuple(_->zeros(10),n[i]) for...
Read more >
python - Tuples: += operator throws exception, but succeeds?
The assigning of t[0] to the top of the stack occurs with STORE_SUBSCR , which fails here as t itself is an immutable...
Read more >
BUG #16846: "retrieved too many tuples in a bounded sort"
In this function, after reading the last tuple and judging that it does not belong to the previous group, the program breaks from...
Read more >
Prefer List of Tuples over Tuple of Lists - Justin Austin
Using a list of tuples instead of a tuple of lists is an easy way to help make illegal states unrepresentable without any...
Read more >
lost-tuple bug and fix for Rinda::TupleSpaceProxy.take
Pushing to the port fails if the process that called #take has exited, so the tuple will not be deleted from the tuplespace...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found