Re: Benefits of Dynamic Typing




Mathematica implements everything that you've listed from Lisp and adds
thousands of mathematical functions, typesetting, algebraic and symbolic
manipulation including simplification and integration, embedded graphics...

Rainer Joswig wrote:
> a) Syntax
>
> syntax for for representing data externally predefined
>
> #c(1 0) complex numbers
> (1 . ( 2 . 3)) binary trees
> #(1 2 3) vectors
> "hskajdhf" strings
> |kfjsahdf| symbols
> and lots more.

1+I
{1, {2, 3}}
{1, 2, 3}
"hskajdhf"
kfjsahdf

> code is represented as data using Lisp's built-in data-types
>
> (defun foo () 'bar)

foo[] := bar

> Additionally there are conventions for programs.
> Predicates end with -p,

Predicates end with Q:

In[1]:= PrimeQ[524287]
Out[2]= True

> b) Extensible Syntax
>
> Then there is a data reader which can be programmed. the reader
> reads from streams and returns lisp data. you can
> change readers and thus manipulate the surface syntax,
> even during reads.

Mathematica takes this further by allowing 2D typesetting of expressions.
One of the examples in the documentation demonstrates how the syntax can be
extended to render Feynman diagrams, for example.

> Then you have a printer which is extensible and can
> print Lisp data to streams. Data is either readable for the reader
> functions or non-readable for possibly human consumption.
> (write "readable") prints "readable"
> (princ "unreadable") prints unreadable

Mathematica adds printing as C or Fortran code, conventional mathematical
notation, prefix notation, its own notation, MathML, PostScript...

> c) Tool building
>
> READ reads data. EVAL evaluates data. PRINT writes DATA readably.
>
> (LOOP (PRINT (EVAL (READ)))) is the simplest type of toplevel loop.
>
> Lisp data functions can be used to generate code.
> (EVAL (LIST '+ 1 2))

In[2]:= ReleaseHold[Hold[1 + 2]]
Out[2]= 3

> Pretty printing formats Lisp data.

Pretty printing formats code and typesets recognised symbolic mathematics,
such as definite or indefinite integrals...

> Macros, compiler macros and others can transform code into other code.

This is the core of Mathematica.

> It is easy to edit Lisp text, since it is easy to write basic editing
> functions that work on the text as Lisp data.

Mathematica adds pattern matching to make manipulating code (and strings)
much easier.

The following rewrite rules differentiate variables, constants, sums,
products, quotients and powers:

In[3]:= deriv =
{d[x_, x_] :> 1,
d[_Symbol | _?NumericQ, _] :> 0,
d[Sin[f_], x_] :> Cos[f]*d[f, x],
d[Cos[f_], x_] :> -Sin[f]*d[f, x],
d[u_ + v__, x_] :> d[u, x] + d[Plus[v], x],
d[u_ v__, x_] :> u*d[Times[v], x] + (Times[v])*d[u, x],
d[u_ / v_, x_] :> (d[u, x]*v + d[v, x]*u)/v^2,
d[u_ ^ v__, x_] :>
u^Power[v]*(Power[v]*(d[u, x]/u) + d[Power[v], x]*Log[u])};

For example:

In[4]:= d[Sin[x]^(Cos[x]/x), x] //. deriv

Out[4]= Sin[x]^(Cos[x]/x)*((Cos[x]*Cot[x])/x + Log[Sin[x]]*(-(Cos[x]/x^2) -
Sin[x]/x))

> And parentheses are quite handy, since you have a visual
> marker for the expression itself on the screen.
> If you have to expressions:
>
> Sin i
>
> and
>
> (sin i)

You can add superfluous parentheses in most languages.

> In Lisp editors you can select sin by click on sin,
> i by clicking on i and the whole expression by clicking
> on either ( or ). Where do you click in an Haskell editor
> on Sin i to select the whole expression? What
> is a simple model for that?

In Mathematica, you'd select a typeset subexpression graphically. In OCaml,
you can get the inferred type of the current subexpression from the editor.

> These are
> some of the reasons why programmers find it useful and
> haven't successfully replaced the Lisp syntax with something
> else.

That is a triumph of hope over reality. The fact is, people have voted with
their feet by using other languages instead of Lisp. As the vast majority
of programmers do not use Lisp, you can count that as them "replacing
Lisp's syntax".

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.



Relevant Pages

  • Re: why do you choose LISP?
    ... i like lisp primarily bceause it is a functional lang. ... It is also during the early 1990s, i started to learn programing on my ... during these years i bought Mathematica (because i heard it's the ... I do not have any concrete idea what IS a language specification ...
    (comp.lang.lisp)
  • Re: merits of Lisp vs Python
    ... To me superfluous mean more regarding a predefined syntax and grammar. ... Lisp has superfluous parentheses when compared with OCaml/F# (are _not_ ... metaprogramming" yet Mathematica, ... Precisely the large criticism to symbolic math in MathML becomes ...
    (comp.lang.lisp)
  • Re: Lisp and Scheme with fewer parentheses / Mathematica??
    ... Any dummy, at our level, knew that Mathematica and lisp have different ... programer, even with say 10 years of programing experience, chances ... functional language and one of the oldest language) ...
    (comp.lang.lisp)
  • Re: Benefits of Dynamic Typing
    ... >> syntax for for representing data externally predefined ... >> reads from streams and returns lisp data. ... > Mathematica takes this further by allowing 2D typesetting of expressions. ...
    (comp.lang.functional)
  • Re: Lisp syntax vs. Mathematica syntax
    ... Let's trying writing a Lisp macro equivalent to Mathematica's Apply. ... In Mathematica, ... That's not what Lisp folks mean when they ... > What you are doing is not the same as other programming environments. ...
    (comp.lang.lisp)