Skip to content

[docs/reference] more fixes in Markdown files #10826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2020

Conversation

michelou
Copy link
Contributor

@michelou michelou commented Dec 16, 2020

Follow up of PR #10767.

Fixes further issues found in MarkDown files in docs/reference/, e.g,

  • removed extra spaces
  • corrected misspellings, etc.
  • reduced line width in several code blocks (to avoid text overflow in the right margin)
  • added missing link to PNG image (class hierarchy in section 6.11.1)
  • added several external links (e.g. Unicode character)

PS. The result of the above changes can be viewed in the PDF document scala3_reference.pdf (736 Kb) generated with Pandoc 2.11.

@michelou michelou requested a review from liufengyun December 16, 2020 23:32
@michelou michelou changed the title [docs/reference]more fixes in Markdown files [docs/reference] more fixes in Markdown files Dec 16, 2020
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @michelou 👍

added missing PNG image (class hierarchy in section 6.11.1)

Do you forget the file, I can't find it in the PR.

case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
case '[EmptyTuple] => Nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolasstucki : Do we still support this use case? It seems to be a valid use case.

@@ -183,7 +183,7 @@ private def dynamicPower(n: Int, x: Double): Double =
else if (n % 2 == 0) dynamicPower(n / 2, x * x)
else x * dynamicPower(n - 1, x)
```
---

This assumes a `Constant` extractor that maps tree nodes representing
constants to their values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolasstucki : do we still support Constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liufengyun For some reason the PNG file explicit-nulls-type-hierarchy.png is outside the docs/reference/ directory (see images/explicit-nulls/). Before running pandoc I call a small preprocessor script which performs several transformations, e.g.

  • replace internal relative links to anchors
  • copy image files to the right place for pandoc

Copy link
Contributor

@nicolasstucki nicolasstucki Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that code is extremely outdated and would not compile. I would use the following version instead


inline def power(x: Double, n: Int): Double =
  ${ powerExpr('x, 'n) }

private def powerExpr(n: Expr[Int], x: Expr[Double])(using Quotes): Expr[Double] =
  n.value match
    case Some(m) => powerCode(x, m)
    case _ => '{ dynamicPower($x, $n) }

private def dynamicPower(x: Double, n: Int): Double =
  if n == 0 then 1.0
  else if n % 2 == 0 then dynamicPower(x * x, n / 2)
  else x * dynamicPower(x, n - 1)

This assumes a .value that maps tree nodes representing constants to their values.


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolasstucki Is the following self-contained code ok for you (NB. powerCode is not defined in your code) ?!

For replacement of the first code example in section "Going Further" of file metaprogramming/macro-spec.md:

import scala.quoted.Expr
import scala.quoted.Quotes

inline def power(x: Double, n: Int): Double =
  ${ powerExpr('x, 'n) }

private def powerExpr(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] =
  n.value match
    case Some(m) => powerExpr(x, m)
    case _ => '{ dynamicPower($x, $n) }

private def powerExpr(x: Expr[Double], n: Int)(using Quotes): Expr[Double] =
  if n == 0 then '{ 1.0 }
  else if n == 1 then x
  else if n % 2 == 0 then '{ val y = $x * $x; ${ powerExpr('y, n / 2) } }
  else '{ $x * ${ powerExpr(x, n - 1) } }

private def dynamicPower(x: Double, n: Int): Double =
  if n == 0 then 1.0
  else if n % 2 == 0 then dynamicPower(x * x, n / 2)
  else x * dynamicPower(x, n - 1)

For testing (not to be included): Main.scala

@main
def Main: Unit =
  val x = 2.0
  for n <- 1 to 10 do
    println(s"power($x, $n) = ${power(x, n)}")

PS. The paragraph directly following the above code example mentions Constant. I assume that text can be removed right ?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace it with

This assumes a `.value` that maps tree nodes representing constants to their values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And use import scala.quoted._

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liufengyun addressed review comment.

@liufengyun
Copy link
Contributor

Thanks @michelou 👍

@liufengyun liufengyun merged commit bfb0b81 into scala:master Dec 17, 2020
@michelou
Copy link
Contributor Author

@liufengyun Thanks. I will create an new PR with more changes, including Nicolas's suggestion (see above):

This assumes a `.value` that maps tree nodes representing constants to their values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants