Giter Club home page Giter Club logo

biwascheme's Introduction

BiwaScheme

biwascheme logo

BiwaScheme is a Scheme interpreter written in JavaScript.

Works with web browsers (including mobile devices) and Node.js.

Demos

see http://www.biwascheme.org/

Download

(Or you can just copy the file from ./release.)

How to use

Just load biwascheme.js (or biwascheme-min.js) and write Scheme code.

<!DOCTYPE html>
<html>
<body>

<div id="bs-console"></div>

<script src="biwascheme.js"></script>
<script type="text/biwascheme">
(display "hello, world!")
</script>

</body>
</html>

How to use with node.js to run a biwa script

  1. $ npm install -g biwascheme

  2. create a file a.scm:

    (display "Hello, world!") (newline)

  3. $ biwas a.scm

How to use from inside node.js as a module

  1. $ npm install biwascheme

  2. create a file a.js:

    var BiwaScheme = require("biwascheme"); BiwaScheme.run("(+ 1 2)"); // or BiwaScheme.run_file("a.scm");

  3. $ node a.js

Statically build biwa-powered website

The npm package contains biwascheme.mjs for module bundlers like rollup. See https://github.com/acmiyaguchi/svelte-biwascheme-example for an example.

Note that biwascheme.mjs does not include jQuery unlike biwascheme-x.y.z.js. You need to bundle jQuery manually if you want to use functions defined in src/library/webscheme_lib.js.

Building biwascheme.js

You need Node.js (tested with v16.5.0) and npm (tested with v7.20.1) to build biwascheme.js.

See doc/dev/build.md.

Development

How to run tests

Prerequisites: Node.js, npm

  1. $ npm install
  2. $ npm run serve
  3. Open http://localhost:7001/test/spec.html

Some more tests

Conformance

BiwaScheme implements most of the features of R7RS small, including first-class continuation and tail call optimization.

Major lacking features are:

  • syntax-rules
  • Exceptions
  • Library system

