Skip to content

Template for integrating the BiwaScheme interpreter, which runs on JavaScript, into LiaScript courses.

License

Notifications You must be signed in to change notification settings

LiaTemplates/BiwaScheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

BiwaScheme - Template

                     --{{0}}--

This document defines some basic macros for applying the JavaScript BiwaScheme interpreter in LiaScript to make Scheme code snippets in Markdown executeable and editable.

Try it on LiaScript:

https://liascript.github.io/course/?https://github.com/liaTemplates/BiwaScheme

See the project on Github:

https://github.com/liaTemplates/BiwaScheme

                     --{{1}}--

There are three ways to use this template. The easiest way is to use the import statement and the url of the raw text-file of the master branch or any other branch or version. But you can also copy the required functionionality directly into the header of your Markdown document, see therefor the last slide. And of course, you could also clone this project and change it, as you wish.

{{1}}

  1. Load the macros via

    import: https://raw.githubusercontent.com/liaTemplates/BiwaScheme/master/README.md

  2. Copy the definitions into your Project

  3. Clone this repository on GitHub

@BiwaScheme.eval

                     --{{0}}--

To use the BiwaScheme interpreter, simply add the macros @BiwaScheme.eval to the end of your scheme snippet.

(define (fizzbuzz x y)
  (print
    (cond (( = (mod x 15) 0 ) "FizzBuzz")
          (( = (mod x 3) 0 ) "Fizz")
          (( = (mod x 5) 0 ) "Buzz")
          (else x)))

    (if (< x y) (fizzbuzz (+ x 1) y)))

(fizzbuzz 1 10)

@BiwaScheme.eval

                     --{{1}}--

For a complete overview on all available functions, see the BiwaScheme project website:

                       {{1}}

https://www.biwascheme.org/doc/reference.html

@BiwaScheme.evalWithTerminal

                     --{{0}}--

Use the @BiwaScheme.evalWithTerminal macro, if you want to enable interactive programming. This opens a terminal after the programm execution that allows to execute scheme code. Add for example your fizzbuzz command with different parameters.

(define (fizzbuzz x y)
  (print
    (cond (( = (mod x 15) 0 ) "FizzBuzz")
          (( = (mod x 3) 0 ) "Fizz")
          (( = (mod x 5) 0 ) "Buzz")
          (else x)))

    (if (< x y) (fizzbuzz (+ x 1) y)))

@BiwaScheme.evalWithTerminal

Implementation

                     --{{0}}--

The code shows how the macros were implemented by using a minified version of the BiwaScheme JavaScript interpreter.

script:   ./biwascheme-0.8.0-min.js

@BiwaScheme.eval
<script>
BiwaScheme.Console.puts = function(str, x){ console.stream(str + (x ? '\n' : '')) }

var biwa = new BiwaScheme.Interpreter(console.error)
biwa.evaluate(`@input`, function(result) {
  if (result && result != "#<undef>") {
    console.debug(result)
  }
});
"LIA: stop"
</script>
@end


@BiwaScheme.evalWithTerminal
<script>
BiwaScheme.Console.puts = function(str, x){ console.stream(str + (x ? '\n' : '')) }

var biwa = new BiwaScheme.Interpreter(console.error)

setTimeout(function() {
  biwa.evaluate(`@input`, function(result) {
    if (result && result != "#<undef>") {
      console.debug(result)
    }
  });
}, 100)

send.handle("input", input => {
  try{
    biwa.evaluate(input, function(result) {
      if (result && result != "#<undef>") {
        console.debug(result)
      }
    })
  } catch (e) {
    console.error(e);
  }
})

send.handle("stop", e => { console.log("execution stopped") })

"LIA: terminal"
</script>

@end
                     --{{1}}--

If you want to minimize loading effort in your LiaScript project, you can also copy this code and paste it into your main comment header, see the code in the raw file of this document.

{{1}} https://raw.githubusercontent.com/liaTemplates/BiwaScheme/master/README.md

Releases

No releases published

Packages

No packages published