diff --git a/docs/_docs/reference/contextual/context-bounds.md b/docs/_docs/reference/contextual/context-bounds.md index a06cb2d79181..60357b3f098d 100644 --- a/docs/_docs/reference/contextual/context-bounds.md +++ b/docs/_docs/reference/contextual/context-bounds.md @@ -199,10 +199,10 @@ The syntax of function types and function literals is generalized as follows to allow context bounds for generic type parameters. ```ebnf -FunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type +FunType ::= FunTypeArgs ('=>' | '?=>') Type | DefTypeParamClause '=>' Type -FunExpr ::= FunParams (‘=>’ | ‘?=>’) Expr - | DefTypeParamClause ‘=>’ Expr +FunExpr ::= FunParams ('=>' | '?=>') Expr + | DefTypeParamClause '=>' Expr ``` The syntax for abstract type members is generalized as follows to allow context bounds: diff --git a/docs/_docs/reference/contextual/deferred-givens.md b/docs/_docs/reference/contextual/deferred-givens.md index 232c15afda35..e63e26858d29 100644 --- a/docs/_docs/reference/contextual/deferred-givens.md +++ b/docs/_docs/reference/contextual/deferred-givens.md @@ -40,7 +40,7 @@ class SortedString[A] extends Sorted: override given Ord[String] = ... ``` -Note that the implementing given needs an `override` modifier since the `deferred` given in class `Sorted` counts as a concrete (i.e. not abstract) definition. In a sense, the `deferred` right hand side in `Sorted` is like a (magic, compiler-supported) macro, with the peculiarity that the macro's implementation also affects subclasses. +Note that the implementing given needs an `override` modifier since the `deferred` given in class `Sorted` counts as a concrete (i.e. not abstract) definition. In a sense, `deferred` on the right-hand side in `Sorted` is like a (magic, compiler-supported) macro, with the peculiarity that the macro's implementation also affects subclasses. ## Abstract Givens @@ -52,6 +52,6 @@ trait HasOrd[T]: ``` An abstract given has the form `given name: Type` without a right-hand side or arguments to the type. -Since Scala 3.6, abstract givens are made redundant by deferred givens. Deferred givens can replace abstract givens. They have better ergonomics, since deferred givens get naturally implemented in inheriting classes, so there is no longer any need for boilerplate to fill in definitions of abstract givens. +Since Scala 3.6, abstract givens are made redundant by deferred givens. Deferred givens have better ergonomics, since they get naturally implemented in inheriting classes, so there is no longer any need for boilerplate to fill in definitions of abstract givens. It is therefore recommended that software architectures relying on abstract givens be migrated to use deferred givens instead. Abstract givens are still supported in Scala 3.6, but will likely be deprecated and phased out over time. diff --git a/docs/_docs/reference/contextual/givens.md b/docs/_docs/reference/contextual/givens.md index b7be460c9a34..088ded2e8db4 100644 --- a/docs/_docs/reference/contextual/givens.md +++ b/docs/_docs/reference/contextual/givens.md @@ -83,11 +83,11 @@ given Position = enclosingTree.position ## Given Instance Initialization An unconditional given instance without parameters is initialized on-demand, the first -time it is accessed. If the given is a simple alias to some immutable value, the given is implemented as a simple forwarder, without incurring the cost of a field to hold a cached value. If a given is conditional, a fresh instance is created for each reference. +time it is accessed. If the given is a mere alias to some immutable value, the given is implemented as a simple forwarder, without incurring the cost of a field to hold a cached value. If a given is conditional, a fresh instance is created for each reference. ## Syntax -Here is the full syntax for given instances. Some of these forms of givens are explained on a separate page on [Other Forms of Givens](../more-givens.md). +Here is the full syntax for given instances. Some of these forms of givens are explained in a separate page: [Other Forms of Givens](../more-givens.md). ```ebnf Here is the complete context-free syntax for all proposed features. @@ -106,7 +106,7 @@ GivenConditional ::= DefTypeParamClause GivenType ::= AnnotType1 {id [nl] AnnotType1} ``` -A given instance starts with the reserved word `given`, which is followed by +A given instance starts with the reserved keyword `given`, which is followed by - An optional name and a colon - An optional list of conditions. diff --git a/docs/_docs/reference/contextual/more-givens.md b/docs/_docs/reference/contextual/more-givens.md index 3d0076543cd7..2f6dd63f7eab 100644 --- a/docs/_docs/reference/contextual/more-givens.md +++ b/docs/_docs/reference/contextual/more-givens.md @@ -43,14 +43,12 @@ given listOrd: [T] => (ord: Ord[T]) => Ord[List[T]]: ## By Name Givens -We sometimes find it necessary that a given alias is re-evaluated each time it is called. For instance, say we have a mutable variable `curCtx` and we want to define a given that returns the current value of that variable. A normal given alias will not do since by default given aliases are mapped to lazy vals. - -In general, we want to avoid re-evaluation of givens. But there are situations like the one above where we want to specify _by-name_ evaluation instead. This is achieved by writing a conditional given with an empty parameter list: +Though in general we want to avoid re-evaluating a given, there are situations where such a re-evaluation may be necessary. For instance, say we have a mutable variable `curCtx` and we want to define a given that returns the current value of that variable. A normal given alias will not do since by default given aliases are mapped to lazy vals. In this case, we can specify a _by-name_ evaluation insteadby writing a conditional given with an empty parameter list: ```scala val curCtx: Context given context: () => Context = curCtx ``` -With this definition, each time a `Context` is summoned we evaluate `context` function, which produces the current value of `curCtx`. +With this definition, each time a `Context` is summoned we evaluate the `context` function, which produces the current value of `curCtx`. ## Given Macros diff --git a/docs/_docs/reference/contextual/previous-givens.md b/docs/_docs/reference/contextual/previous-givens.md index dc88daaab691..a78d8a3751ea 100644 --- a/docs/_docs/reference/contextual/previous-givens.md +++ b/docs/_docs/reference/contextual/previous-givens.md @@ -161,7 +161,6 @@ Note that the inline methods within the given instances may be `transparent`. The inlining of given instances will not inline/duplicate the implementation of the given, it will just inline the instantiation of that instance. This is used to help dead code elimination of the given instances that are not used after inlining. - ## Pattern-Bound Given Instances Given instances can also appear in patterns. Example: @@ -215,12 +214,12 @@ Here is the syntax for given instances: ```ebnf TmplDef ::= ... - | ‘given’ GivenDef + | 'given' GivenDef GivenDef ::= [GivenSig] StructuralInstance | [GivenSig] AnnotType ‘=’ Expr | [GivenSig] AnnotType -GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody] +GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ':' +StructuralInstance ::= ConstrApp {'with' ConstrApp} [‘with’ TemplateBody] ``` A given instance starts with the reserved word `given` and an optional _signature_. The signature diff --git a/docs/_docs/reference/experimental/typeclasses.md b/docs/_docs/reference/experimental/typeclasses.md index c366c40779b9..add5853e10ba 100644 --- a/docs/_docs/reference/experimental/typeclasses.md +++ b/docs/_docs/reference/experimental/typeclasses.md @@ -18,7 +18,7 @@ a bit cumbersome and limiting for standard generic programming patterns. Much ha This note shows that with some fairly small and reasonable tweaks to Scala's syntax and typing rules we can obtain a much better scheme for working with type classes, or do generic programming in general. The bulk of the suggested improvements has been implemented and is available -in under source version `future` if the additional experimental language import `modularity` is present. For instance, using the following command: +in source version `future` if the additional experimental language import `modularity` is present. For instance, using the following command: ``` scala compile -source:future -language:experimental.modularity diff --git a/docs/_docs/reference/syntax.md b/docs/_docs/reference/syntax.md index 3e71718d0752..0f78ff03583e 100644 --- a/docs/_docs/reference/syntax.md +++ b/docs/_docs/reference/syntax.md @@ -214,9 +214,9 @@ ParamValueType ::= Type [‘*’] TypeArgs ::= ‘[’ Types ‘]’ Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>> TypeBounds ::= [‘>:’ Type] [‘<:’ Type] -TypeAndCtxBounds ::= TypeBounds [‘:’ ContextBounds] +TypeAndCtxBounds ::= TypeBounds [':' ContextBounds] ContextBounds ::= ContextBound - | ContextBound `:` ContextBounds -- to be deprecated + | ContextBound ':' ContextBounds -- to be deprecated | '{' ContextBound {',' ContextBound} '}' ContextBound ::= Type ['as' id] Types ::= Type {‘,’ Type} @@ -441,7 +441,7 @@ TypeDef ::= id [HkTypeParamClause] {FunParamClause}TypeBounds TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef | [‘case’] ‘object’ ObjectDef | ‘enum’ EnumDef - | ‘given’ (GivenDef | OldGivenDef) + | 'given' (GivenDef | OldGivenDef) ClassDef ::= id ClassConstr [Template] ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses ConstrMods ::= {Annotation} [AccessModifier]