unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: A Soare <alinsoar@voila.fr>
To: emacs-devel@gnu.org
Subject: Embedding HTML in Lisp.
Date: Sun, 22 Jun 2008 22:53:21 +0200 (CEST)	[thread overview]
Message-ID: <25112253.8571481214168001329.JavaMail.www@wwinf4622> (raw)



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>
  <td>y</td>
 </tr>
 <tr>
  <td>a</td>
  <td>b</td>
 </tr>
</table>

will become

(table (tr (td "x") (td "y"))
       (tr (td "a") (td "b")))

and this form will be evaluated after the rules of the emacs lisp
evaluator.

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:

http://fr.wikipedia.org/wiki/Hypertext_Markup_Language

« 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»:

http://fr.wikipedia.org/wiki/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
html->lisp...

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"))
       (tr
         (td
           (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"))))
         (td "o")))

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






             reply	other threads:[~2008-06-22 20:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-22 20:53 A Soare [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-06-22 20:56 Embedding Html in Lisp A Soare
2008-06-22 21:29 ` Drew Adams
2008-06-23  8:33 ` Thien-Thi Nguyen
2008-06-22 22:27 A Soare
2008-06-23 11:49 A Soare
2008-06-23 12:23 A Soare
2008-06-23 13:21 A Soare
2008-06-23 13:51 ` tomas
2008-06-23 16:56 ` Thomas Lord
2008-06-23 17:04 ` Thien-Thi Nguyen
2008-06-23 20:07 ` Stephen J. Turnbull
2008-06-23 14:08 A Soare
2008-06-24 13:36 ` T. V. Raman
2008-06-24 14:41   ` joakim
2008-06-23 21:38 A Soare
2008-06-24  0:32 A Soare
2008-06-24  0:51 ` Stefan Monnier
2008-06-24  1:34 ` Thomas Lord
2008-06-24  3:09 A Soare
2008-06-24 10:19 ` Thien-Thi Nguyen
2008-07-01 19:05 A Soare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25112253.8571481214168001329.JavaMail.www@wwinf4622 \
    --to=alinsoar@voila.fr \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).