Table of Contents
- Scheme inline
- Value Mapping
- Null and Undefined
- (generic js-tostring ::JsObject ::JsGlobalObject)
- (generic js-tonumber ::JsObject ::JsGlobalObject)
- (generic js-integer ::JsObject ::JsGlobalObject)
- (generic js-valueof ::JsObject ::JsGlobalObject)
- (generic js-get ::JsObject ::symbol ::JsGlobalObject)
- (generic js-put! ::JsObject ::symbol ::obj ::bool ::JsGlobalObject)
<Expression> → ... | <SchemeIdentifier> <SchemeIdentifier> → #:SchemeId
let x = #:list( 1, 2, 3 ); #:set-car!( x, 0 ); let y = #:cadr( x );
require form can be used to import Scheme
a function named
hopscript that should accept exactly for arguments:
_, currently unused;
When the a required module is suffixed with
.hop the following actions
- the Scheme module is loaded in memory;
- the Scheme function
hopscriptis invoked, passing it the newly created object.
The result of the
require form is the freshly allocated module object.
const hopmod = require( "./example.hop" ); console.log( hopmod );
and let us define a simple example that merely leaves a trace of its loading:
(module a-module (export (hopscript %this _ scope mod))) (define (hopscript %this _ scope mod) (print "in a-module"))
(js-get jsobject propname %this)
(js-put! jsobject propname throw %this)
The first argument
propname is the name of the read property. It is a Scheme symbol. The
third argument of the
js-put! function is a boolean that control whether
an exception should be raised if the property cannot be writen. The
(module a-module-with-binding (export (hopscript %this _ scope mod))) (define (hopscript %this _ scope mod) (let ((exports (js-get mod 'exports %this))) (js-put! exports 'loaded #t #f %this)))
console.log( require( "./mod.hop" ).loaded );
Null and Undefined
null is represented as the Scheme empty list
undefined is represented as the Scheme
js-number->jsnumber does it.
JsObject. Global objects (the
%this parameter of module
declaration) are instances of the
JsGlobalObject class. These
classes own private fields that should not be directly accessed.
(generic js-tostring ::JsObject ::JsGlobalObject)
(generic js-tonumber ::JsObject ::JsGlobalObject)
(generic js-integer ::JsObject ::JsGlobalObject)
(generic js-valueof ::JsObject ::JsGlobalObject)
This generic function implements the
(generic js-get ::JsObject ::symbol ::JsGlobalObject)
This generic function is used to fetch object attributes.
(generic js-put! ::JsObject ::symbol ::obj ::bool ::JsGlobalObject)
This generic function is used to set object attributes.
JsWrapper class is to be used by Scheme programs that need to pass
(class JsWrapper::JsObject obj data)
This class can be sub-classes, in particular to override the generic functions.