From: Stormcoder
Subject: PARSE-BODY and Clisp
Date: 
Message-ID: <9e120d03-646e-40db-938b-3bd014bfbc41@z1g2000yqn.googlegroups.com>
I'm trying to use PARSE-BODY in Clisp and whenever I try to eval I get
the error "*** - EVAL: undefined function PARSE-BODY"

Here's the code I am using:

(defpackage Monitor
  (:use "SYSTEM")
  (:use "COMMON-LISP"))
(in-package Monitor)

(defmacro with-open-com ((stream port-name) &body body)
  (multiple-value-bind (body-rest declarations) (parse-body BODY)
    `(let ((,stream)
           (flags-bits 2147483648))
       (ffi:with-c-var (lpDCB `DCB)
         (ffi:with-c-var (hFile `ffi:int)
           (declare (read-only ,stream) ,@declarations)
           (setf hFile (CreateFileW ,port-name flags-bits 0 NIL 3 0
0))
           (GetCommState hFile (ffi:c-var-address lpDCB))
           (SetCommState hFile (make-DCB :DCBLength 28
                                         :BaudRate 115200
                                         :flag 0
                                         :wReserved 0
                                         :XonLim 2048
                                         :XoffLim 512
                                         :ByteSize 8
                                         :Parity 0
                                         :StopBits 0
                                         :XonChar 17
                                         :XoffChar 19
                                         :ErrorChar 0
                                         :wReserved 0))
           (CloseHandle hFile)
           (setf ,stream (open ,port-name :direction :io :element-type
`unsigned-byte))
           (unwind-protect
                (multiple-value-prog1 (progn ,@body-rest)
                  (when ,stream
                    (close ,stream)
                    (setf hFile (CreateFileW ,port-name flags-bits 0
NIL 3 0 0))
                    (SetCommState hFile lpDCB)
                    (CloseHandle hFile)))
             (when ,stream
               (close ,stream :abort t)
               (setf hFile (CreateFileW ,port-name flags-bits 0 NIL 3
0 0))
               (SetCommState hFile lpDCB)
               (CloseHandle hFile))))))))

(defun Monitor-Read2 ()
    (with-open-com (serial "COM2")
      (format t "start...")
      (loop :for c = (read-char-no-hang serial) :while c :do
         (format t "~C" c))))

The error occurs when I eval the Monitor-Read2 function. I've tried
different things to try to get around the problem. I tried referencing
parse-body using the package name like so: system:parse-body. I've
tried different ways to get the name into the current package such as
import. I'm kind of at a loss since this function should be available
and nothing I've tried worked. What am I doing wrong?

From: Zach Beane
Subject: Re: PARSE-BODY and Clisp
Date: 
Message-ID: <m3od05uk50.fsf@unnamed.xach.com>
Stormcoder <·········@gmail.com> writes:

> I tried referencing parse-body using the package name like so:
> system:parse-body. I've tried different ways to get the name into the
> current package such as import. I'm kind of at a loss since this
> function should be available and nothing I've tried worked. What am I
> doing wrong?

In my CLISP, PARSE-BODY is not an exported symbol of the SYSTEM package,
so using IMPORT, :USE, or a single-colon reference like
SYSTEM:PARSE-BODY will all fail.

If you really want to use it, you can probably go with
SYSTEM::PARSE-BODY. However, if a symbol isn't exported, that's a sign
that you probably shouldn't use it casually.

Zach
From: Tobias C. Rittweiler
Subject: Re: PARSE-BODY and Clisp
Date: 
Message-ID: <87zljpc8f3.fsf@freebits.de>
Stormcoder <·········@gmail.com> writes:

> (defmacro with-open-com ((stream port-name) &body body)
>   (multiple-value-bind (body-rest declarations) (parse-body BODY)
>     `(let ((,stream)
>            (flags-bits 2147483648))
>        (ffi:with-c-var (lpDCB `DCB)
>          (ffi:with-c-var (hFile `ffi:int)
>            (declare (read-only ,stream) ,@declarations)
>            ...

This naive splicing of the declarations won't be semantically
correct. You can look at the library `parse-declarations'[1] (which also
comes with a PARSE-BODY function) to get it 100% correct. 

Your macro is also leaky in several ways.

  -T.

[*] http://common-lisp.net/project/parse-declarations
From: Stormcoder
Subject: Re: PARSE-BODY and Clisp
Date: 
Message-ID: <178b929d-3590-426e-b9cb-a2f1475179df@j39g2000yqn.googlegroups.com>
On Nov 24, 9:58 am, "Tobias C. Rittweiler" <····@freebits.de.invalid>
wrote:
> Stormcoder <·········@gmail.com> writes:
> > (defmacro with-open-com ((stream port-name) &body body)
> >   (multiple-value-bind (body-rest declarations) (parse-body BODY)
> >     `(let ((,stream)
> >            (flags-bits 2147483648))
> >        (ffi:with-c-var (lpDCB `DCB)
> >          (ffi:with-c-var (hFile `ffi:int)
> >            (declare (read-only ,stream) ,@declarations)
> >            ...
>
> This naive splicing of the declarations won't be semantically
> correct. You can look at the library `parse-declarations'[1] (which also
> comes with a PARSE-BODY function) to get it 100% correct.
>
> Your macro is also leaky in several ways.
>
>   -T.
>
> [*]http://common-lisp.net/project/parse-declarations

I'm still figuring out figuring out macros. Thanks for the info Tobias
and Zach. I'm taking the iterative aproach, obviously. ;') I thought
the win32 part of the app was going to be the hard part but it seems
getting the macro right is where the work is going to be.