[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: common lisp vs elisp.
From: |
Jean Louis |
Subject: |
Re: common lisp vs elisp. |
Date: |
Sun, 20 Jun 2021 10:16:32 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Joost Kremers <joostkremers@fastmail.fm> [2021-06-20 09:46]:
> Second, IELM interacts with your Emacs session. If you set a variable or
> define
> a function in it, the variable or function is available throughout Emacs.
> SLIME
> interacts with a Common Lisp subprocess and whatever you do there has no
> effect
> on Emacs. So you can't define a function in SLIME and then call it from
> somewhere else in Emacs, nor can that function access Emacs' state.
Though it is possible to emulated or get some limited functionality by
calling external Lisp or other languages from Emacs Lisp:
(defun clisp-number-to-words (n &optional trim)
"Returns the cardinal English number representation, for example if N is 4,
it would return \"four\""
(clisp (format "(format t \"~R\" %d)" n) trim))
Number of our ancestors in 50 generations (left to thinking):
(clisp-number-to-words (expt 2 50)) ⇒ "one quadrillion, one hundred and
twenty-five trillion, eight hundred and ninety-nine billion, nine hundred and
six million, eight hundred and forty-two thousand, six hundred and twenty-four
"
Or evaluating string with Perl programming language:
(defun perl (string)
(if (rcd-which "perl")
(if string
(rcd-command-output-from-input "perl" string)
"")
(rcd-warning-message "RCD ERROR: `perl' not found in $PATH")))
(perl "print 2 + 2") ⇒ "4"
(perl "print 2 + 2; print \"\n\"; print 10") ⇒ "4
10"
Or evaluating variable DATA as string, sending it to external Common
Lisp implementation CLISP and getting result from it:
(defun clisp (data &optional trim)
(if (rcd-which "clisp")
(let* ((value (if data
(rcd-command-output-from-input "clisp" data "-q"
"-norc" "-")
""))
(value (if trim (string-trim value) value)))
value)
(rcd-warning-message "RCD ERROR: `clisp' not found in $PATH")))
(clisp "(princ (+ 2 2))") ⇒ "4
"
(clisp "(format t \"~R\" (expt 2 50))") ⇒ "one quadrillion, one
hundred and twenty-five trillion, eight hundred and ninety-nine
billion, nine hundred and six million, eight hundred and forty-two
thousand, six hundred and twenty-four
""
or with the macro that allows some easier Lisp writing and illusion of
direct evaluation:
(defmacro clisp-macro (&rest body)
(declare (indent 1) (debug t))
`(clisp (prin1-to-string (quote ,@body)) t))
(clisp-macro (format t "~R" (expt 2 50))) ⇒ "one quadrillion, one hundred and
twenty-five trillion, eight hundred and ninety-nine billion, nine hundred and
six million, eight hundred and forty-two thousand, six hundred and twenty-four"
Though I would like that this macro becomes able to evaluate any
number of forms. If somebody has a solutin, let me know.
(clisp-macro (princ "First form")) ⇒ "First form"
(clisp-macro (princ "First form") (princ "Second form")) -- not working
Of course this way it would work:
(clisp-macro (progn
(princ "First form") (princ " Second form"))) ⇒ "First form
Second form"
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
- Re: common lisp vs elisp., (continued)
- Re: common lisp vs elisp., Stefan Monnier, 2021/06/20
- Re: common lisp vs elisp., Hongyi Zhao, 2021/06/20
- Re: common lisp vs elisp., Emanuel Berg, 2021/06/20
- Re: common lisp vs elisp., Joost Kremers, 2021/06/20
- Re: common lisp vs elisp., Hongyi Zhao, 2021/06/20
- Re: common lisp vs elisp., Jean Louis, 2021/06/20
- Re: common lisp vs elisp., Emanuel Berg, 2021/06/20
- Re: common lisp vs elisp., Andreas Eder, 2021/06/27
- Re: common lisp vs elisp., Emanuel Berg, 2021/06/27
- Re: common lisp vs elisp., Jean Louis, 2021/06/28
- Re: common lisp vs elisp.,
Jean Louis <=
- Re: common lisp vs elisp., Jean Louis, 2021/06/20