Language Research Paperx

Download Report

Transcript Language Research Paperx



Jamie Gordon


(lay-tek) Documents!



LATEX2ε is the current version
www.latex-project.org/ftp.html
proTeXt for Windows ~1.6GB
o Gives TeX, LaTeX through MikTeX 2.9 (with PDF conversion)
o Includes GUI TeXstudio

If you hate GUIs:
o latex foo.tex
Creates DVI
o xdvi foo.dvi
View DVI (UNIX)
o yap foo.dvi
View DVI (Windows)



Stable
Linux, OSX, and Windows
You can either get proTeXt or get the individual Parts:
o TEX/LATEX program for processing LATEX into PDF or DVI documents
o Text Editor or IDE
o PDF/DVI viewing program
o Program to handle PostScript files and images for inclusion into
documents (if necessary)




A Markup Language for typesetting documents
Very useful for scientific or mathematical documents
Still useful for any other kind of paper
Is built on top of TEX by Leslie Lamport
o TeX was a program & language designed by Donald E. Knuth (1977)
o Primarily for mathematical equations and formulas at first
o Designed to unlock the potential of digital printing






Advantages
Excels at typesetting
Math formulas
Consistent formatting for
professional look
Provides many layouts
Complex structures
(footnotes, etc.) can be
easily generated
Free, as are add-ons



Disadvantages
Code is not very reusable
Time consuming to create
new layout
Many external packages
are not well documented


Everything in LaTeX is either a command, environment, or
text.
Commands and environments are case sensitive.

Two formats:
o Starts with a \ and a name consisting of letters
o Starts with a \ and one non-letter


There are also starred (*) variants of many commands
Whitespace after a command is ignored if there are no
parameters
o To get a space after a command, always leave an empty parameter
when none is required

1.
2.

Two flavors of parameters:
{ } – required
[ ] – optional
Combine all your knowledge:
o \command[optional]{required}{required2}
So the file structure is
arguably the most important
part of the language


A space where a new formatting style can be applied
There are environments for:
o Lists (itemize, enumerate)
o Code listings (lstlisting)
o Comments (comment)
o Tables (tabular)

An environment surrounds content:
o \begin{environment}
o Content…
o \end{environment}
Can also be defined in the
preamble.
This code is inserted by compiler
where \begin{smalldoubleitemize} is
This code is inserted by compiler
where \end{smalldoubleitemize} is
article
For articles in scientific journals,
presentations, short reports, program
documentation, invitations, ...
IEEEtran
For articles with the IEEE Transactions
format.
proc
A class for proceedings based on the
article class.
minimal
Is as small as it can get. It only sets a
page size and a base font. It is mainly
used for debugging purposes.
report
For longer reports containing several
chapters, small books, thesis, ...
book
For real books.
slides
For slides. The class uses big sans serif
letters.
memoir
For changing sensibly the output of the
document. It is based on
the book class, but you can create any
kind of document with it [1]
letter
For writing letters.
beamer
For writing presentations
(see LaTeX/Presentations).



The document class
helps define the
default values for
document styling
Some (like book)
provide new
commands that would
not otherwise be
available (like chapter)
http://en.wikibooks.or
g/wiki/LaTeX/Docume
nt_Structure#Docume
nt_classes

You can write equations! Fancy ones even!
Inline: surround by $...$

Multiline:

o \begin{equation}
o x^n + y^n = z^n, n\leq{}2
o \end{equation}




Compiled
Compilation to DVI is quick
Conversion to PDF is slower
Depending on the amount of code that has changed, the
process can take between 1 and 5 seconds

Code is very simple to write
o Most of it is text, after all

The purpose of code can be easily inferred form the names
or the context of use
o Eases readability and writability

There are many available commands and environments,
probably near impossible to know all of them



There are only three basic constructs: commands,
environments, and text
The combinations between them are also relatively small
Commands can be within environments, but commands
cannot surround environments





