[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Embedding HTML in Lisp.
Embedding HTML in Lisp.
Sun, 22 Jun 2008 22:53:21 +0200 (CEST)
Bonjour à tous.
I have to prepare an exam and I needed a good access to a French
dictionary. I considered that the best choice is http://www.cnrtl.fr/,
a database of the "Centre national de la recherche scientifique". This
dictionary is provided in html format.
So I thought how to get access to a html page. I tried to define html.
I define html as « html is a programming language like any other
programming language ».
Being a language, it can be transformed in lisp and evaluated using
the lisp evaluator.
Apart a few special tags (like BR, HR, <tag expr />, etc), the grammar
of the html is identical ( via an isomorphism ) to the lisp grammar:
<tag expr> text </tag> <----> (tag (expr) text)
So I transformed html in lisp via this iso.
(table (tr (td "x") (td "y"))
(tr (td "a") (td "b")))
and this form will be evaluated after the rules of the emacs lisp
Now I have to give the tags' definitions.
I observe that the lisp evaluator will first call the functions `td'
with a string as parameter, and then will call the functions `tr' with
the output of `td' as parameter, and finally will call `table' with a
list of elements that are the ouputs from `tr' functions as parameter.
Hence html is a subset of lisp, in which the functions are the symbols
like table, div, input, center, I, B, et ctera.
So I did so:
1. I downloaded the page from CNRTL.
2. I filtered it to extract just the definition, and cut the unuseful
informations. (using a signal->filter->accumulate library (not
included in the example I send here))
3. I transformed the result using the grammar isomorphism
4. I evaluated the resulted lisp structure.
The result of the 4th step is the context of the filtered html
page (just the definition).
So that was my implementation of html.
Now if I look in the dictionary, to see the definition of html:
« L'Hypertext Markup Language, généralement abrégé HTML, est le
**format de données** conçu pour représenter les pages web. Il permet
notamment d'implanter de l'hypertexte dans le contenu des pages et
repose sur un **langage de balisage**, d’où son nom »
More, look at the definition of «langage de balisage»:
« L'inclusion de balises permet de transférer à la fois la structure
du document et son contenu. Cette structure est compréhensible par un
**programme informatique** , ce qui autorise un affichage personnalisé
selon des règles pré-établies »
So, in the dictionaries, html is considered as a data structure, that
can be rendered by a program. Maybe the lisp evaluator is that program
in my code... and the data structure is a lisp structure obtained by
When I first read this definition, it sounded me very strange.
I redefined html as a programming language «en tant que tel», as any
other programming language, neither as a «langage de balisage», nor as
«format de données».
In this new implementation of html the emacs lisp user will have all
the liberty to redefine the rendering of every html (= lisp) symbol as
one wishes. For example, if the user does not like the default
implementation of the tag `table', he will know that the tag `table'
is a lisp function that receives as parameter a list that contains
many list (rows), and every such list contains strings that are the
information of columns (depending of the implementation of TD and
TR). The function must return a string that is the image of the
table. More than that, one could attach to this tag everything
semantically, like a cond form in lisp, or progn. But in this case the
html standard would not be accomplished. In lisp a procedure must
always return an object (Lisp_Object) that can be of a few types. In
html we return an object that must be a string or a list, depending on
the html function (id est: we chop, like Edward Scissorhands, the
lisp evaluator and we obtain so a html evaluator).
When a table is inside another table (or any object inside another
object), the inner table will be evaluated first, then the outside
table. Maybe the outside object (function) will not like the
dimensions of the returned image of the inner object, and want to
rescale it. To solve this, during parsing one can add the quoted text
of every procedure after its definition, for example:
(table (tr (td "x") '(td "x") (td "y") '(td "y"))
'(tr (td "x") '(td "x") (td "y") '(td "y"))
(table (tr (td "a") '(td "a") (td "b") '(td "b"))
(tr (td "x") '(td "x") (td "b") '(td "b")))
'(table (tr (td "a") '(td "a") (td "b") '(td "b"))
(tr (td "x") '(td "x") (td "b") '(td "b"))))
and, in case the table "x y" will be able to rescale the inner table
"a b". This has the disavantage that the lisp code grows exponentially
with the html tree's deep. Another solution is to insert the
percentage of the current object during the transformation
html->lisp. For example:
(table (tr (td 50 "x") (td 50 "y"))
(tr (td 40 "a") (td 60 "b")))
When the lisp evaluator will call every function, it will know exactly
how huch the width of that element must me.
There are many possibilities to solve this problem.
The transformation of structures from html to lisp in html->lisp is
very inefficient in my implementation (it's just for test) and have to
be embedded in C (with DEFUN) for a good speed.
For the rest, I will write in the near future for myself a few more
filters for a few French newspapers that I read dayly, and I will add
some more definitions like <table, <a href= , <img src= , <hr>,
etc. But I will not define all the tags of the html language; I will
define just that ones that I need for these pages.
The current definitions of div, span, etc, are adapted for the CNRTL
dictionnary. That was just what I needed here. One can test it using
the call (cnrtl-get 'french-word).
I believe that the ideas from this implementation of html (cnrtl), can
be used in future to implement a complete web browser embedded in
emacs lisp, more customizable than any other browser of emacs (in fact
emacs does not have an incorporated web browser).
Html is lisp.
Finally, I wish to dedicate this implementation of html as a
programming language to Julie B. White from San Diego with all the
gratitude for her encouragements and for a beautiful friendship.
Alin C. Soare
PS: I promised 1 year ago that I would send the indentation of
the lisp code in O(n) time complexity, and I will send it, I hope
soon, because I have much to work and I do not have time at this
instant to check it out before.
En quelques secondes, créez-vous une autre adresse mail ! http://mail.voila.fr
|[Prev in Thread]
||[Next in Thread]|
- Embedding HTML in Lisp.,
A Soare <=