[Uim] Questions on coding for uim

Kazuki Ohta mover at hct.zaq.ne.jp
Fri Jun 24 18:34:47 EEST 2005


Hi, Park.
Thank you for your efforts :-)

Now, current context-update-preedit implementation is this.

   610 |(define context-update-preedit
   611 |  (lambda (context segments)
   612 |    (im-clear-preedit context)
   613 |    (print segments)
   614 |    (for-each (lambda (segment)
   615 |                (if segment
   616 |                    (let ((attr (car segment))
   617 |                          (str (cdr segment)))
   618 |                      (im-pushback-preedit context attr str))))
   619 |              segments)
   620 |    (im-update-preedit context)))

and the variable "segments" is like this.

((6 . "") (1 . ""))
(() () () ())

And, current siod (scheme interpreter) behave like this.

ubuntu% ./uim-sh 
uim> (car '())
()
uim> (car #f)
()

As a result, both '() and #f is ignored in context-update-preedit.
But R5RS, scheme interpreter should behave as below (using Gauche)

ubuntu% gosh
gosh> (car '())
*** ERROR: pair required, but got ()
Stack Trace:
_______________________________________
gosh> (car #f)
*** ERROR: pair required, but got #f
Stack Trace:
_______________________________________

So, if we use the R5RS compatible scheme interpreter, we'll need to
implement sanity check for '() in context-update-preedit. passing #f to
contex-update-preedit is semantically wrong, I think.

(define context-update-preedit
  (lambda (context segments)
    (im-clear-preedit context)
    (print segments)
    (for-each (lambda (segment)
                (if segment
                    (let ((attr (if (null? segment)
                                      '()
                                       car segment))
                           (str (if (null? segment)
                                     '()
                                      cdr segment)))
                      (im-pushback-preedit context attr str))))
              segments)
    (im-update-preedit context)))

> Hello,
> 
> TOKUNAGA Hiroyuki <tkng at xem.jp> writes:
> 
> > 
> > > I have a question on writing scheme code for uim, related to bug 1).
> > > The second argument of context-update-preedit is a list of pairs of
> > > attributes and strings.  According to anthy-input-state-preedit, it
> > > seems that the list is also allowed to have #f or '() as one of its
> > > elements.  Is it #f or '() that can be an element of the second
> > > argument of context-update-preedit?
> > 
> > attr should be a number which defined in im.scm. i.e. preedit-none, 
> > preedit-underline, preedit-reverse, preedit-cursor or preedit-
> > separator. If there's no attribute, you should use preedit-none. On the
> > other hand, when the segment has no str, you should use "".
> > 
> 
> My question is something else.  Look at the following procedure from
> anthy.scm:
> 
> (define anthy-input-state-preedit
>   (lambda (ac)
>     (let* ((preconv-str (anthy-context-preconv-ustr ac))
> 	   (rkc (anthy-context-rkc ac))
> 	   (pending (rk-pending rkc))
> 	   (kana (anthy-context-kana-mode ac))
> 	   (rule (anthy-context-input-rule ac))
> 	   (extract-kana
> 	    (if (= rule anthy-input-rule-kana)
> 		(lambda (entry) (car entry))
> 		(lambda (entry) (nth kana entry)))))
> 
>       (list
>        (and (not (ustr-cursor-at-beginning? preconv-str))
> 	    (cons preedit-underline
> 		  (string-append-map-ustr-former extract-kana preconv-str)))
>        (and (> (length pending) 0)
> 	    (cons preedit-underline pending))
>        (and (anthy-has-preedit? ac)
> 	    (cons preedit-cursor ""))
>        (and (not (ustr-cursor-at-end? preconv-str))
> 	    (cons preedit-underline
> 		  (string-append-map-ustr-latter extract-kana preconv-str)))))))
> 
> The result is a list with four elements.  Each element can be either a
> pair or #f depending on the first argument passed to and.  So I guess
> that #f is ignored by context-update-preedit.  Because the current
> scheme interpreter does not distinguish between #f and '(), I am
> wondering about the exact spec of context-update-preedit.  Does it
> ignore #f, '(), or both?
> 
> Regards,
> 
> Jae-hyeon
> _______________________________________________
> uim mailing list
> uim at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/uim
> 
> 

-- 
-------------------------------------------------
Kazuki Ohta : mover at hct.zaq.ne.jp
-------------------------------------------------



More information about the uim mailing list