-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[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
Conversation
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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._
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liufengyun addressed review comment.
Thanks @michelou 👍 |
@liufengyun Thanks. I will create an new PR with more changes, including Nicolas's suggestion (see above):
|
Follow up of PR #10767.
Fixes further issues found in MarkDown files in
docs/reference/
, e.g,PS. The result of the above changes can be viewed in the PDF document
scala3_reference.pdf
(736 Kb) generated with Pandoc 2.11.