Coder Social home page Coder Social logo

Multi-assignment might be nice about rock HOT 8 CLOSED

ooc-lang avatar ooc-lang commented on August 16, 2024
Multi-assignment might be nice

from rock.

Comments (8)

maximeg avatar maximeg commented on August 16, 2024

This will be interesting if it'll be compatible with function return.

some: func -> (Int, Int, Int) {
  return (1, 2, 3)
}

(a, b, c) := some()

And as usual, the notation of the type of returned value could be shortened in "-> Int" in case of same type for the n.

There's tons of possible examples.
One ramdomly picked and a bit stupid : a function that diagonalize a matrix and return the diagonalized matrix and the base changement matrix.

(excuse my english math...)

from rock.

nddrylliog avatar nddrylliog commented on August 16, 2024

Yes, yes that's definitely the spirit. We need an ORC on that.

from rock.

danopia avatar danopia commented on August 16, 2024

So it would be like tuples in other languages? As in immutable arrays?

from rock.

nddrylliog avatar nddrylliog commented on August 16, 2024

Well, even if they're only used in 1) assignment and 2) function retuns, they would still be pretty useful. Having them as a real data-type isn't really needed imho, we have arrays for that.

from rock.

wandernauta avatar wandernauta commented on August 16, 2024

Using multi-assignment for swapping values would be nice too:

(a, b) = (b, a)

How cool is that?

from rock.

solson avatar solson commented on August 16, 2024

It's cool, but is it needed? Where is that ever really necessary?

from rock.

nddrylliog avatar nddrylliog commented on August 16, 2024

Where is it ever necessary? Well, not that often, but often enough to justify it.

Turns out, it's really really easy to implement now that nagaqueen parses tuples and that rock has an AST node for it anyway. Just a matter of matching the left and right arguments, and creating a temp variable if needed.

A child could do it. Anyone wanna give it a try or do you prefer if I handle it?

from rock.

nddrylliog avatar nddrylliog commented on August 16, 2024

Fully implemented multi-assign. Closed by f1ecc49

from rock.

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.