Giter VIP home page Giter VIP logo

biwascheme's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.