Syntax is quite simple
Everything that is not explicitly related to content is included
in the preamble
Content within the preamble is very well defined
All commands follow the same format as do environments
An exception which is not well documented:
o \command|…|
o I believe this takes an environment and converts it to be inline

Semantics can be easily inferred from names




Compilation requires code to be correct before any output
will be created
This means program verification is always required
Because the language is built on TeX (believed to be one of
the most stable language implementations) the current
version is especially stable
Code can be used on almost any computing system


Concurrency, Object-Oriented, Functional





“Scalable Language”
Supposed to grow with you; as you become “more powerful”
with the language
Claimed to be both an Object-oriented and functional
Runs on the JVM (can also use all Java libraries)
Open Source





www.scala-lang.org/download
JVM
Unix-based or Windows systems
There is an Eclipse Plugin
Compile:
o scalac HelloWorld.scala

Run:
o scala HelloWorld

Try in browser www.simplyscala.com
Advantages





Runs on JVM (portability, Java
libraries)
Scalable
Concurrency and parallelism
are readily supported
Open-source project,
consistently being improved
Mission critical server
systems

Disadvantages
A language without a clear
vision
o Wants to be both object-
oriented and functional


Difficult readability and
writability
Terse documentation



The object-oriented part of Scala is based on Java syntax,
for the most part
Much of the difference comes from the compiler “inferring”
things on behalf of the programmer
Scala documentation insists that you can start writing Scala
programs as you would writing Java programs
object HelloWorld {
def main(args: Array[String]){
println("Hello, world!")
}
}
Note the use of the reserved word “object,” means this is a
singleton object (instead of class)
 No explicit data encapsulation, return type, or static modifier
definitions
 Scala has no static members and return type is inferred to be
void
 Parameter syntax arrays are explicitly referred to as a class

(1).+(((2).*(3))./(x))


Numbers are objects, and any operand is actually a method
from an object
Actually, functions are also objects
o Functions can be passed as parameters
o This is why Scala can be used as a functional language
Inference:
1 + 2 * 3 / x
(also legal syntax)





The Scala compiler attempts to infer a lot about what you
are coding
This means that semicolons are (usually) not required
However, sometimes they are required
Possibly from ambiguity in the grammar, I was not able to
find any documentation for why this is the case
def not(x: MyBool) = x negate; // semicolon required here
def xor(x: MyBool, y: MyBool) = (x or y) and not(x and y)

Names are given using keywords: val and var
val – immutable values
var – variables

Statically typed


o Given types at compile-time

Sometimes compiler will not be able to infer data type from
context, then you will have to explicitly tell the compiler
using an annotation
o However, you will not be able to tell this until the compiler throws an
error at you



Proponents of Scala insist that type inference both reduces
the amount of typing that must be done and that it gives
code more clarity
It does reduce the amount of typing done
It also hurts readability



Scala boasts of its inferences
However, overridden methods have to be preceded by
override, as in the below
The two methods re & im are defined without parameters,
this means that they can be called without parentheses
o However, this makes them resemble variables more than methods
class Complex(real: Double, imaginary: Double) {
def re = real
def im = imaginary
override def toString() =
"" + re + (if (im < 0) "" else "+") + im + "i"
}





Compiled
There are complaints of the compiler being slow
The more of Scala’s features that are used, the slower the
compilation is (also affects testing)
Efficiency of execution is tied to efficiency of JVM
Just-in-time compilation, low optimization and bytecode is
interpreted




