all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using lisp code in emacs inside a C program
@ 2012-10-25  3:13 gnuist007
  2012-10-25 15:17 ` Sohail Somani
       [not found] ` <mailman.11690.1351178239.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: gnuist007 @ 2012-10-25  3:13 UTC (permalink / raw)
  To: help-gnu-emacs

Dear Lispers,

I wrote a humble file parsing/structure-searching program in emacs
lisp. Essentially a collection of elisp functions called by a main
function. I may need the function to grow and to maintain it. I think
its easiest in the elisp in which I started the project.

I want to convert it to an executable or a form that runs without the
need for emacs. Hence, I want to be able to take whatever lisp
interpreter code from emacs and link to it or incorporate inside my C
executable.

The main functions from the emacs that my program uses are essentially
navigation and
regexp and non-greedy wildcards, ie "*?" and multiline searches.

I dont know if any of the standard regexp library in C or C++ supports
such extended regexp. Even sed does not support it and I avoid perl.
The only other option would be javascript but I want to stay loyal to
lisp if you are able to give me enough ideas on this matter. I would
be even willing to put together a small lisp interpreter in C with
your help and then bootstrap it using Lisp etc and then dump the
binary image after it has computed rest of the higher lisp definitions
in primitive lisp and link it to my code in elisp.

There is really no gui facility that it uses. I am sure many of you
have done this kind of thing as I keep on hearing but have to go
through all the steps myself.

Gnuist





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-25  3:13 Using lisp code in emacs inside a C program gnuist007
@ 2012-10-25 15:17 ` Sohail Somani
       [not found] ` <mailman.11690.1351178239.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Sohail Somani @ 2012-10-25 15:17 UTC (permalink / raw)
  To: help-gnu-emacs

On 24/10/2012 11:13 PM, gnuist007@hotmail.com wrote:
> I would
> be even willing to put together a small lisp interpreter in C with
> your help and then bootstrap it using Lisp etc and then dump the
> binary image after it has computed rest of the higher lisp definitions
> in primitive lisp and link it to my code in elisp.

Try http://ecls.sourceforge.net/ which is an embeddable Common Lisp. 
It's pretty handy and good at what it says it does.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
       [not found] ` <mailman.11690.1351178239.855.help-gnu-emacs@gnu.org>
@ 2012-10-25 15:46   ` gnuist007
  2012-10-28 17:42     ` Pascal J. Bourguignon
  2012-10-26  5:08   ` Rivka Miller
  1 sibling, 1 reply; 9+ messages in thread
From: gnuist007 @ 2012-10-25 15:46 UTC (permalink / raw)
  To: help-gnu-emacs

On Oct 25, 8:17 am, Sohail Somani <soh...@taggedtype.net> wrote:
> On 24/10/2012 11:13 PM, gnuist...@hotmail.com wrote:
>
> > I would
> > be even willing to put together a small lisp interpreter in C with
> > your help and then bootstrap it using Lisp etc and then dump the
> > binary image after it has computed rest of the higher lisp definitions
> > in primitive lisp and link it to my code in elisp.
>
> Try http://ecls.sourceforge.net/ which is an embeddable Common Lisp.
> It's pretty handy and good at what it says it does.

Thanks for the link and the terminology of embedded.
I want to know more about the authors, but I could not find any clue.
Also, if anyone has used it and its compatibility with the emacs. I
found a file called emacs.el in it and I am pasting it here so people
can guess what it does and offer comments. What might be the structure
of the program like? Certainly, would be interesting to read the
source and if anyone has done so and if it is commented well or
obfuscated? Here the personality of the authors comes in handy to know
their motivations for the project.

Maybe, I also try to find the core file where he has written the
interpreter in C. Can anyone point it out and the general structure of
the program?

emacs.el    167 lines (153 with data), 4.3 kB

