proper use of define-alias

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

proper use of define-alias

Chuah Teong Leong
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?
Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Chuah Teong Leong
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
<[hidden email]> 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?
Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Alcides Flores Pineda
Hello Chuah:

According to Kawa's documentation, (despite it  may not be very clear
here to newbie programmers) define-alias is for aliasing Java Classes
or Java Packages (aka "locations") NOT numerical constants.

If you evaluate in the Kawa REPL the mentioned constants you'll get
their numerical values. Example:

#|kawa:1|# javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS
22

(By the way, the angle-bracket syntax is now considered deprecated as
far as I know)

So the right way to accomplish what you are trying to do is either use:

(define vert-sb-always
        javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)

Or

(define-alias ScrollPaneConstants javax.swing.ScrollPaneConstants)

and then use

ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS

whenever you need the mentioned constant.

Greetings.

Alcides Flores Pineda.

> El Fri, 22 Jun 2012 16:57:04 +0800
> Chuah Teong Leong <[hidden email]> escribió:
> 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
> <[hidden email]> 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?

Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Chuah Teong Leong
Thanks Alcides.

The reason I started using define-alias was
(define vert-sb-always
       javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)

Throws me this kind of error just from having the above line of code.
Any idea what could be wrong?

java kawa.repl sandbox.scm

exception while initializing module scrollpane
        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:84)
        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:57)
        at gnu.expr.ModuleInfo.getInstance(ModuleInfo.java:272)
        at kawa.standard.require.find(require.java:120)
        at sandbox.run(sandbox.scm:5)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:279)
        at gnu.expr.CompiledModule.evalModule(CompiledModule.java:41)
        at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
        at kawa.Shell.runFile(Shell.java:510)
        at kawa.Shell.runFileOrClass(Shell.java:426)
        at kawa.repl.main(repl.java:873)
Caused by: java.lang.VerifyError: (class: scrollpane, method: run signature: (Lg
nu/mapping/CallContext;)V) Expecting to find integer on stack
        at java.lang.Class.getDeclaredFields0(Native Method)
        at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
        at java.lang.Class.getDeclaredField(Class.java:1880)
        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:74)
        ... 10 more

On Fri, Jun 22, 2012 at 11:33 PM, Alcides Flores Pineda
<[hidden email]> wrote:

> Hello Chuah:
>
> According to Kawa's documentation, (despite it  may not be very clear
> here to newbie programmers) define-alias is for aliasing Java Classes
> or Java Packages (aka "locations") NOT numerical constants.
>
> If you evaluate in the Kawa REPL the mentioned constants you'll get
> their numerical values. Example:
>
> #|kawa:1|# javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS
> 22
>
> (By the way, the angle-bracket syntax is now considered deprecated as
> far as I know)
>
> So the right way to accomplish what you are trying to do is either use:
>
> (define vert-sb-always
>        javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
>
> Or
>
> (define-alias ScrollPaneConstants javax.swing.ScrollPaneConstants)
>
> and then use
>
> ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS
>
> whenever you need the mentioned constant.
>
> Greetings.
>
> Alcides Flores Pineda.
>
>> El Fri, 22 Jun 2012 16:57:04 +0800
>> Chuah Teong Leong <[hidden email]> escribió:
>> 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
>> <[hidden email]> 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?
>
Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Chuah Teong Leong
ahh how blind of me its a private field and it is asking me to do a
define-private.
Thanks you for your reply

On Sun, Jun 24, 2012 at 1:06 PM, Chuah Teong Leong <[hidden email]> wrote:

> Thanks Alcides.
>
> The reason I started using define-alias was
> (define vert-sb-always
>       javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
>
> Throws me this kind of error just from having the above line of code.
> Any idea what could be wrong?
>
> java kawa.repl sandbox.scm
>
> exception while initializing module scrollpane
>        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:84)
>        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:57)
>        at gnu.expr.ModuleInfo.getInstance(ModuleInfo.java:272)
>        at kawa.standard.require.find(require.java:120)
>        at sandbox.run(sandbox.scm:5)
>        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:279)
>        at gnu.expr.CompiledModule.evalModule(CompiledModule.java:41)
>        at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
>        at kawa.Shell.runFile(Shell.java:510)
>        at kawa.Shell.runFileOrClass(Shell.java:426)
>        at kawa.repl.main(repl.java:873)
> Caused by: java.lang.VerifyError: (class: scrollpane, method: run signature: (Lg
> nu/mapping/CallContext;)V) Expecting to find integer on stack
>        at java.lang.Class.getDeclaredFields0(Native Method)
>        at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
>        at java.lang.Class.getDeclaredField(Class.java:1880)
>        at gnu.expr.ModuleContext.findInstance(ModuleContext.java:74)
>        ... 10 more
>
> On Fri, Jun 22, 2012 at 11:33 PM, Alcides Flores Pineda
> <[hidden email]> wrote:
>> Hello Chuah:
>>
>> According to Kawa's documentation, (despite it  may not be very clear
>> here to newbie programmers) define-alias is for aliasing Java Classes
>> or Java Packages (aka "locations") NOT numerical constants.
>>
>> If you evaluate in the Kawa REPL the mentioned constants you'll get
>> their numerical values. Example:
>>
>> #|kawa:1|# javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS
>> 22
>>
>> (By the way, the angle-bracket syntax is now considered deprecated as
>> far as I know)
>>
>> So the right way to accomplish what you are trying to do is either use:
>>
>> (define vert-sb-always
>>        javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
>>
>> Or
>>
>> (define-alias ScrollPaneConstants javax.swing.ScrollPaneConstants)
>>
>> and then use
>>
>> ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS
>>
>> whenever you need the mentioned constant.
>>
>> Greetings.
>>
>> Alcides Flores Pineda.
>>
>>> El Fri, 22 Jun 2012 16:57:04 +0800
>>> Chuah Teong Leong <[hidden email]> escribió:
>>> 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
>>> <[hidden email]> 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?
>>
Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Per Bothner
In reply to this post by Alcides Flores Pineda
On 06/22/2012 08:33 AM, Alcides Flores Pineda wrote:
> According to Kawa's documentation, (despite it  may not be very clear
> here to newbie programmers) define-alias is for aliasing Java Classes
> or Java Packages (aka "locations") NOT numerical constants.