Inferences decreases readability and writability
Perhaps after careful study, the ins and outs of inferences
can make code easier to write, however, readability will
always be affected
Readability is affected by how much functional and objectoriented code is mixed
Readability can be enhanced by parameter inference; code
looks more like standard English
import scala._
// Wild card -- all of Scala is imported
import scala.{ Predef => _, _ } // Exception, everything
except Predef
def f[M[_]]
// Higher kinded type parameter
def f(m: M[_])
// Existential type
_ + _
// Anonymous function placeholder parameter
m _
// Eta expansion of method into method value
m(_)
// Partial function application
_ => 5
// Discarded parameter
case _ =>
// Wild card pattern -- matches anything
val (a, _) = (1, 2) // same thing
for (_ <- 1 to 10) // same thing
f(xs: _*)
// Sequence xs is passed as multiple
parameters to f(ys: T*)
case Seq(xs @ _*) // Identifier xs is bound to the whole
matched sequence
var i: Int = _
// Initialization to the default value
def abc_<>!
// An underscore must separate alphanumerics
from symbols on identifiers
t._2
// Part of a method name, such as tuple
getters



Leaves much to be desired
Many symbols are pulling double-duty, and often in ways
that do not make a lot of sense
Standard operations can be overridden by the programmer





Reliability is in many ways tied to the JVM
This makes it highly portable
Static typing
Problems with typing can be found at compile time
However, verification of whether or not the compiler can
compile inferred code cannot be decided at design-time






Anonymous functions
Anonymous variables
Traits (interfaces with code, basically an abstract class)
Implicit classes
Pass functions as arguments
Case classes


Function-level, Math, Stat, Logical Analysis







Developed in 1990 by Kenneth E. Iverson and Roger Hui
Combination of APL and function-level languages
http://www.jsoftware.com/
Can get it for free, commercial license is available
Current version is j701
J is a function-level language maintained by Jsoftware, inc.
Uses tacit programming and the basic ASCII character set


Not a functional language, more constrained
Hierarchy of types:
o Atoms
o Functions (process atoms into other atoms)
o High-order functions (process functions into other functions)
Advantages


Primarily designed to tackle
“mathematical, statistical,
and logical analysis of data
Has many other capabilities:
o
o
o
o
o
o


Database
3D Graphics
Plotting
GUI
J Web Servers
And Language Interfaces
Concise code
Useful utilities






Disadvantages
Small amount of datatypes
Not readable
Confusing operators
Implicit parameters
No operator precedence
Operators are computed
right to left
Tacit/Point-free style – explicit arguments for functions are
not usually used
avg=: +/ % #

A function that takes an array, sums the items, and then
divides that by the number of items in the array
 No precedence, right-to-left (parentheses can still be used)
10 – 4 – 3 = 9


26 lowercase letters (a to z)
26 uppercase letters (A to Z)
0123456789
=<>_
+*-%
^$~|
.:,;
#!/\
[]{}
"`@&?
()
'






Word – Group of characters form the alphabet with
meaning
Sentence – Group of words that form a complete instruction
Verb – Word that expresses action (function/method)
Noun – Things that verbs are done to (parameters)
Number – Cannot begin with a period; can be expressed in
scientific notation using “e.” The underscore (_) is a
number, meaning infinity
Negative – begins with _ and not -. - is a verb instead. __
(double underscore) is also a number meaning negative
infinity.



Primitive – A Word defined by the system, usually uses a
graphic character; possibly modified by an adverb. They are
also expressed with one or more letters followed by a period
or colon (if. or i.).
Name – Word defined by a user. You may use either =. or =:
(v =. 23). You may also give verbs a name (plus=.+).
Adverb – Changes the effect a verb has. Some examples
are ., :, /. Specially / tells J to use the verb between all
terms of the argument.
Operator
Affect
1 Adverb
Effect
2 Adverbs
Effect
+
Addition
+/
Summation
+./
OR or GCD
*
Multiplicatio */
n
“pi product” *./
AND or LCM
<
Less than
<.
Minimum
<./
Array
minimum
>
Greater
than
>.
Maximum
>./
Array
Maximum


Many languages use a similar character set
However, most are not so dependent on mostly using
symbols for all operations.
o Most of the time, if a symbol is not associated with an operation, a
named function is used

