Bugs in printf?



Ray,

this is cool! I didn't know that this specification exists. 
But unfortunately it doesn't seem to be implemented in GCL.

OK with CLISP:

MAXIMA> (defun bf (&rest args) (format t "~a" args))
BF
MAXIMA> (format t "abc~/maxima::bf/abc~%" 42)
abc(#<IO SYNONYM-STREAM *TERMINAL-IO*> 42 NIL NIL)abc
NIL

But with GCL:
MAXIMA> (defun bf (&rest args) (format t "~a" args))

BF
MAXIMA> (format t "abc~/maxima::bf/abc~%" 42)

abc
Maxima encountered a Lisp error:

 Error in FORMAT [or a callee]: Format error: illegal directive.
     V
"abc~/maxima::bf/abc~%"

Or am I doing something wrong?

Volker


Raymond Toy schrieb:
> Volker van Nek wrote:
>   
>> I fear I have to say that this bug is impossible to fix in the current 
>> implementation of printf. 
>>
>> printf basically uses format. Since format doesn't know a directive for 
>> bigfloats I invented the ~h directive (h=huge) and wrote a version of 
>> printf where each ~h directive is converted to an according ~a directive 
>> and the corresponding bigfloat argument is converted into a formatted string 
>> before calling format.
>>     
> Perhaps instead of using ~h, which is not standard CL, we can use ~/,
> which is standard CL
> (http://www.lispworks.com/documentation/HyperSpec/Body/22_ced.htm).
>
> So for printing bigfloats, we can use ~/maxima::bf/ or something like
> that.  We'll have to write the function maxima::bf, but that shouldn't
> be too hard since you already have something to handle ~h.
>
> Don't know if this will work or not; I've never used printf before and
> haven't looked at the implementation either.
>
> Ray
>
>   
>>  
>> As a result of this concept I already had to skip the ~* directive which allows 
>> to use arguments more than one time. In your example you effectively reorder 
>> the arguments. This also leads into trouble. 
>> My preprocessing the expressions before calling format needs a proper 
>> sequential correspondence of both directives and arguments. 
>>
>> A way out of these problems will be an implementation of printf which uses 
>> format only in a very basic way (just single args). But that is a long way. 
>> I hope I can do it this year. 
>>
>> At the moment I can't be more helpful.
>>
>> Volker 
>>
>>
>>
>>
>>   
>>     
>>> I'm using a very recent CVS version.
>>>
>>> Regards,
>>> Jaime
>>>
>>>
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>>   
>>>     
>>>       
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>   
>>     
>
>
>