[Openmcl-devel] rules for string to NSstring conversions

Alexander Repenning ralex at cs.colorado.edu
Mon Dec 15 07:47:48 PST 2008


This may well be explained in the documentation somewhere but I did  
not find it. Btw, I think it would be nice to have the Clozure doc (http://ccl.clozure.com/manual/ 
  ) available with some search function. I find myself constantly  
guessing in which section I have to look at. Usually I fall back to to  
just use Google search. In the mean time just having the doc available  
as one pdf would be nice.

Anyway, here is just something that appears to be inconsistent. Two  
implementations of MCL-like standard alert dialog. The first one can  
handle lisp string to NSstring coercion just fine (i.e., "bla" turn  
into a constant NSstring and nil turns into a Objective-c null  
pointer) whereas the second implementation based on the  
"alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat 
" function which also takes NSstring parameters, cannot handle lisp  
strings or nil. What is the rule for automatic conversion to work? The  
only obvious difference I can see is that  
alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat 
  is a class method but why would that be relevant?

Alex





(defmethod STANDARD-ALERT-DIALOG ((Message string) &key
                                   (Yes-Text "Yes")
                                   (No-Text "No")
                                   (Cancel-Text "Cancel")
                                   (Explanation-Text)
                                   (Is-Critical nil))
   (let ((Alert (#/init (#/alloc ns:ns-alert))))
     (#/setMessageText: Alert Message)
     (#/addButtonWithTitle: Alert Yes-Text)
     (#/addButtonWithTitle: Alert No-Text)
     (#/addButtonWithTitle: Alert Cancel-Text)
     (when Explanation-Text (#/setInformativeText: Alert Explanation- 
Text))
     (#/setAlertStyle: Alert (if Is-Critical #$NSCriticalAlertStyle # 
$NSWarningAlertStyle))
     (case (#/runModal Alert)
       (#.#$NSAlertFirstButtonReturn t)
       (#.#$NSAlertSecondButtonReturn nil)
       (#.#$NSAlertThirdButtonReturn (throw :cancel nil)))))


#| Why does this require NSstring parameters and does not  
automatically convert Lisp strings or deal with nil??

(defun STANDARD-ALERT-DIALOG2 (Message &key
                                   (yes-text #@"Yes")
                                   (no-text #@"No")
                                   (cancel-text #@"Cancel")
                                   (explanation-text #@"because..."))
   (#/runModal
    (#/ 
alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat 
:
     ns:ns-alert
     Message
     yes-text
     no-text
     cancel-text
     explanation-text)))

(standard-alert-dialog2 #@"this works")
(standard-alert-dialog2 "but not this")

|#


Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20081215/a25a91b1/attachment.htm>


More information about the Openmcl-devel mailing list