Live data from Hacker News

Generalised plusequals

leontrolski.github.io

1–10 of 13 posts

Re: Generalised plusequals

#4
It seems like this is proposing syntactic sugar to make mutating and non-mutating operations be on equal footing.

> The more interesting example is reassigning the deeply nested l to make the cat inside older, without mutating the original cat

Isn't that mutating l, though? If you're concerned about mutating cat, shouldn't you be concerned about mutating l?

Re: Generalised plusequals

#5
post #4

It seems like this is proposing syntactic sugar to make mutating and non-mutating operations be on equal footing. > The more interesting example is reassigning the deeply nested l to make the cat inside older, without mutating the original cat Isn't that mutating l, though? If you're concerned about mutating cat, shouldn't you be concerned about mutating l?

It doesn't mutate l exactly, it makes a new list slightly different from the original one and assigns it to l.

That means if someone has a reference to the original l, they do not see the change (because l is immutable. Both of them).

Re: Generalised plusequals

#7
In Lil[0], this is how ordinary assignment syntax works. Implicitly defining a dictionary stored in a variable named "cat" with a field "age":

    cat.age:3
    # {"age":3}
Defining "l" as in the example in the article. We need the "list" operator to enlist nested values so that the "," operator doesn't concatenate them into a flat list:

    l:1,(list 2,list cat),4
    # (1,(2,{"age":3}),4)
Updating the "age" field in the nested dictionary. Lil's basic datatypes are immutable, so "l" is rebound to a new list containing a new dictionary, leaving any previous references undisturbed:

    l[1][1].age:9
    # (1,(2,{"age":9}),4)
    cat
    # {"age":3}
There's no special "infix" promotion syntax, so that last example would be:

    l:l,5
    # (1,(2,{"age":9}),4,5)
[0] http://beyondloom.com/tools/trylil.html

Re: Generalised plusequals

#8
post #4

It seems like this is proposing syntactic sugar to make mutating and non-mutating operations be on equal footing. > The more interesting example is reassigning the deeply nested l to make the cat inside older, without mutating the original cat Isn't that mutating l, though? If you're concerned about mutating cat, shouldn't you be concerned about mutating l?

It doesn't mutate l exactly, it makes a new list slightly different from the original one and assigns it to l. That means if someone has a reference to the original l, they do not see the change (because l is immutable. Both of them).

[deleted]

Re: Generalised plusequals

#9
post #4

It seems like this is proposing syntactic sugar to make mutating and non-mutating operations be on equal footing. > The more interesting example is reassigning the deeply nested l to make the cat inside older, without mutating the original cat Isn't that mutating l, though? If you're concerned about mutating cat, shouldn't you be concerned about mutating l?

It doesn't mutate l exactly, it makes a new list slightly different from the original one and assigns it to l. That means if someone has a reference to the original l, they do not see the change (because l is immutable. Both of them).

I think I am misunderstanding the behavior of the alt keyword

Re: Generalised plusequals

#10

In Lil[0], this is how ordinary assignment syntax works. Implicitly defining a dictionary stored in a variable named "cat" with a field "age": cat.age:3 # {"age":3} Defining "l" as in the example in the article. We need the "list" operator to enlist nested values so that the "," operator doesn't concatenate them into a flat list: l:1,(list 2,list cat),4 # (1,(2,{"age":3}),4) Updating the "age" field in the nested dic…

This is surprising to me:

  l[1][1].age:9
  # (1,(2,{"age":9}),4)
How come it doesn't return just:

  {"age":9}
Or is there something totally different going on with references here? As in, how is this different to:

  l_inner = l[1][1]
  l_inner.age:9
Post reply on HN