List of functions

Basic types

Numeric types

Control structure

Macro

BiwaScheme does not have syntax-rules or syntax-case, but has define-macro.

(define-macro (test expr)
  `(if ,expr
    #t
    (print (format "test failed: ~a" (quote ,expr)))))

(test (= 1 2)) ;=> test failed: (= 1 2)

Other macro-related functions:

Advanced types

Utilities

Syntax

JavaScript language interface

Browser functions

These functions are only available in browsers (i.e. does not work on Node.js.)

  (element-new '(div "foo"))        => <div>foo</div>
  (element-new '("div#main" "foo")) => <div id='main'>foo</div>
  (element-new '("div.red" "foo"))  => <div class='red'>foo</div>
  (element-new '(div align "right" "foo"))  => <div align='right'>foo</div>
  (element-new '(div (span "foo"))  => <div><span>foo</span></div>

Node.js

System functions

Loading other files

path is relative to the current directory, unless it starts with / or /^\w:/ (i.e. c:, d:, etc.)

Using Node.js libraries

You can also use Node.js libraries via js-eval, etc.

(define fs (js-eval "require('fs')"))

(define path ".")
(print (js-invoke fs 'readdirSync path))
; Alternatively you can use `..` macro syntax:
; (print (.. fs `(readdirSync ,path)))

BiwaScheme JavaScript API

Evaluate Scheme program

<script type="text/javascript" src="biwascheme.js"></script>
<script type="text/javascript">
var onError = function(e){ console.error(e); }
var biwa = new BiwaScheme.Interpreter(onError)
biwa.evaluate("(+ 1 2)", function(result) {
  alert(result);  //=> 3
});
</script>

Define library function

You can write JavaScript library function with BiwaScheme.define_libfunc.

BiwaScheme.define_libfunc("add", 2, 2, function(ar){
  BiwaScheme.assert_integer(ar[0]);
  BiwaScheme.assert_integer(ar[1]);
  return ar[0] + ar[1];
});

See src/library/*.js for more examples.

Stringify scheme object