Most system verbs in J are associated with graphical
symbols
Most associated with control structures
if. T do. B end.
if. T do. B else. B1 end.
if. T do. B elseif. T1 do. B1 elseif. T2 do. B2 end.
try. B catch. B1 end.
while. T do. B end.
whilst. T do. B end.
for. T do. B end.
for_i. T do. B end.
select. T
case. T0 do. B0
case. T1 do. B1
fcase.T2 do. B2
case. T3 do. B3
end.




1.
2.
Verbs are arguably the most important part of J
http://www.jsoftware.com/help/dictionary/contents.htm
Verbs come in two flavors:
Monad – only uses a right argument (-7=_7 or
%2=0.5)
Dyad uses both a left and right argument (5-3=2 or
6%3=2)

1.
2.


Two different verbs for assignment
=.
=:
The first is used to define local names
The second is used to define names in the global scope



1.
2.
3.


All code in J Is executed in a “locale”
A locale is a section of memory in the J system
Three special Locales
j – the default locale, always defined
base – whatever the current locale is
z – parent locale of all other locales
You may define the locale in which code should be executed
using
name_locale_
Many ways to make verbs
 You already saw one
 Let’s define a monad using multiple lines
verb1=: 3 : 0


What this means is that you want to define a monad (3) on
the subsequent lines (0). To show where a verb definition
ends, use a closing parenthesis, )
factorial =: 3 : 0
if. y > 0 do. y * factorial (y – 1)
else. 1 end.
)
ALTERNATIVELY use
factorial =: verb define
ALSO, YOU MAY USE single line
negate =: 3 : ‘-y’

For a dyad, use 4 instead of three.
minus =: verb define
-y
:
x-y
)
You separate the monad and the dyad using :.
The undefined names x and y correspond to
the nouns preceding and following the verb,
respectively


1.
2.
3.
4.
Every noun is an array
All
integers
There are:
up to 10
0-dimensional arrays called atoms (1)
1-dimensional arrays called lists (1 2 3 4 OR i. 10)
2-dimensional arrays called tables
Higher order arrays
Defined using $
2 5 $ 8
8 8 8 8 8
8 8 8 8 8
2 3 $ 7 8 9 10 11 12
7 8 9
10 11 12
i. 2 5
1 2 3 4 5
6 7 8 9 10
Much work has been done by J designers to make sure that
all verbs can be used with lists:
1 2 3 + 4 5 6
5 7 9
1 + 2 3 4
3 4 5






J is interpreted
Written in scripts
Written with extension .ijs
Execution time is based on how well you choose your verbs,
a single keystroke in a J sentence can summon billions of
calculations
No compile time.







Issues with complexity
Number of operations is staggering
About 170 different verbs, each one can be modified by
adverbs
Symbolic nature of most verbs (oftentimes not related to
operation at all) makes readability hard
Code can be writable, you can perform a lot of calculations
with relatively few instructions
Code has been worked on straight for 23 years, amount of
knowledge needed is staggering
Combine this with the lack of explicit parameters, means
that readability and writability are heavily affected


The number of entities is rather small
However, the number of operations that can be performed
on each is extreme




Syntax and semantics of the program are sound
However, verbs can be aliased
Some special words are only keywords that can be
overrode, like verb and define
Syntax allows for tacit programming






Code is very reliable and stable
J is interpreted, program verification is very difficult
For the most part, any error reports you get are unhelpful
Aliasing reduces reliability
Most operations have been defined on all entities in the
language, which does mean that exceptions are avoided
Code is not portable at all, J is very high-level and
abstracted
o No types, variables, or parameters
Feature
LaTeX2e
Scala
J
Paradigm
Markup
O-O/Functional
Function-level
Distribution
Open-Source
Open-Source
GPL3/Commercial
Suited For
Documents
Concurrency
Math, Analysis
Age
1985
2003
1990
Execution
Compiled
Compiled
Interpreted
Advantage
Typesetting
JVM and Packages
Complex Analysis
Disadvantage
Portability
Slow Compilation
Complexity