添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I googled "←" and searched for it on here, unable to find anything. But I found this source code for a chess game. View it here . Example of a code block that has copious usage of this symbol:

 for {
      storedFen ← GameRepo initialFen game
      fen = storedFen orElse (aiVariant match {
        case v@Horde => v.initialFen.some
        case _       => none
      uciMoves ← uciMemo get game
      moveResult ← move(uciMoves.toList, fen, level, aiVariant)
      uciMove ← (UciMove(moveResult.move) toValid s"${game.id} wrong bestmove: $moveResult").future
      result ← game.toChess(uciMove.orig, uciMove.dest, uciMove.promotion).future
      (c, move) = result
      progress = game.update(c, move)
      _ ← (GameRepo save progress) >>- uciMemo.add(game, uciMove.uci)
    } yield PlayResult(progress, move)

The Scala spec says on page 4 that (unicode \u2190) is reserved as is its ascii equivalent <- which as others are also pointing out, is an iterator for a for loop.

for(x <- 1 to 5)  println(i)

In scala you can bracket a complex expression and treat it as a single line with value provided by the end of the expression. What this is doing is creating a large nested for loop where each run through the loop increments the iterator at the end of the loop until, when it recycles, iterates the earlier iterator.

Here's an example using the scala shell and both syntaxes:

This is how most people write a for loop

Note that the | symbol is a line continuation not typed by me but rather inserted by scala shell

scala> for { 
     | x<-1 to 5
     | y<-2 to 6
     | } println (x,y)
(1,2)
(1,3)
(1,4)
(1,5)
(1,6)
(2,2)
(2,3)
(5,5)
(5,6)

But you can also use that funny arrow unicode symbol and it does the same thing:

scala> for {
     | x ← 1 to 5 
     | y ← 2 to 6 
     | } println (x,y)
(1,2)
(1,3)
(1,4)
(1,5)
(1,6)
(2,2)
(2,3)
(5,5)
(5,6)

You might notice that some of the expressions in that complex for {} block you posted are assignments, not iterations. That's allowed, and doesn't break the chain of iteration. Here's a simpler example:

scala> for {
     | x ← 1 to 3
     | y = x*x 
     | z ← 1 to 4
     | } println (x,y,z)
(1,1,1)
(1,1,2)
(1,1,3)
(1,1,4)
(2,4,1)
(2,4,2)
(2,4,3)
(2,4,4)
(3,9,1)
(3,9,2)
(3,9,3)
(3,9,4)
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.