scheme and jsr223

scheme and java objects


Comment out statement

";" That is, a semicolon at the beginning of the line


import

For now, it's a good idea to declare the following on the first line:

(import type-system) (import oo) (import s2j)


Operation check

(display "HelloWorld")

Whether to output to the console with


Object-orientation

Basically, object manipulation in object-oriented languages doesn't seem to be in the language specification, but it seems that most implementations have it separately. sisc is also prepared because it is implemented on JavaVM.

(Field instance name)

Feeling

Obj as an instance. If str as a field

(str obj)

Feeling like that.

If the argument is args in the method,

(str obj args)

Feeling like that.


JSR223 object

It's in the readme of the interface for JSR223, but there is a var for the bound object.

For example, if you are binding as obj,

(var 'obj)

Feeling like that.

But Java instances are usually case-sensitive, aren't they?

So For example, if you are binding as Obj,

(var '|Obj|)

Feeling like that.

So to access that field str

(str (var '|Obj|))

It means that.


Java field name

Well, Java fields are also case sensitive, huh.

So what if the previous str was something like Str?

So, there are methods (or operators or commands) that resolve Java field names.

(generic-java-field-accessor '|Str|)

Feeling like that.

So, to access the Str field of the bound Obj object,

(  (generic-java-field-accessor '|Str|)  (var '|Obj|) )

Will be.

Another for field updates 「generic-java-field-modifier」 For methods 「generic-java-method」 There is something like


I want to use the value of Java field name as scheme data.

Now let's assume a Java Boolean field called IsBool (let's say it's a field of a bound object called Obj) and consider using it in the if of scheme.

(  (generic-java-field-accessor '|IsBool|)  (var '|Obj|) )

As it is, it cannot be used in shceme, so there is something called (-> type target) to use this as a scheme, so

(->boolean  (   (generic-java-field--accessor '|IsBool|)   (var '|Obj|)  ) )

With that feeling, it became possible to use it in scheme, so if you give it to the if operator, it will finally look like this

(if  (eq?   (->boolean    (     (generic-java-field--accessor '|IsBool|)     (var '|Obj|)    )   )   #t  ) (This is the true formula) (This is a fake formula) )

It will be like that.

Recommended Posts

scheme and jsr223
jacl and jsr223
== and equals