Bigos <
ruby....@googlemail.com> writes:
> On 03/12/12 19:16, Pascal J. Bourguignon wrote:
>> Bigos <
ruby....@googlemail.com> writes:
>>
>>> I did some calculations and had a shock. if all files in my /usr/bin
>>> were lisp images it would be over 20GB.
>>
>> So little? I could load them all in my RAM!
>>
>>
>
> :-P I'd love to see the specification of your machine.
>
> I know I sound daft when I mention the 20GB, but it would be lovely
> and cool if you could compile a lisp program to a small executable.
People keep forgetting that we have something very few language
ecosystem has: we have tens of implementations!
Lisp500 is a subset of Common Lisp. If you want to deliver small
programs, you can develop with SBCL programs that will run on lisp500.
Or if you need a full CL implementation, you can use ecl, and like any
other modern unix program, use shared libraries including
/usr/lib/libecl.so.
> [pjb@kuiper :0 ecldemo]$ ./ecldemo
> (* 3 4)
12
> (list-all-packages)
(#<"FFI" package> #<"GRAY" package> #<"MP" package> #<"CLOS" package>
#<"SI" package> #<"KEYWORD" package> #<"COMMON-LISP-USER" package>
#<"COMMON-LISP" package>)
> (si:exit)
[pjb@kuiper :0 ecldemo]$ ls -l ecldemo
-rwxr-xr-x 1 pjb pjb 12715 Dec 4 00:59 ecldemo*
[pjb@kuiper :0 ecldemo]$ strip ecldemo
[pjb@kuiper :0 ecldemo]$ ls -l ecldemo
-rwxr-xr-x 1 pjb pjb 10376 Dec 4 01:00 ecldemo*
[pjb@kuiper :0 ecldemo]$
----(ecldemo.c)---------------------------------------------------------
/* -*- mode:c; coding:us-ascii */
/* Example of a C program embedding ECL with callbacks to C functions. */
/* Compiled via: gcc ecldemo.c -lecl */
#include <stdio.h>
#include <stdlib.h>
#include "ecl/ecl.h"
#define DEFUN(name,fun,args) \
cl_def_c_function(c_string_to_object(name), \
(cl_objectfn_fixed)fun, \
args)
cl_object foo() {
return ecl_make_integer(42);
}
cl_object bar(cl_object a, cl_object b) {
int aval = fix(a);
int bval = fix(b);
return ecl_make_integer(aval + bval);
}
/*
Assumes the string is a valid call.
*/
cl_object ecl_call(char *call) {
return cl_safe_eval(c_string_to_object(call), Cnil, Cnil);
}
void init() {
cl_boot(1, (char **)&"");
atexit(cl_shutdown);
/*
Uncomment these lines to place your code into a separate package,
They may then be called like (my-code:foo)
*/
// ecl_call("(make-package :my-code)");
// ecl_call("(in-package my-code)");
DEFUN("foo", foo, 0);
DEFUN("bar", bar, 2);
// ecl_call("(export foo)");
// ecl_call("(export bar)");
// ecl_call("(in-package common-lisp-user)");
}
int main() {
init();
cl_object exit_obj = c_string_to_object(":EXIT");
cl_object result = Cnil;
while (cl_equal(exit_obj, result) == Cnil) {
printf("\n> ");
fflush(stdout);
cl_object form = ecl_call("(read)");
result = cl_safe_eval(form, Cnil, Cnil);
cl_print(1, result);
}
putchar('\n');
return 0;
}
------------------------------------------------------------------------
> At the moment CL is like a huge and powerful truck that lacks of some
> flexibility of a small car.
No, you are entirely wrong.
CL is a shop with bicycles, sedans, trucks, camions, trains, transport
airplanes, fighter jets, rockets, and UFOs.
You get to choose which one you use.
> It might be the most powerful in the world
> but most people either don't needs it's power, or don't know it's
> available.
Yes, people may need more information.
> Perhaps it's not possible with CL but I wonder if here was a project
> where somebody would try to write a Lisp compiler (not CL) that would
> create small executables.
Smaller than ten thousand three hundred and seventy six bytes for a
64-bit hello world that contains a whole CL implementation?
> I wonder how much would have to be stripped off contemporary Lisp
> specifications to make such compilation possible.
Absolutely nothing.