(require 'cl)
(defvar ecl-search-string "")
(defun query-replace-ecl-doc (from-string to-string &optional
delimited start end)
(interactive (query-replace-read-args "Query replace" nil))
(let ((remaining (member (buffer-file-name (current-buffer)) ecl-doc-
files)))
(dolist (i (or remaining ecl-doc-files))
(let ((b (find-buffer-visiting i)))
(unless (equal b (current-buffer))
(switch-to-buffer b)
(beginning-of-buffer)))
(perform-replace from-string to-string t nil delimited nil nil
start end))))
(defun query-replace-regexp-ecl-doc (from-string to-string &optional
delimited start end)
(interactive (query-replace-read-args "Query replace" nil))
(let ((remaining (member (buffer-file-name (current-buffer)) ecl-doc-
files)))
(dolist (i (or remaining ecl-doc-files))
(let ((b (find-buffer-visiting i)))
(unless (equal b (current-buffer))
(switch-to-buffer b)
(beginning-of-buffer)))
(query-replace-regexp from-string to-string delimited start end))))
(defun search-ecl-doc (string)
(interactive "sString: ")
(setq ecl-search-string string)
(let ((remaining (member (buffer-file-name (current-buffer)) ecl-doc-
files)))
(dolist (i (or remaining ecl-doc-files))
(let ((b (find-buffer-visiting i)))
(unless (equal b (current-buffer))
(print b)
(switch-to-buffer b)
(beginning-of-buffer)))
(print '*)
(setq case-fold-search t)
(if (search-forward string nil t)
(return)))))
(defun search-next-ecl-doc ()
(interactive)
(search-ecl-doc ecl-search-string))
(defun back-to-emacs ()
(interactive)
(switch-to-buffer "emacs.el"))
(defun next-ecl-doc ()
(interactive)
(let ((remaining (member (buffer-file-name (current-buffer)) ecl-doc-
files)))
(when (cdr remaining)
(switch-to-buffer (find-buffer-visiting (cadr remaining))))))
(global-set-key [?\M-p ?\C-i] 'back-to-emacs)
(global-set-key [?\M-p ?\C-s] 'search-ecl-doc )
(global-set-key [?\M-p ?\C-n] 'search-next-ecl-doc )
(global-set-key [?\M-p ?\C-m] 'next-ecl-doc )
(global-set-key [?\M-p ?\C-p] 'ecl-load-symbols)
(setq auto-mode-alist (acons "\\.d\\'" 'c-mode auto-mode-alist))
(setq ecl-doc-files
(mapcar (lambda (x)
;(set-buffer "emacs.el")
(concat (subseq (buffer-file-name (current-buffer)) 0 -8) x))
'(
"asdf.xmlf"
"bibliography.xmlf"
"clos.xmlf"
"compiler.xmlf"
"copyright.xmlf"
"declarations.xmlf"
"discarded.xml"
"discarded.xmlf"
"ecl.xml"
"ecldev.xmlf"
"embed.xmlf"
"ffi.xmlf"
"gc.xmlf"
"internals.xmlf"
"interpreter.xmlf"
"intro.xmlf"
"io.xmlf"
"macros.xmlf"
"memory.xmlf"
"mop.xmlf"
"mp.xmlf"
"os.xmlf"
"pde.xmlf"
"preface.xmlf"
"ref_c_arrays.xml"
"ref_c_characters.xml"
"ref_c_conditions.xml"
"ref_c_conses.xml"
"ref_c_data_flow.xml"
"ref_c_environment.xml"
"ref_c_evaluation.xml"
"ref_c_filenames.xml"
"ref_c_files.xml"
"ref_c_hash_tables.xml"
"ref_c_numbers.xml"
"ref_c_objects.xml"
"ref_c_packages.xml"
"ref_c_printer.xml"
"ref_c_reader.xml"
"ref_c_sequences.xml"
"ref_c_streams.xml"
"ref_c_strings.xml"
"ref_c_structures.xml"
"ref_c_symbols.xml"
"ref_c_system_construction.xml"
"ref_c_types_and_classes.xml"
"ref_embed.xmlf"
"ref_memory.xmlf"
"ref_mp.xmlf"
"ref_os.xmlf"
"ref_signals.xmlf"
"schemas.xml"
"signals.xmlf"
"uffi/ref_aggregate.xml"
"uffi/ref_declare.xml"
"uffi/ref_func_libr.xml"
"uffi/ref_object.xml"
"uffi/ref_primitive.xml"
"uffi/ref_string.xml"
"uffi/schemas.xml"
"ansi_arrays.xml"
"ansi_characters.xml"
"ansi_conses.xml"
"ansi_data_flow.xml"
"ansi_environment.xml"
"ansi_evaluation.xml"
"ansi_filenames.xml"
"ansi_files.xml"
"ansi_hash_tables.xml"
"ansi_numbers.xml"
"ansi_objects.xml"
"ansi_overview.xml"
"ansi_packages.xml"
"ansi_printer.xml"
"ansi_reader.xml"
"ansi_sequences.xml"
"ansi_streams.xml"
"ansi_strings.xml"
"ansi_structures.xml"
"ansi_symbols.xml"
"ansi_system_construction.xml"
"ansi_types.xml"
)))
(mapcar 'find-file ecl-doc-files)
(defun ecl-doc-revert ()
(interactive)
(mapcar '(lambda (x) (let ((a (find-buffer-visiting x)))
(and a (switch-to-buffer a)
(revert-buffer t t))))
ecl-doc-files))
(defun ecl-doc-save ()
(interactive)
(mapcar '(lambda (x) (let ((a (find-buffer-visiting x)))
(and a (switch-to-buffer a)
(save-buffer 0))))
ecl-doc-files))



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
       [not found] ` <mailman.11690.1351178239.855.help-gnu-emacs@gnu.org>
  2012-10-25 15:46   ` gnuist007
@ 2012-10-26  5:08   ` Rivka Miller
  2012-10-26  5:59     ` William Gardella
  1 sibling, 1 reply; 9+ messages in thread
From: Rivka Miller @ 2012-10-26  5:08 UTC (permalink / raw)
  To: help-gnu-emacs

On Oct 25, 8:17 am, Sohail Somani <soh...@taggedtype.net> wrote:
> On 24/10/2012 11:13 PM, gnuist...@hotmail.com wrote:
>
> > I would
> > be even willing to put together a small lisp interpreter in C with
> > your help and then bootstrap it using Lisp etc and then dump the
> > binary image after it has computed rest of the higher lisp definitions
> > in primitive lisp and link it to my code in elisp.
>
> Tryhttp://ecls.sourceforge.net/which is an embeddable Common Lisp.
> It's pretty handy and good at what it says it does.

\begin{quotation}
ECL (ECL for short) uses standard C calling conventions for Lisp
compiled functions, which allows C programs to easily call Lisp
functions and vice versa. No foreign function interface is required:
data can be exchanged between C and Lisp with no need for conversion.
\end{quotation}

How did ECL achieve this?

R


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-26  5:08   ` Rivka Miller
@ 2012-10-26  5:59     ` William Gardella
  2012-10-26 17:24       ` gnuist007
  0 siblings, 1 reply; 9+ messages in thread
From: William Gardella @ 2012-10-26  5:59 UTC (permalink / raw)
  To: help-gnu-emacs

Rivka Miller <rivkaumiller@gmail.com> writes:
> \begin{quotation}
> ECL (ECL for short) uses standard C calling conventions for Lisp
> compiled functions, which allows C programs to easily call Lisp
> functions and vice versa. No foreign function interface is required:
> data can be exchanged between C and Lisp with no need for conversion.
> \end{quotation}
>
> How did ECL achieve this?
>
> R

Not to oversimplify too much, but a compiled ECL function *is* a C
function.  The Debian description of the package lists among its
features:

> ECL stands for Embeddable Common-Lisp. The ECL project is an effort to
> modernize Giuseppe Attardi's ECL environment to produce an implementation of
> the Common-Lisp language which complies to the ANSI X3J13 definition of the
> language. 

> The current ECL implementation features: 
> * A bytecodes compiler and interpreter. 
> * A translator to C. 
> ...

So it's like similar initiatives for Pascal, FORTRAN, etc.--the end
result is a C program that you can poke at with tools designed to work
with C (binutils, gdb, etc.) and which can communicate natively with C
functions.  I've not used it and have heard mixed reviews (mostly on
#emacs) about its performance relative to other compiled CL
implementations.  But if what you need is Lisp inside C, it seems this
is your bet--it can even be used to make C shared libraries, it looks
like.

Chicken, being an R5RS-to-C compiler, has similar aspirations for the
world of Scheme.

Best,
WGG

-- 
I use grml (http://grml.org/)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-26  5:59     ` William Gardella
@ 2012-10-26 17:24       ` gnuist007
  2012-10-26 21:03         ` Aurélien Aptel
  2012-10-27 17:01         ` William Gardella
  0 siblings, 2 replies; 9+ messages in thread
From: gnuist007 @ 2012-10-26 17:24 UTC (permalink / raw)
  To: help-gnu-emacs

On Oct 25, 11:00 pm, William Gardella <gardell...@gmail.com> wrote:
> Rivka Miller <rivkaumil...@gmail.com> writes:
> > \begin{quotation}
> > ECL (ECL for short) uses standard C calling conventions for Lisp
> > compiled functions, which allows C programs to easily call Lisp
> > functions and vice versa. No foreign function interface is required:
> > data can be exchanged between C and Lisp with no need for conversion.
> > \end{quotation}
>
> > How did ECL achieve this?
>
> > R
>
> Not to oversimplify too much, but a compiled ECL function *is* a C
> function.  The Debian description of the package lists among its
> features:
>
> > ECL stands for Embeddable Common-Lisp. The ECL project is an effort to
> > modernize Giuseppe Attardi's ECL environment to produce an implementation of
> > the Common-Lisp language which complies to the ANSI X3J13 definition of the
> > language.
> > The current ECL implementation features:
> > * A bytecodes compiler and interpreter.
> > * A translator to C.
> > ...
>
> So it's like similar initiatives for Pascal, FORTRAN, etc.--the end
> result is a C program that you can poke at with tools designed to work
> with C (binutils, gdb, etc.) and which can communicate natively with C
> functions.  I've not used it and have heard mixed reviews (mostly on
> #emacs) about its performance relative to other compiled CL
> implementations.  But if what you need is Lisp inside C, it seems this
> is your bet--it can even be used to make C shared libraries, it looks
> like.
>
> Chicken, being an R5RS-to-C compiler, has similar aspirations for the
> world of Scheme.
>

You didnt answer her question on the computer science of translation,
code flow graphing, or any useful aspect than advertising your Chicken
and she posted only on this newsgroup, while I wanted it to be in the
related newsgroups. Maybe someone can give the pertinent referenecs to
key useful papers.

G


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-26 17:24       ` gnuist007
@ 2012-10-26 21:03         ` Aurélien Aptel
  2012-10-27 17:01         ` William Gardella
  1 sibling, 0 replies; 9+ messages in thread
From: Aurélien Aptel @ 2012-10-26 21:03 UTC (permalink / raw)
  To: gnuist007; +Cc: help-gnu-emacs

On Fri, Oct 26, 2012 at 7:24 PM,  <gnuist007@hotmail.com> wrote:
> You didnt answer her question on the computer science of translation,
> code flow graphing, or any useful aspect than advertising your Chicken
> and she posted only on this newsgroup, while I wanted it to be in the
> related newsgroups. Maybe someone can give the pertinent referenecs to
> key useful papers.

He simply replied with something relevant which I personally found
interesting. This is a public mailing list, you are not forced to
strictly reply to questions.
I have to say I chuckled at "advertising your Chicken" :)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-26 17:24       ` gnuist007
  2012-10-26 21:03         ` Aurélien Aptel
@ 2012-10-27 17:01         ` William Gardella
  1 sibling, 0 replies; 9+ messages in thread
From: William Gardella @ 2012-10-27 17:01 UTC (permalink / raw)
  To: help-gnu-emacs

gnuist007@hotmail.com writes:
> You didnt answer her question on the computer science of translation,
> code flow graphing, or any useful aspect than advertising your Chicken
> and she posted only on this newsgroup, while I wanted it to be in the
> related newsgroups. Maybe someone can give the pertinent referenecs to
> key useful papers.
>
> G

I'm not a Chicken developer, nor an ECL developer, nor was I
"advertising" anything.  I simply mentioned Chicken as a somewhat
parallel C translation project for Scheme.

As for "pertinent references to key useful papers," that's outside my
competency.  Perhaps you could do the homework.

WGG

-- 
I use grml (http://grml.org/)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using lisp code in emacs inside a C program
  2012-10-25 15:46   ` gnuist007
@ 2012-10-28 17:42     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2012-10-28 17:42 UTC (permalink / raw)
  To: help-gnu-emacs

gnuist007@hotmail.com writes:

> On Oct 25, 8:17 am, Sohail Somani <soh...@taggedtype.net> wrote:
>> On 24/10/2012 11:13 PM, gnuist...@hotmail.com wrote:
>>
>> > I would
>> > be even willing to put together a small lisp interpreter in C with
>> > your help and then bootstrap it using Lisp etc and then dump the
>> > binary image after it has computed rest of the higher lisp definitions
>> > in primitive lisp and link it to my code in elisp.
>>
>> Try http://ecls.sourceforge.net/ which is an embeddable Common Lisp.
>> It's pretty handy and good at what it says it does.
>
> Thanks for the link and the terminology of embedded.
> I want to know more about the authors, but I could not find any clue.

The current maintainer is Juan Jose Garcia Ripoll.

http://lisp-univ-etc.blogspot.fr/2012/06/juan-jose-garcia-ripoll-is-physicist.html

http://ecls.sourceforge.net/
http://ecls.sourceforge.net/resources.html



> Also, if anyone has used it and its compatibility with the emacs. 

All CL implementation is compatible with emacs, in the sense that you
can use emacs to edit CL programs, and you can run it with M-x
inferior-lisp RET, or even for most of them (including ecl) with M-x
slime RET. 

> I  found a file called emacs.el in it and I am pasting it here so people
> can guess what it does and offer comments. What might be the structure
> of the program like? Certainly, would be interesting to read the
> source and if anyone has done so and if it is commented well or
> obfuscated? 

Almost all projects written by programmers using emacs will contain some
emacs lisp file containing some utility emacs commands the authors use
to edit the project files.  


> Here the personality of the authors comes in handy to know
> their motivations for the project.
>
> Maybe, I also try to find the core file where he has written the
> interpreter in C. Can anyone point it out and the general structure of
> the program?

The ecl subdirectory named "src" contains:

[pjb@triton :0 src]$ ls
./           aclocal.m4   clx/             config.sub*   gc/          lsp/
../          bare.lsp.in  cmp/             configure*    gmp/         new-cmp/
CHANGELOG*   c/           compile.lsp.in*  configure.in  h/           util/
Makefile.in  clos/        config.guess*    doc/          install.sh*

I would say cmp/ and new-cmp/ contain compilers.
The c/ contains some C sources, including a file named "interpreter.d".


Concerning personalities, I would say yours doesn't bode well, given
that you didn't fetch the sources and see that yourself.  One wonders
about your motivations...  ;-)

-- 
__Pascal Bourguignon__
http://www.informatimago.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-10-28 17:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-25  3:13 Using lisp code in emacs inside a C program gnuist007
2012-10-25 15:17 ` Sohail Somani
     [not found] ` <mailman.11690.1351178239.855.help-gnu-emacs@gnu.org>
2012-10-25 15:46   ` gnuist007
2012-10-28 17:42     ` Pascal J. Bourguignon
2012-10-26  5:08   ` Rivka Miller
2012-10-26  5:59     ` William Gardella
2012-10-26 17:24       ` gnuist007
2012-10-26 21:03         ` Aurélien Aptel
2012-10-27 17:01         ` William Gardella

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.