maxima lisp emacs



Hi,

Now it works

; definition of function
(defun write_To_XPM_File (file)
	; initial values of local variable
	; which exist only for the duration of its scope, which in Lisp is the 
length of the let statement.
	( let( 	(iWidth 4) ; the pixmap width
			(iHeight 4) ; the pixmap height,
			(NoColors 2) ; the number of colors
			(cpp 1))	  ;  the number of characters per pixel

	(with-open-file
			(st file
			:direction :output
			:if-exists :overwrite
			:if-does-not-exist :create )
        ; write XPM file header to the file
		(format st "/* XPM */~%static char *a[] = {~%")
		(format st "\"~a ~a ~a ~a\",~%" iWidth iHeight NoColors cpp)
		; write color table  to file
		(format st "\"* c #000000\",~%") ;  black
		(format st "\". c #ffffff\",~%") ; white
		; write strings containing line of pixel's colors
		(format st "\".**.\",~%")
		(format st "\".**.\",~%")
		(format st "\".**.\",~%")
		(format st "\".**.\",~%")
		; write end of the file  ;  ~%   is a    new line
	    (format st "};~%")))  ; with-open-file; let
      (format t "file was created " file) ; t is a standard output
) ; defun write_To_XPM_File

; execution of function
(write_To_XPM_File "c.xpm" )



Thx

Adam























Adam Majewski pisze:
> 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