Login
000-016.th1ish at [151811b651]
Login

File th1ish/unit/000-016.th1ish artifact 3eda37f1a6 part of check-in 151811b651


/**
    Experimenting with "conventional" func(call) syntax.
*/
if{'function' === (typename 1.0.toInt())}{
    $print "Conventional func(call) syntax is disabled." \
        "When using the demo/test shell, use the -c flag to enable it."
    return
}
print("Conventional func(call) syntax is enabled.")

//$print 'function' '===' typename 1.0.toInt()

1 && scope {
    var ok = false
    scope {
        var cache = object{}
        proc{}{
            assert cache
            ok = true
            assert ok
        }.importSymbols('cache', 'ok')
    }()
}

1 && scope {
    $print 1 2 3 4 5
    [print 1 2 3 4 5]
    print(1,2, 3, 4, 5)
    
    $print 1 2; print(3,4)
    ($print 1 2) print(3,4)
    [print 1 2] print(3,4)
    print(1, 2) print(3,4)

    var x = "hi"
    assert "hiho" === x.concat("ho")
    // seemingly unresolvable ambiguity:
    assert "hi123" === x.concat(1,2,3)
    // ===> $print (x.concat (1,2,3))
    //Doh:
    //$print (x.concat) (1,2,3) 
    // ===> $(print (x.concat)) (1,2,3)
    // ===> 3
    //$(print) (x.concat) (1,2,3) "?"
    // ==> $(print) ((x.concat) (1,2,3)) "?"

    $print x.concat (1,2,3)

    assert 'hiobjsubstr' ===
        object{sub:object{str: x}}.
            sub.str.concat ('obj','sub','str')
}


1 && scope {

    print ["HI".toLower].prototype
    assert "hi" === [["HI".toLower].toString]
    assert "hi" === "HI".toLower().toString()
    assert 'hi' === "HI".toString().toLower().toUpper().toLower()
}

1 && scope {
    /* Ensure that 'this' is translated properly when
       chaining method calls... */
    const ob2 = object{
        g:proc(){
            return this
        }
    }
    const obj = object {
        f:proc(){
            return this.g
        },
        g:proc(){
            print("G!", this);
            return this
        },
        h:proc(){
            return ob2
        }
    }

    //$print obj.f() obj.g
    assert obj.g === obj.f()
    assert obj.g === [obj.f]
    $print 'f =' obj.f ', g =' obj.g ', f() =' obj.f() ', g() =' obj.g()
    $print '[[obj.f]] =' [[obj.f]] ', f()() =' obj.f()()
    assert obj.g === [[obj.f]]
    assert obj === obj.g()
    assert ob2 === obj.h().g()

}

1 && scope {
    var obj = object{}
    assert 'CWAL_SCR_SYNTAX' === [catch{obj.foo(undefined,2,null)}.codeString]
    assert 'CWAL_SCR_SYNTAX' === [catch{obj.foo ()}.codeString]
    assert undefined === eval {obj.foo,()}
    // Ensure that short-circuting of func call arguments
    // DTRT...
    0 && $print this must not cause an error
    true ? 1 : $print(this must not cause an error)
}


scope {

    const f = proc(){
          print(a,b,c)
    }.importSymbols(
        'print',
        object{
          a: "hi", b: "world", c:"!"
        }
    )
    f()
}

var rc = "Done with ".concat(__FILE,'.')
print(rc)
return rc