News for hackers. Stuff that matters.
Re:Grain: A strongly-typed functional programming language f... by gopiandcode on Monday April 26, 2021 @06:52AM (#26941200)
Here's an example of how the behaviour between Rust and Python differ because of scoping:

in Rust:

  fn main() {
    let a = 3;
    let f = | | { a };
    let a = "b";
    println!("{}, {}", f(), a);
  }
in Python:

  a = 3
  def f ():
      return a
  a = "b"
  print("{}, {}".format(f(), a))

The rust code outputs "3, b" while the python code outputs "b, b". The python code _assigns_ to the variable a, whereas the rust code creates a new scope and redefines a, shadowing it in the parent scope.
Re:Grain: A strongly-typed functional programming language f... by KingOfCoders on Monday April 26, 2021 @07:10AM (#26941297)
Yes you're right, I also would think closures would be impacted by scope.