Giter Site home page Giter Site logo

yhara / biwascheme Goto Github PK

View Code? Open in Web Editor NEW

This project forked from biwascheme/biwascheme

88.0 88.0 3.0 5.16 MB

yhara's private clone of BiwaScheme. The official one is:

Home Page: https://github.com/biwascheme/biwascheme

License: MIT License

Shell 0.05% JavaScript 91.56% Scheme 8.39%

biwascheme's People

Contributors

erjiang avatar jasonfruit avatar kenpratt avatar masatake avatar yhara 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

rbarraud wbcook

biwascheme's Issues

Error checking for invalid syntax

Currently, things like (), and (lambda) work, but they shouldn't (reference implementation Chez Scheme gives invalid syntax (lambda), for example).

While things like (if) and (define xif if) are uncaught errors that cause BiwaScheme to stop working. (Chez Scheme gives invalid syntax if.)

Stop auto-converting `undefined'

1. rewrite library functions which return `undefined’ to return undef
2. rewrite define_libfunc not to convert `undefined’ nor`null’
3. add define_libfunc2 (TODO: better name) which does not raise for `undefined’/`null’

repl doesn't work in firefox

I recently tried the biwascheme repl in firefox. The hello world sample code produces this error:

$(this.dumparea) is null

I have tried this in firefox 3.5 on windows, and firefox 3 on linux.

I remember that the previous time I tried it (a few months ago) it didn't work in firefox either, but it was ok in Internet Explorer.

there is no gensym function in scheme

gensym implementation could look like this:

BiwaScheme.gensymcount = 0;
BiwaScheme.define_libfunc('gensym', 0, 0, function(args) {
    with(BiwaScheme) {
        return new Sym('#' + gensymcount++);
    }
});

I've found that there is BiwaScheme.gensym function but it's not accessable from scheme.

BiwaScheme.define_libfunc('gensym', 0, 0, function(args) {
    return BiwaScheme.gensym();
}

Broken pair detection for assoc, etc.

In line 14404 and 14421 of biwascheme.js, assoc checks for the presence of a pair by running x.car.car though an if(...) statement. This presents a type 2 error in cases where the car of the pair is anything that would return false, like 0 or #f.
I fixed it in my tests by replacing:

if(x.car.car) {
 ...
}

with

if(typeof(x.car.car) != "undefined") {
 ...
}

cadr on list with 1 element.

When applying functions like cadr to a list, for which it should not work (and raise the message "Error: Attempt to apply car on nil"), instead the result is "[BUG] library function `cadr' returned JavaScript's undefined". I guess this is a low-priority bug, since it presents itself only when the input is incorrect, but nevertheless I doubt it is what is expected.

The bug also appears when calling caddr and cadddr with similar examples.

Example:
(cadr '(1))
[BUG] library function `cadr' returned JavaScript's undefined

Version is 0.5.7, as seen on repl.it

Wrong scoping

[UPDATE] Updated to general scoping issue.

(define x 1) 
(print x)             ;;1
(define (i n)
    (define x 2)
    n)
(print x)             ;; #<undef>
(i 1)
(print x)             ;; 2

http://repl.it/BuI/1

And this is a general block scoping issue, its not confined to define.
No matter how deep you nest blocks, block structure definitions always escape to the global scope.

define-macro strange behavior

If you use undefined variable in macro, when you use it it will return javascript undefined.
eg.:
(define-macro (foo x) y)
(foo 10) ; this return nothing
above throw "[BUG] library function `macroexpand' returned JavaScript's undefined"
(macroexpand '(foo 10))
This bug makes very dificult to debug macros.

'list-ref' implementation bug

I think it affects more than just list-ref, but bounds checking is broken:

biwascheme> (list-ref (iota 9) 9)
[BUG] library function `list-ref' returned JavaScript's undefined
biwascheme> (list-ref (iota 9) 11)
d is undefined

In the most recent version, the error is the same, though the variable is named 'o' instead of 'd'. These interactions were taken from the interpreter on biwascheme.org.

It's pretty clear what's causing this in the implementation -- it's just a case of some edge cases slipping through the implementation (returning x.cdr without checking if it is defined, for example).

(define (f) (lambda args args)) throws error

error on Opera:

Statement on line 937: Type mismatch (usually non-object value supplied where object required)
Backtrace:
  Line 937 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
              ret = this.find_free(body, b.set_union(vars.to_set()), f);
  Line 959 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
                set = set.set_union(this.find_free(p.car, b, f));
  Line 930 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
              ret = this.find_free(x.cdr, b, f); //(ignores improper list)
  Line 1089 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
                var free = this.find_free(body, proper.to_set(), f); //free variables
  Line 1163 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
          return this.compile(expr, [new Set(), new Set()], new Set(), new Set(), ["halt"]);
  Line 1168 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
        return (new Compiler).run(expr, next);
  Line 1686 of linked script http://www.biwascheme.org/repos/lib/stackbase.js 
          var opc = Compiler.compile(obj);
  Line 8 of inline#1 script in http://www.biwascheme.org/repos/repl.html: In function bs_eval 
        var opc = biwascheme.compile(str);
  Line 1 of function script  
    bs_eval()
...

Provide functions doumentation.

There will be nice if funtions in scheme have documentations.

(documentation 'function)

could return documentation string. It could be kept in BiwaScheme.Symbols association array.

BiwaScheme.define_libfunc function could have fifth parameter which hold documentation string.

There is also need to update interpreter and compiler to put first element, after argumets, from procedure definition, if it's string, to BiwaScheme.Symols array for specific procedure name.

Here is the code for extracting documentation from scheme procedure. doc variable holds documentation string and name variable is name of the symbol.

    var tokens = (new BiwaScheme.Parser(str)).tokens;
    if (tokens[1] == "define") {
        var doc = "";
        var name = ""
        if (tokens[2] == "(") {
            //procedure definition
            start_scan = 2;
            name = tokens[3];
        } else if (tokens[3] == "(" && tokens[4] == "lambda") {
            //lambda expresion
            start_scan = 5;
            name = tokens[2];
        }
        
        for (i=2; i<tokens.length-1; ++i) {
            if (tokens[i] == ")" && tokens[i+1].match(/".*"/)) {
                doc = tokens[i+1];
            }
        }
    }

But I don't know where to put it.It could be done with something like:

BiwaScheme.Symbols[name].doc = doc;

The documenation function should look like this

BiwaScheme.define_libfunc('documentation', 1, 1, function(args) {
  if (typeof args[0] == BiwaScheme.Symbol) {
    name = args[0].to_write();
  } else if (typeof args[0] == "string") {
    name = args[0];
  }
  return typeof BiwaScheme.Symbols[name] != "undefined" && BiwaScheme.Symbols[name].documentation() || BiwaScheme.udef;
}

Strings should not be primitive values

In BiwaScheme,
(eq? "hi" "hi") => #t

but should be #f, since strings should be heap-allocated objects in usual Schemes. This can be solved by making a BiwaScheme String object to take advantage of native JS ==. Additionally, this allows for mutable strings because the String object's wrapped value can simply be replaced.

to_write takes too much time for big objects

example:
(+ 1 (lambda ()))

will stop the browser trying to serialize all the elements of the closure array.

The same thing happens when giving wrong typed big object to a function call.
Maybe we should make to_write2 (or something) which snips the output.

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.