There are two limitations that arise from JavaScript. These will not be fixed (it's technically possible to fix but will be very inefficient).

  • Strings are immutable
  • Integers are not distinguished from float

Links

License

MIT-LICENSE

BiwaScheme logo by @jcubic: Creative Commons Attribution 3.0

Acknowledgements

Contact

https://github.com/biwascheme/biwascheme

Yutaka HARA (yhara) yutaka.hara.gmail.com http://twitter.com/yhara_en

biwascheme's People

Contributors

acmiyaguchi avatar alanthird avatar anadrome avatar cpressey avatar dependabot[bot] avatar dragoncoder047 avatar eatonphil avatar epozzobon avatar erjiang avatar jbonigomes avatar jcubic avatar jfhbrook avatar kenpratt avatar kpengboy avatar lilsweetcaligula avatar masatake avatar matthewdean avatar mikecat avatar mtornwall avatar okuoku avatar peterolson avatar pulpgrinder avatar rain-1 avatar spatten avatar vidjuheffex avatar viebel avatar woxtu avatar wware avatar yhara avatar zaoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

biwascheme's Issues

Sorting functions do lexicographical sort

For example,

(vector-sort (vector 1 2 10))

returns

#(1 10 2)

when it should return

#(1 2 10)

This is likely due to using the native Javascript Array.prototype.sort function which does lexicographical sorting.

Website: REPL, unit test etc. are down

Hello,

Interactive examples hosted on biwascheme.org under the "Demo" section are currently down, with quite a few 404.

Thank you for your work on BiwaScheme.

Unnecessary use of `with`?

The biwascheme library code uses with in several places, generally in conjunction with define_libfunc. Given the concerns involved in use of with (the ambiguity problem came up for me earlier why trying to hack on the js interface...), I'd think that, in the long term, it could be useful to refactor the withs out.

(Tangentially, I'd also super-appreciate it if a future biwascheme would conform to ES5 strict mode, but that isn't necessarily feasible.)

Release 0.6.2

  • fix raphaelis demo is broken
  • update History.txt
  • Add size cap to stack trace (#9) Confirmed it grows too long with infinite loop.
  • release .js (update website)
  • release node package

remove-handler! does not seem to work

Hello,

Scheme (and programming) novice here, so please forgive any obvious mistake.
I tried the following code in BiwaScheme's REPL:

(define say-hello
(lambda ()
(alert "Hi there!")))

(add-handler! (getelem "body") "click" say-hello)
(remove-handler! (getelem "body") "click" say-hello)

Upon clicking the page, an alert shows nonetheless. Am I missing something?

Thank you.

"unknown opecode type: undefined"

Using BiwaScheme 0.6.3.dev
When I run

((lambda (a . b) 0))

I get

[BUG] unknown opecode type: undefined []

which I guess means the compiler's generating invalid bytecode?

define-record-type syntax

Is there a reason define-record-type doesn't follow the spec?
It should look like:

(define-record-type my-type
  (make-my-type bar baz)
  my-type?
  (bar get-bar set-bar!)
  (baz get-baz))

but instead, it's like:

(define-record-type my-type
  (fields (mutable bar) (immutable baz)))

I can't port Scheme code, and anyone who works with what I have in Biwascheme would have to figure out this syntax.

(Chrome) Browser hotkeys override DOM focus

This is somewhat interesting, as I've never seen Chrome fail to defer focus to an active DOM element. Typing "(" into the interpreter works, but "d" triggers a scroll down hotkey in Chrome. It also consumes the character.

EDIT: This appears to be a conflict with the Vimium extension for Chrome. Disabling the extension allows the interpreter to work as it should. Possibly this is more of an issue with Vimium than BiwaScheme...

psyntax

I am working on a project using Scheme in the browser. Biwa seems to check off all the other requirements except for proper r6 syntax support. I am therefore interested in getting the portable syntax implementation working on Biwa if possible.

Before I start, I am curious if anyone else has tried, would like to offer advice, or can provide guidance for eventually landing it as a patch to Biwa if I succeed.

Thanks!

Duplicate function

Hello,

element-append-child! and element-insert! are duplicates of the same function. Maybe you could deprecate one of the two?

Thanks.

How to deal with numbers?

Please give me a couple of code examples of how to deal with:

  • complex numbers
  • rational numbers
  • infinity
  • inexact numbers
  • etc...

Infinit loop using delay, force

I just tried some examples with the new delay and force functions but they produce infinitiy loops in the browser. Here is my example:

(define stream-car car)

(define stream-cdr
  (lambda (stm)
    (force (cdr stm))))

(define-syntax stream-cons
  (syntax-rules ()
    ((_ head tail) (cons head (delay tail)))))

(define make-stream 
  (lambda (seed proc)
    (letrec 
      ((stream-builder
         (lambda (n)
           (stream-cons n (stream-builder (proc n))))))
      (stream-builder seed))))

(define stream-item
  (lambda (str k)
    (if (= k 0)
      (stream-car str)
      (stream-item (stream-cdr str) (- k 1)))))

(define stream-map
  (lambda (f str)
    (stream-cons
     (f (stream-car str))
     (stream-map f (stream-cdr str)))))

(define print-stream
  (lambda (stm n)
    (cond
      ((<= n 0) (display "...")(newline))
      (else
       (display (stream-car stm))
       (display ", ")
       (print-stream (stream-cdr stm) (- n 1))))))

(define nat_zahlen (make-stream 0 (lambda (n) (+ n 1))))
(print-stream nat_zahlen 11)

This example works on https://bluishcoder.co.nz/jsscheme/ and should produce:

(print-stream nat_zahlen 11)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...

(complex? 123) should return #t

  • complex? should return #t for complex, real, rational, integer
  • real? should return #t for real, rational, integer
  • rational? should return #t for rational, integer

Allowing wrong number of arguments

I'm new to Scheme, so I don't know it this is allowed by the Scheme spec, but the Racket implementation in both R5RS and PrettyBig mode reports an error when using more arguments than needed.
Is this is by design, or a bug?

(define (func x y) (* x y))
(func 2 3 4 5 6) ; This returns 6, despite using more arguments than required.

Tried this in repl.it (BiwaScheme version 0.5.7) and biwascheme.org (version 0.6.1).

list? error

On certain lists with repeated entries, the list? predicate disagrees with other Scheme implementations, e.g., DrRacket and http://tryscheme.sourceforge.net/. See the session from http://www.biwascheme.org/ below.

BiwaScheme Interpreter version 0.6.1
Copyright (C) 2007-2010 Yutaka HARA and the BiwaScheme team
biwascheme> (list? (list 1 1))
=> #f
biwascheme>

Embedded jquery and underscore library in biwascheme-0.6.3.js

I've had some problems with jquery when trying biwascheme with other libraries loaded in the page. Is that perhaps because of the jquery and underscore in the biwascheme library? I'm wondering if that is conflicting with other libraries. Wouldn't it be better to put those in the node and bower package files and let the user of the library manage those dependencies?

(load) failing with newest release (16th Nov) - txt.replace is not a function

Hi, I know this was marked fixed two years ago, but it seems to have recurred in the newest release.

Here's the code I'm using, and the error:

HTML:

<script src="biwascheme.js">
(load "./test.scm")
(myfunc)
</script>

test.scm:

(define (myfunc)
(element-insert! "body" "Test"))

And this is the error in the JavaScript console:
TypeError: txt.replace is not a function
on line biwascheme.js:11575

This is on Firefox 25.0.1, the problem does not happen in the Webkit-based dwb browser, however.

Some functions are incorrectly converting nested lists

The following code:

(map (lambda (x) x) (list 1 2 (vector 3 4)))

Should return:

(1 2 [3 4]) (leaving the vector alone)

But is instead returning:

(1 2 (3 4)) (converting the vector into a list)

This is actually a deep problem in the codebase, caused by my refactoring in August:
kenpratt@6367a19
kenpratt@6c43488

Basically, there used to be a function named build_list that did a deep conversion, and everything else was shallow, but in the process of refactoring I changed List(...) to be deep and this many parts of the codebase were switched to deep conversion that should have been shallow conversion.

I've gone through the code carefully to figure out what behaviour I changed from shallow list conversion to deep list conversion and fixed it. Patch is here:
kenpratt@99e28ca

I've changed it so that:

List(1, 2, [3]) == (list 1 2 (vector 3 4))
array_to_list(1, 2, [3]) == (list 1 2 (vector 3 4))
deep_array_to_list(1, 2, [3, 4]) == (list 1 2 (list 3 4))

So the only time you get a recursive conversion is when you ask for it with deep_array_to_list.

"$ ./bin/biwas" does not load the development version of BiwaScheme

Hi,

I found ./bin/biwas does not load the development version of BiwaScheme (i.e. release/node_biwascheme.js.)

Before 25321cb , "$ ./node_modules/biwascheme/bin/biwas" loaded ./node_modules/biwascheme/lib/biwascheme.js. It is good to have a handy way to evaluate some expressions on the terminal.

@kenpratt: May I revert that commit? Or do you have any good idea to fix it?

It seems that we don't need .npmignore because the npm package (biwascheme-0.6.1.tgz) only contains package.json, bin/biwas, lib/.notempty and lib/biwascheme.js. (you can download it from http://search.npmjs.org/#/biwascheme )

LOAD fails with 0.6.1

bscm.html:

<html>
  <body>
    <script src="http://www.biwascheme.org/repos/release/biwascheme.js">
      (load "bscm.scm")
    </script>
  </body>
</html>

bscm.scm:

(define (f x) x)

On Firefox 11.0, bscm.html causes a syntax error. The following messages are printed on Web Console (Ctrl + Shift + K).

[19:25:14.288] 構文エラーです。 @ file:///C:/Documents%20and%20Settings/manabu/work/bscm.scm:1
[19:25:14.293] txt.replace is not a function @ http://www.biwascheme.org/repos/release/biwascheme.js:11575

R4RS and R5RS specify modulo and remainder rather than mod

Biwascheme implements the "mod" procedure but not "modulo" or "remainder."

R4RS and R5RS require:

remainder Scheme Procedure
Return the remainder of the numbers x and y.

(remainder 13 4) => 1
(remainder -13 4) => -1

modulo Scheme Procedure
Return the modulo of the numbers x and y.

(modulo 13 4) => 1
(modulo -13 4) => 3

Unexpected output on functions

I've been trying to build an n*n tic-tac-toe game with Biwascheme, and lately, I've been encountering this weird issue where several values are getting replaced by

#("argument" #("refer-global"  #"con
s" #("shift" 2 #("tco_hinted_apply"))))

and cause random errors when I test. I'm running them all using biwascheme 0.6.4 and Firefox 47

Two examples include:

(define (make-list n val)
   (if (zero? n)
       '()
       (cons val (make-list (- n 1)))))

and for a non-trivial example: this

Tested the above, and does not produce errors in Gambit-in-the-browser.

EDIT: Clarity, details and links

Bug in "define" scoping

The following session illustrates the bug:

BiwaScheme Interpreter version 0.6.1
Copyright (C) 2007-2010 Yutaka HARA and the BiwaScheme team
biwascheme> (define (f x) (define y x) x)
biwascheme> (f 3)
=> 3
biwascheme> y
=> 3

y should be undefined.

Chapter 19 R5RS compatibility - delay, force

I found: (delay expression), (force promise) and (make-promise (lambda () expression))
in the source code but are they already implemented in biwascheme?

I found a working implementation of those syntax elements in https://bluishcoder.co.nz/jsscheme/ but I have no idea how to extend biwascheme accordingly.

Would be a really help to have those functions for creating streams and similar concepts.

reactjs interop

I'm looking for example code that use libraries like reactjs. That is javascript libraries that are declare the view and patch the dom to render it.

Thanks!

Unexpected behavior with a user-defined list generator

I was writing a procedure that would take a string and output a list where all instances of param rep was replaced by param sub

Full code here

testing the code using the coimmand using the [repl](http://www.biwascheme.org./demo/repl.html] from biwascheme.org)
(replace-split "aeaeaeur" #\e #\a)

returned
(#\r #\a #\r #\a #\r #\a #\r #\r)

I tested this using other lists, and the result was the same, all of the characters not replaced with param sub got replaced with the last item on the string. I got the same results with numbers, letters and spaces.

I checked by manually going through the instructions in the code and applying them to the string example above, and got the expected result. I also verified this by running the same code using the repl at JsScheme, and at Gambit-js and all returned the expected results as described in the procedure.

Interpreter cycles on some errors and doesn't evaluate further input

Interpreter cycles on some errors and doesn't evaluate further input. For example:

biwascheme> (lambda x)
Error: Invalid lambda: (lambda x)
[USER]: undefined: Error: Invalid lambda: (lambda x)
[undefined]: undefined
biwascheme> (+)
Error: Invalid lambda: (lambda x)
[USER]: undefined: Error: Invalid lambda: (lambda x)
[undefined]: undefined

have to restart BiwaScheme to get rid of the error

biwascheme> (+)
=> 0
biwascheme> (if #t)
Cannot read property 'car' of undefined
[USER]: undefined: Cannot read property 'car' of undefined
[undefined]: undefined
biwascheme> (+)
Cannot read property 'car' of undefined
[USER]: undefined: Cannot read property 'car' of undefined
[undefined]: undefined

BiwaScheme Interpreter version 0.6.3.dev

error "x.cdr.to_array is not a function" for "(1 . 2)"

When I run a ill-formed expression

(1 . 2)

(not '(1 . 2) , which is correct syntax) on "Try it now" on the web page,
I get a error

x.cdr.to_array is not a function
[USER]: http://www.biwascheme.org/release/biwascheme.js: x.cdr.to_array is not a function

in red characters and the interperter stops.

I think that it is caused on 557th line of src/system/interperter.js , which is

        var expanded_cdr = BiwaScheme.array_to_list(
                             _.map(x.cdr.to_array(),
                                   function(item){ return expand(item, flag); }));

and that you should check if x.cdr.to_array is available.

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.