8000 Merge pull request #234 from xeno-by/topic/reflection · techaddict/scala.github.com@55a6304 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55a6304

Browse files
committed
Merge pull request scala#234 from xeno-by/topic/reflection
rewritten intro paragraphs of reflection overview
2 parents ce1070e + 475f8a6 commit 55a6304

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

overviews/reflection/overview.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Overview
44

55
partof: reflection
66
num: 1
7-
outof: 6
7+
outof: 6
88
languages: [ja]
99
---
1010

@@ -13,37 +13,38 @@ languages: [ja]
1313
**Heather Miller, Eugene Burmako, Philipp Haller**
1414

1515
*Reflection* is the ability of a program to inspect, and possibly even modify
16-
itself at runtime. It has a long history across object-oriented, functional,
17-
and logic programming paradigms, with each paradigm evolving its own,
18-
sometimes markedly different, *status quo* for reflection. While more
19-
functional programming languages like Lisp/Scheme have focused primarily on
20-
reification to enable tasks like dynamic interpretation, object-oriented
21-
programming languages like Java have focused primarily on runtime reflection to
22-
enable tasks like the inspection and/or invocation of class members at runtime.
23-
24-
Three principal use cases of reflection across languages and paradigms are:
25-
26-
1. **Runtime Reflection**. The ability to inspect and invoke runtime types and their members.
27-
2. **Compile-time Reflection**. The ability to access and manipulate abstract syntax trees at compile time.
28-
3. **Reification**. The generation of abstract syntax trees at runtime in the case of (1), or at compile time in the case of (2).
16+
itself. It has a long history across object-oriented, functional,
17+
and logic programming paradigms.
18+
While some languages are built around reflection as a guiding principle, many
19+
languages progressively evolve their reflection abilities over time.
20+
21+
Reflection involves the ability to **reify** (ie. make explicit) otherwise-implicit
22+
elements of a program. These elements can be either static program elements
23+
like classes, methods, or expressions, or dynamic elements like the current
24+
continuation or execution events such as method invocations and field accesses.
25+
One usually distinguishes between compile-time and runtime reflection depending
26+
on when the reflection process is performed. **Compile-time reflection**
27+
is a powerful way to develop program transformers and generators, while
28+
**runtime reflection** is typically used to adapt the language semantics
29+
or to support very late binding between software components.
2930

3031
Until 2.10, Scala has not had any reflection capabilities of its own. Instead,
31-
one could use Java reflection which provided a very limited subset of runtime
32-
reflection capabilities from point (1) above. However, many Scala-specific types are
33-
simply unrecoverable under standalone Java reflection; including info about
34-
runtime existential, higher-kinded, path-dependent and abstract types. In
35-
addition to these Scala-specific types, Java reflection is also unable to
36-
recover runtime type info of Java types that are generic at compile-time; a
37-
restriction that carried through to runtime reflection on generic types in
38-
Scala.
32+
one could use part of the Java reflection API, namely that dealing with providing
33+
the ability to dynamically inspect classes and objects and access their members.
34+
However, many Scala-specific elements are unrecoverable under standalone Java reflection,
35+
which only exposes Java elements (no functions, no traits)
36+
and types (no existential, higher-kinded, path-dependent and abstract types).
37+
In addition, Java reflection is also unable to recover runtime type info of Java types
38+
that are generic at compile-time; a restriction that carried through to runtime
39+
reflection on generic types in Scala.
3940

4041
In Scala 2.10, a new reflection library was introduced not only to address the shortcomings
41-
of Java's runtime reflection on Scala-specific and generic types, but to also
42-
add a more powerful toolbox of general reflective capabilities to Scala. Along
43-
with full-featured runtime reflection for Scala types and generics (1), Scala 2.10 also
42+
of Javas runtime reflection on Scala-specific and generic types, but to also
43+
add a more powerful toolkit of general reflective capabilities to Scala. Along
44+
with full-featured runtime reflection for Scala types and generics, Scala 2.10 also
4445
ships with compile-time reflection capabilities, in the form of
45-
[macros]({{site.baseurl }}/overviews/macros/overview.html) (2), as well as the
46-
ability to *reify* Scala expressions into abstract syntax trees (3).
46+
[macros]({{site.baseurl }}/overviews/macros/overview.html), as well as the
47+
ability to *reify* Scala expressions into abstract syntax trees.
4748

4849
## Runtime Reflection
4950

@@ -342,4 +343,4 @@ For more details, see the section of this guide on
342343
[Mirrors]({{ site.baseurl}}/overviews/reflection/environment-universes-mirrors.html),
343344
or the
344345
[Mirrors API docs](http://www.scala-lang.org/api/{{ site.scala-version}}/scala/reflect/api/Mirrors.html)
345-
in package `scala.reflect.api`.
346+
in package `scala.reflect.api`.

0 commit comments

Comments
 (0)
0