[Maxima] maxima lisp emacs

Adam Majewski adammaj1 at o2.pl
Fri Nov 13 12:11:25 CST 2009


Hi,

Thx for answer and tips,
I have removed 3 errors ( syntax ?),
and found nest 2 logical ( ?) :
- first : A local variable exists only for the duration of its scope, 
which in Lisp is the length of the let statement. ( so I have to move 
closing paren)
- second : I have to change content of file to be properly created.


Thx  (:-))

Adam



Raymond Toy pisze:
> Adam Majewski wrote:
>> Hi Jaime ,
>>
>> Thx for answer,
>>
>> I have made function for creating xpm file:
>>   
> 
> First, it's a lot easier to find the problem if you use more typical
> Lisp indentation style.  (This particular result was obtained by running
> (pprint '(defun ....)) with CMUCL.  There will be differences if other
> Lisps are used.)
> 
> (defun write_to_xpm_file (file)
>   (let (iwidth 4)
>     (iheight 4)
>     (nocolors 2)
>     (cpp 1)
>     (file "m.xpm"))
>   with-open-file
>   ((st file :direction :output :if-exists :overwrite :if-does-not-exist
>     :create)
>    (format st "/* xpm */~%static char *a[] = {~%")
>    (format st "\"~a ~a ~a ~a\",~%" iwidth iheight nocolors cpp)
>    (format st "* c #000000~%") (format st ". c #ffffff~%")
>    (format st ".**.~%") (format st ".**.~%") (format st ".**.~%")
>    (format st ".**.~%") (format st "};~%"))
>   (format t "file was created " file))
> 
> 
> Immediately we can see 3 problems.  First is the let form.  It should be:
> 
>   (let ((iwidth 4)
>         (iheight 4)
>         (nocolors 2)
>         (cpp 1)
>         (file "m.xpm"))
> 
> Then we can see another problem:  with-open-file needs an opening paren:
> 
>     (with-open-file
> 
> Finally, the last issue is that there are too many parentheses after
> with-open-file.  It should look like
> 
>         (st file :direction :output :if-exists :overwrite :if-does-not-exist
> 
> So, put all of these fixes together and indent nicely:
> 
> (defun write_to_xpm_file (file)
>   (let ((iwidth 4) (iheight 4) (nocolors 2) (cpp 1) (file "m.xpm"))
>     (with-open-file
>         (st file :direction :output :if-exists :overwrite
>          :if-does-not-exist :create)
>       (format st "/* xpm */~%static char *a[] = {~%")
>       (format st "\"~a ~a ~a ~a\",~%" iwidth iheight nocolors cpp)
>       (format st "* c #000000~%")
>       (format st ". c #ffffff~%")
>       (format st ".**.~%")
>       (format st ".**.~%")
>       (format st ".**.~%")
>       (format st ".**.~%")
>       (format st "};~%"))
>     (format t "file was created " file)))
> 
> (This is CMUCL's pretty printer.  My personal style is slightly
> different.  Each part of let would be on a separate line and I'd put (st
> file ...) on the same line as with-open-file.)
> 
> It would be beneficial to read a Lisp book.  Practical Common Lisp is
> one that you can find online.
> 
> Ray



More information about the Maxima mailing list