src/Doc/System/Scala.thy
author wenzelm
Thu, 22 Oct 2015 21:16:49 +0200
changeset 61503 28e788ca2c5d
parent 61407 7ba7b8103565
child 61575 f18f6e51e901
permissions -rw-r--r--
more control symbols; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     1
theory Scala
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     2
imports Base
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     3
begin
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     4
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
     5
chapter \<open>Isabelle/Scala development tools\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
     7
text \<open>Isabelle/ML and Isabelle/Scala are the two main language
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     8
environments for Isabelle tool implementations.  There are some basic
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
     9
command-line tools to work with the underlying Java Virtual Machine,
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    10
the Scala toplevel and compiler.  Note that Isabelle/jEdit
58553
3876a1a9ee42 prefer @{cite} antiquotation;
wenzelm
parents: 57855
diff changeset
    11
@{cite "isabelle-jedit"} provides a Scala Console for interactive
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    12
experimentation within the running application.\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    13
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    14
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    15
section \<open>Java Runtime Environment within Isabelle \label{sec:tool-java}\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    16
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    17
text \<open>The @{tool_def java} tool is a direct wrapper for the Java
48602
342ca8f3197b more uniform usage of "isabelle tool";
wenzelm
parents: 47825
diff changeset
    18
  Runtime Environment, within the regular Isabelle settings
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    19
  environment (\secref{sec:settings}).  The command line arguments are
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    20
  that of the underlying Java version.  It is run in \<^verbatim>\<open>-server\<close> mode
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    21
  if possible, to improve performance (at the cost of extra startup time).
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    22
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    23
  The \<^verbatim>\<open>java\<close> executable is the one within @{setting
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    24
  ISABELLE_JDK_HOME}, according to the standard directory layout for
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    25
  official JDK distributions.  The class loader is augmented such that
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    26
  the name space of \<^verbatim>\<open>Isabelle/Pure.jar\<close> is available,
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    27
  which is the main Isabelle/Scala module.
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    28
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    29
  For example, the following command-line invokes the main method of
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    30
  class \<^verbatim>\<open>isabelle.GUI_Setup\<close>, which opens a windows with
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    31
  some diagnostic information about the Isabelle environment:
61407
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    32
  @{verbatim [display] \<open>isabelle java isabelle.GUI_Setup\<close>}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    33
\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    34
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    35
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    36
section \<open>Scala toplevel \label{sec:tool-scala}\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    37
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    38
text \<open>The @{tool_def scala} tool is a direct wrapper for the Scala
48602
342ca8f3197b more uniform usage of "isabelle tool";
wenzelm
parents: 47825
diff changeset
    39
  toplevel; see also @{tool java} above.  The command line arguments
342ca8f3197b more uniform usage of "isabelle tool";
wenzelm
parents: 47825
diff changeset
    40
  are that of the underlying Scala version.
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    41
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    42
  This allows to interact with Isabelle/Scala in TTY mode like this:
61407
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    43
  @{verbatim [display]
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    44
\<open>isabelle scala
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    45
scala> isabelle.Isabelle_System.getenv("ISABELLE_HOME")
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    46
scala> val options = isabelle.Options.init()
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    47
scala> options.bool("browser_info")
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    48
scala> options.string("document")\<close>}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    49
\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    50
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    51
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    52
section \<open>Scala compiler \label{sec:tool-scalac}\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    53
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    54
text \<open>The @{tool_def scalac} tool is a direct wrapper for the Scala
48602
342ca8f3197b more uniform usage of "isabelle tool";
wenzelm
parents: 47825
diff changeset
    55
  compiler; see also @{tool scala} above.  The command line arguments
342ca8f3197b more uniform usage of "isabelle tool";
wenzelm
parents: 47825
diff changeset
    56
  are that of the underlying Scala version.
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    57
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    58
  This allows to compile further Scala modules, depending on existing
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    59
  Isabelle/Scala functionality.  The resulting class or jar files can
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61407
diff changeset
    60
  be added to the Java classpath using the \<^verbatim>\<open>classpath\<close> Bash
53576
793a429c63e7 maintain classpath in more elementary manner: turn ISABELLE_CLASSPATH into -classpath option, so that all jars are covered by sun.misc.Launcher.AppClassLoader (e.g. relevant for loading add-on resources);
wenzelm
parents: 52116
diff changeset
    61
  function that is provided by the Isabelle process environment.  Thus
793a429c63e7 maintain classpath in more elementary manner: turn ISABELLE_CLASSPATH into -classpath option, so that all jars are covered by sun.misc.Launcher.AppClassLoader (e.g. relevant for loading add-on resources);
wenzelm
parents: 52116
diff changeset
    62
  add-on components can register themselves in a modular manner, see
793a429c63e7 maintain classpath in more elementary manner: turn ISABELLE_CLASSPATH into -classpath option, so that all jars are covered by sun.misc.Launcher.AppClassLoader (e.g. relevant for loading add-on resources);
wenzelm
parents: 52116
diff changeset
    63
  also \secref{sec:components}.
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    64
58553
3876a1a9ee42 prefer @{cite} antiquotation;
wenzelm
parents: 57855
diff changeset
    65
  Note that jEdit @{cite "isabelle-jedit"} has its own mechanisms for
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    66
  adding plugin components, which needs special attention since
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    67
  it overrides the standard Java class loader.\<close>
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    68
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    69
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    70
section \<open>Scala script wrapper\<close>
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    71
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    72
text \<open>The executable @{executable
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    73
  "$ISABELLE_HOME/bin/isabelle_scala_script"} allows to run
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    74
  Isabelle/Scala source files stand-alone programs, by using a
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    75
  suitable ``hash-bang'' line and executable file permissions.
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    76
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    77
  The subsequent example assumes that the main Isabelle binaries have
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    78
  been installed in some directory that is included in @{setting PATH}
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    79
  (see also @{tool "install"}):
61407
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    80
  @{verbatim [display]
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    81
\<open>#!/usr/bin/env isabelle_scala_script
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    82
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    83
val options = isabelle.Options.init()
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    84
Console.println("browser_info = " + options.bool("browser_info"))
61407
7ba7b8103565 @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 58618
diff changeset
    85
Console.println("document = " + options.string("document"))\<close>}
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    86
53982
wenzelm
parents: 53576
diff changeset
    87
  Alternatively the full @{file
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    88
  "$ISABELLE_HOME/bin/isabelle_scala_script"} may be specified in
58618
782f0b662cae more cartouches;
wenzelm
parents: 58553
diff changeset
    89
  expanded form.\<close>
52116
abf9fcfa65cf added isabelle_scala_script wrapper -- NB: portable hash-bang allows exactly one executable, without additional arguments;
wenzelm
parents: 48985
diff changeset
    90
47825
4f25960417ae some coverage of Isabelle/Scala tools;
wenzelm
parents:
diff changeset
    91
end