That's the primary use, but it seems a bug that this doesn't work:

#|kawa:1|# (define-alias vert-sb-always
javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
#|kawa:2|# vert-sb-always
22

However, using define-constant may be preferable as a matter of style.
That also seems to avoid the VerifyError you mentioned when using define.
(Though a VerifyError is of course definitely a compiler bug.)
--
        --Per Bothner
[hidden email]   http://per.bothner.com/


Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Per Bothner
In reply to this post by Chuah Teong Leong
On 06/23/2012 10:06 PM, Chuah Teong Leong wrote:
> Thanks Alcides.
>
> The reason I started using define-alias was
> (define vert-sb-always
>         javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)

This should be working now in the SVN version.

> exception while initializing module scrollpane
>          at gnu.expr.ModuleContext.findInstance(ModuleContext.java:84)
>          at gnu.expr.ModuleContext.findInstance(ModuleContext.java:57)
>          at gnu.expr.ModuleInfo.getInstance(ModuleInfo.java:272)
>          at kawa.standard.require.find(require.java:120)
>          at sandbox.run(sandbox.scm:5)
>          at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:279)
>          at gnu.expr.CompiledModule.evalModule(CompiledModule.java:41)
>          at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
>          at kawa.Shell.runFile(Shell.java:510)
>          at kawa.Shell.runFileOrClass(Shell.java:426)
>          at kawa.repl.main(repl.java:873)
> Caused by: java.lang.VerifyError: (class: scrollpane, method: run signature: (Lg
> nu/mapping/CallContext;)V) Expecting to find integer on stack
>          at java.lang.Class.getDeclaredFields0(Native Method)
>          at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
>          at java.lang.Class.getDeclaredField(Class.java:1880)
>          at gnu.expr.ModuleContext.findInstance(ModuleContext.java:74)
>          ... 10 more
--
        --Per Bothner
[hidden email]   http://per.bothner.com/


Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Per Bothner
In reply to this post by Per Bothner
On 06/24/2012 12:00 AM, Per Bothner wrote:
> That's the primary use, but it seems a bug that this doesn't work:
>
> #|kawa:1|# (define-alias vert-sb-always
> javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
> #|kawa:2|# vert-sb-always
> 22

I checked in a fix for this.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/


Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Jamison Hope
On Jun 26, 2012, at 2:15 PM, Per Bothner wrote:

> On 06/24/2012 12:00 AM, Per Bothner wrote:
>> That's the primary use, but it seems a bug that this doesn't work:
>>
>> #|kawa:1|# (define-alias vert-sb-always
>> javax.swing.ScrollPaneConstants:VERTICAL_SCROLLBAR_ALWAYS)
>> #|kawa:2|# vert-sb-always
>> 22
>
> I checked in a fix for this.

In testsuite/define1.scm that should be define-alias, right?

-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com



Reply | Threaded
Open this post in threaded view
|

Re: proper use of define-alias

Per Bothner
On 06/26/2012 12:27 PM, Jamison Hope wrote:
> In testsuite/define1.scm that should be define-alias, right?

Yes and no - the intention was to test a different failure.

But it makes sense to test both, so I'll check in a change to do that.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/