Subject: AW: [clisp-list] Networking?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Feb 12 07:08:01 2004

Hi,

Michael Koehne wrote:
>  An FFI implementing simple (read-line and hiding the nastynesses of
>  IAC telnet signals would be nice. I therefore swiched to GCL where
>  (defentry is much easier than FFI.
This made me curious so I looked at defentry to see whether there was something new about FFI to learn.
http://www.scit.wlv.ac.uk/appdocs/gcl/gcl-si_16.html
I found nothing particularly attracting to me.

If you prefer defentry over FFI then you might wish to take a look at CLISP's module's documentation, esp. modprep.

My opinion is that defentry allows you to put some C code into a Lisp file. Modprep allows you to put C code into a mostly-C file, with special preprocessor macros like DEFUN to ease definining parameters.

Another approach might be to use FFI:C-LINES to add C code to the current module. Long ago, I thought about extending FFI:C-LINES to be able to add functions and variables that the module system would know about. That would be very similar to defentry. It's really just a matter of some more code in CLISP's foreign1.lisp, given some design choices. I wondered if this could be useful to anybody except me.

The list of parameter types supported by defentry is very poor:
>The list of allowed types is (object char int float double string)

There's some benefit (and also drawbacks) in mixing C and Lisp code a la defentry. Literate programming comes to mind, which mixes code and documentation, and variants like dotweb or dotnoweb, which, from a single source file, extract the shell, C Lisp, TeX, xyz. parts and puts these into separate files.

Yet even for small files, I prefer to have separate Lisp and C files, partly because in C, one usually needs a plethora of #include and #ifdef... #include (for portability), which I don't want to see in Lisp files.

All in all, we're talking here about ease of use or suitability for fast-forward aka. quick hacks, not about advanced or high-level features.

Given my Amiga background, where the goal was to interface to existing libraries, compiling and adding tiny C wrappers was deemed superfluous. Nowadays, I'd expect similar useage patters with FFI to dynamic link libraries on MS-Windows and UNIX: to use an existing libxyz.so/dll/dynlib, *I* wouldn't want to have to define some C glue code.
YMMV. In my article on extending CLISP, I believe I had listed some pros and cons on glue code.

Regards,
	Jorg Hohle.

---

From: Michael Koehne <[email-masked]>
Date: Thu Feb 12 09:38:09 2004

Moin Hoehle, Joerg-Cyril,

> something new about FFI to learn.

  well - I've tried to understand clisp .d files and FFI several times,
  but failed. My current GCL code is in a stage, that I already use
  a wrapper macro around defentry and stuff, as GCL has its problem
  with ELF and ECL has a slightly different defentry syntax. A step
  would be to extend this wrapper to build a clisp core from same
  source. CLISP has the smallest footprint and the fastest bytecode
  engine, for my kind of applications.
  
> Given my Amiga background

  i know this is totaly off topic, but do you know a clisp for KICK.ROM
  3.1, Kickstart version 40.63, Workbench version 34.28 ? The sourceforge
  only offers linux binaries - and I dont have a C compiler on the Amiga,
  nor the time to generate a GNU cross compiler on my Debian box.

  I'm just collecting them for UAE ;)

Bye Michael
-- 
  mailto:[email-masked]             UNA:+.? 'CED+2+:::Linux:2.4.22'UNZ+1'
  http://www.xml-edifact.org/           CETERUM CENSEO WINDOWS ESSE DELENDAM

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 12 10:26:05 2004

> * Michael Koehne <[email-masked]> [2004-02-12 18:35:52 +0100]:
>
> I've tried to understand clisp .d files and FFI several times,

what do you need to understand .d for?
Did you look at the modules facility?
<http://clisp.cons.org/impnotes/modules.html>
what are your problems with the FFI?
<http://clisp.cons.org/impnotes/dffi.html>
please be specific - otherwise we cannot help you!

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Profanity is the one language all programmers know best.

---

From: Michael Koehne <[email-masked]>
Date: Thu Feb 12 12:56:04 2004

Moin Sam Steingold,

> what do you need to understand .d for?

  much more time - I tried to understand what happens inside stream.d
  because 'socket-status did'nt work with 'read-line ( it never would
  as stdio never would work with select - as I realised later ) I
  therefore came up to use 'read-byte-sequence and convert-string-from-bytes
  instead ( thanks to your suggestion ) and avoided coding .d.

> please be specific - otherwise we cannot help you!

  I mainly need calling normal C libraries like X or OpenGL or
  lib[cm] directly. 

  a screen full of code would be enough as a starter, e.g. a small
  test of my gcl-elf-loader (oh well old GCL doesn'nt know ELF ;)
  looks like :

    (elf::use-lib 'libm "libm.so.6")
    (defCfun "double call_d1d(int prt, double rad)" 0
        "double (*callptr)(double); callptr=prt; return ( (*callptr)(rad) );" )
    (defentry call-d1d (int double) (double call_d1d))
    (defun dyn-sin (rad) (call-d1d (elf::use-sym 'libm '|sin|) rad))
    (defun dyn-cos (rad) (call-d1d (elf::use-sym 'libm '|cos|) rad))
    (defun dyn-tan (rad) (call-d1d (elf::use-sym 'libm '|tan|) rad))
    (defun dyn-asin (rad) (call-d1d (elf::use-sym 'libm '|asin|) rad))
    (defun dyn-acos (rad) (call-d1d (elf::use-sym 'libm '|acos|) rad))
    (defun dyn-atan (rad) (call-d1d (elf::use-sym 'libm '|atan|) rad))

  I could then (compile-file and (load this file, and I'm even able
  to do an (elf::save-system on it, producing a core that is able
  to dynamicaly link its libraries next time.

  It would be nice to come up with a wrapper macro, so that my X&OpenGL
  experiments work with both kinds of GNU Common Lisp. A simple clisp
  code calling some function out of external libraries - perhaps even
  some using strings would be a head start.

Bye Michael

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 12 13:26:07 2004

> * Michael Koehne <[email-masked]> [2004-02-12 21:53:38 +0100]:
>

see <modules/bindings/glibc/linux.lisp>

(def-call-out sin (:arguments (x double-float)) (:return-type double-float))

or

(def-call-out sin (:arguments (x double-float))
  (:library "/lib/libc.so")
  (:return-type double-float))

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Software is like sex: it's better when it's free.

---

From: Michael Koehne <[email-masked]>
Date: Thu Feb 12 14:34:08 2004

Moin Sam Steingold,

> (def-call-out sin (:arguments (x double-float)) (:return-type double-float))

  this could be used for calling functions defined by (c-inline 

>   (:return-type double-float))

  I tried this one and it gave :

Compiling file /bakunin/export/home/kraehe/lisp/mucl/elf-test.lsp ...
*** - Invalid option in
(FFI:DEF-CALL-OUT SIN (:ARGUMENTS (X DOUBLE-FLOAT)) (:LIBRARY "/lib/libm.so")
 (:RETURN-TYPE DOUBLE-FLOAT)): (:LIBRARY "/lib/libm.so")
1. Break [2]> *features*
(:CLOS :LOOP :COMPILER :CLISP :ANSI-CL :COMMON-LISP :LISP=CL :INTERPRETER
 :SOCKETS :GENERIC-STREAMS :LOGICAL-PATHNAMES :SCREEN :FFI :GETTEXT :UNICODE
 :BASE-CHAR=CHARACTER :PC386 :UNIX)
1. Break [2]> (quit)

  Do I need to re./configure --with-dynamic-modules or what whats going
  wrong here.

Bye Michael

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 12 15:41:17 2004

> * Michael Koehne <[email-masked]> [2004-02-12 23:32:22 +0100]:
>

you have an old version.
note that you will need (:name "sin") also.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
We're too busy mopping the floor to turn off the faucet.

---

From: Michael Koehne <[email-masked]>
Date: Thu Feb 12 18:09:00 2004

Moin Sam Steingold,

> you have an old version.

  i tried current CVS and run into the following problems :

  On Debian/Sarge only one test failed, ...

  Form: (LET ((F "foo.bar") FWD1) (UNWIND-PROTECT (PROGN (WITH-OPEN-FILE
  (S F :DIRECTION :OUTPUT) (WRITE F :STREAM S) (SETQ FWD1
  (FILE-WRITE-DATE S))) (WITH-OPEN-FILE (S F :DIRECTION :PROBE) (= FWD1
  (FILE-WRITE-DATE S)))) (DELETE-FILE F)))
  CORRECT: T
  CLISP  : NIL

  but on Debian/Woody 

  (LET ((X (MAKE-STRING-OUTPUT-STREAM))) (PPRINT-LOGICAL-BLOCK (X NIL
  :PREFIX "a" :PER-LINE-PREFIX "b"))) 
  OK: ERROR
  (PPRINT-NEWLINE :FRESH) 
  OK: TYPE-ERROR
  (PPRINT-POP) 
  OK: ERROR
  (PPRINT-TAB :PARAGRAPH 0 1) 
  OK: ERROR
  (LET ((*PRINT-READABLY* T)) (PRINT-UNREADABLE-OBJECT (NIL
  *STANDARD-OUTPUT*))) 
  OK: PRINT-NOT-READABLE
  (PRINT 1 2) make[1]: *** [tests] Segmentation fault
  make[1]: Leaving directory
  `/bakunin/export/home/kraehe/lisp/clisp-cvs-bakunin/src/suite'
  make: *** [testsuite] Error 2

  now funny - when I try (PRINT 1 2) with ./clisp it will work
  with Sarge barking, that "argument 2 is not a STREAM", while
  it will crash on Woody. Any idea ?

Bye Michael

---

From: Philippe Brochard <[email-masked]>
Date: Fri Feb 13 01:38:06 2004

>   it will crash on Woody. Any idea ?

I also have had this error with Woody because I use gcc 2.95,
when I switch to gcc 3.2 (also on Woody but compiled by myself),
there is no probleme.

So, maybe you have to use a more recent version of gcc.

Philippe

-- 
Philippe Brochard    <[email-masked]>
                      http://hocwp.free.fr

-=-= http://www.gnu.org/home.fr.html =-=-