This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: proper use of define-alias
A shorter version of my question is as follows
(define-alias vert-sb-always
<javax.swing.ScrollPaneConstants>:VERTICAL_SCROLLBAR_ALWAYS)
(define-alias hori-sb-always
<javax.swing.ScrollPaneConstants>:HORIZONTAL_SCROLLBAR_ALWAYS)
;; this doesnt work
(let ((myvar vert-sb-always)
(myvar2 hori-sb-always))
(make-scrollpane-with-policy in-component
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? myvar myvar2))
why cant i assign a temp variable like that and use it like that?
in the previous example using vpolicy and hpolicy throws an exception
;; choose the correct constant based on the symbol passed in
(define vpolicy
(case vp-sym
((always) vert-sb-always)
((needed) vert-sb-needed)
((never) vert-sb-never)
(else (display "Error unknown policy ")(display vp-sym)
vert-sb-needed)))
(define hpolicy
(case hp-sym
((always) hori-sb-always)
((needed) hori-sb-needed)
((never) hori-sb-never)
(else (display "Error unknown policy ")(display hp-sym)
hori-sb-needed)))
(<javax.swing.JScrollPane> in-component vpolicy hpolicy)
whereas...
this works
(<javax.swing.JScrollPane>
in-component
(case vp-sym
((always) vert-sb-always)
((needed) vert-sb-needed)
((never) vert-sb-never)
(else (display "Error unknown policy ")(display vp-sym)
vert-sb-needed))
(case hp-sym
((always) hori-sb-always)
((needed) hori-sb-needed)
((never) hori-sb-never)
(else (display "Error unknown policy ")(display hp-sym)
hori-sb-needed)))
so essentially my problem is with why there's a problem with assigning
a temp variable to the define-alias variables
On Thu, Jun 21, 2012 at 11:11 PM, Chuah Teong Leong
<teongleong@gmail.com> wrote:
> hi. I'm new to the use of define-alias and I was trying to use it as follows.
>
> Exception:
> Value '20' for variable 'vpolicy' has wrong type (java.lang.Integer) (java.lang.
> Integer cannot be cast to gnu.mapping.Location)
>
> (define-alias vert-sb-always
> <javax.swing.ScrollPaneConstants>:VERTICAL_SCROLLBAR_ALWAYS)
> (define-alias vert-sb-needed
> <javax.swing.ScrollPaneConstants>:VERTICAL_SCROLLBAR_AS_NEEDED)
> (define-alias vert-sb-never
> <javax.swing.ScrollPaneConstants>:VERTICAL_SCROLLBAR_NEVER)
>
> (define-alias hori-sb-always
> <javax.swing.ScrollPaneConstants>:HORIZONTAL_SCROLLBAR_ALWAYS)
> (define-alias hori-sb-needed
> <javax.swing.ScrollPaneConstants>:HORIZONTAL_SCROLLBAR_AS_NEEDED)
> (define-alias hori-sb-never
> <javax.swing.ScrollPaneConstants>:HORIZONTAL_SCROLLBAR_NEVER)
>
> (define (make-scrollpane in-component :: <javax.swing.JComponent>)
> ?(<javax.swing.JScrollPane> in-component))
>
> ;; make a scrollpane with policy
> (define (make-scrollpane-with-policy in-component :: <javax.swing.JComponent>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vp-sym :: <symbol>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? hp-sym :: <symbol> )
>
> ;; choose the correct constant based on the symbol passed in
> ?(define vpolicy
> ? ?(case vp-sym
> ? ? ?((always) vert-sb-always)
> ? ? ?((needed) vert-sb-needed)
> ? ? ?((never) vert-sb-never)
> ? ? ?(else (display "Error unknown policy ")(display vp-sym)
> ? ? ? ? ? ?vert-sb-needed)))
>
> ? (define hpolicy
> ? ?(case hp-sym
> ? ? ?((always) hori-sb-always)
> ? ? ?((needed) hori-sb-needed)
> ? ? ?((never) hori-sb-never)
> ? ? ?(else (display "Error unknown policy ")(display hp-sym)
> ? ? ? ? ? ?hori-sb-needed)))
>
> ? (<javax.swing.JScrollPane> in-component vpolicy hpolicy)
> ?)
>
> What is the proper way of doing what I want to do here?