daonode: a functional logic solver with built in parser.

81 views
Skip to first unread message

Simeon Chaos

unread,
May 24, 2013, 11:08:16 PM5/24/13
to nod...@googlegroups.com
I have released daonode on npm and https://github.com/chaosim/daonode
To use daonode, just:
npm install daonode

Dao is a functional logic solver, unifying code with data, grammar with program, logic with functional, compiling with running.
Daonode is a porting, rewriting and upgrading from python to coffeecript(so just javscript) of the dao project.
What would happen when lisp meets prolog in javascript?  

some examples (the code is extracted from the coffeescript tests):

    "test builtin function": (test) ->
        add = fun(2, (x, y) -> x+y)
        test.equal  solve(add(1, add(1,1)), 3

    "test macro": (test) ->
        orpm = macro((x, y) -> orp(x, y))
        test.equal  solve(orpm(fail, print_(2))), null

    "test macro tofun": (test) ->
        orpm = macro(2, (x, y) -> orp(x, y))
        test.equal  solve(orpm(print_(1), print_(2))), null
        test.equal  solve(tofun(orpm)(print_(1), print_(2))), null
        test.equal  solve(tofun(orpm)(quote(print_(1)), quote(print_(2)))), null

    "test proc,aka online function in dao": (test) ->
        a = proc(0, 'a', () ->
          i = 0
          add(1, 2))
        test.equal solve(a()), 3

    "test eval_ quote": (test) ->
        exp = if_(1, 2, 3)
        test.equal  solve(quote(exp)), exp
        test.equal  solve(eval_(quote(exp))), 2

    "test lisp style catch/throw ": (test) ->
        test.equal  solve(catch_(1, 2)), 2
        test.equal  solve(catch_(1, throw_(1, 2), 3)), 2
        test.equal(solve(block('foo', protect(break_('foo', 1), print_(2)))), 1)
        test.equal(solve(block('foo', protect(break_('foo', 1),  print_(2), print_(3)))), 1)

    "test callcc2": (test) ->
        a = null
        solve(begin(callcc((k) -> a = k), add(1, 2)))
        test.equal a(null), 3

    "test callfc": (test) ->
        a = null
        x = vari('x')
        x.binding = 5
        solve(orp(callfc((k) -> a = k), add(x, 2)))
        test.equal a(null), 7

    "test quasiquote": (test) ->
        test.equal solve(qq(1)), 1
        a = add(1, 2)
        test.deepEqual solve(qq(a)), a
        test.deepEqual solve(qq(uq(a))), 3
        test.deepEqual solve(qq(uqs([1,2]))), new UnquoteSliceValue([1,2])
        test.deepEqual solve(qq(add(uqs([1,2])))), a

    "test block break continue": (test) ->
        test.equal  solve(block('a', 1)), 1
        test.equal  solve(block('a', break_('a', 2), 1)), 2
        test.equal  solve(block('a', block('b', break_('b', 2), 1), 3)), 3
        a = vari('a')
        test.equal  solve(begin(assign(a, 1),  block('a', if_(eq(a, 5), break_('a', a)), inc(a), continue_('a')))), 5

    "test logic predicate": (test) ->
        test.equal(solve(andp(unify(a, 1))), true)
        test.equal  (solve(andp(unify(a, 1), unify(a, 2))), false)
        test.equal  solve(orp(andp(unify(a, 1), unify(a, 2)), unify(a, 2))), true
       test.equal  (solve(orp(findall(orp(print_(1), print_(2))),)
                               print_(3))), null
       test.equal  (solve(findall(once(orp(print_(1), (print_(2)))))), null)

    "test logic rule": (test) ->
        r = rule(2, (x, y) ->
          [[x,y], 1, null])
        test.equal  solve(r(1,1)), 1

    "test parser builtins": (test) ->
        test.deepEqual  (solve(begin(settext('ab'), any(char(_), result, _), eoi, result)), ['a', 'b'])
        test.equal  (solve(parsetext(begin(some(char(_)), char('c'), eoi), 'abc')), true)
        test.deepEqual  (solve(begin(parsetext(seplist(char(_), {sep:char(','), times:n, result:result, template:_}), 'a,b,c'), result)), ['a', 'b','c'])
        test.deepEqual  (solve(begin(parsetext(andp(seplist(char(_), {sep:char(','), times:n, result:result, template:_}), char(','), char('b'), char(','), char('c')), 'a,b,c'), result)), ['a'])

Simeon Chaos

unread,
May 27, 2013, 10:27:34 PM5/27/13
to nod...@googlegroups.com
I have released some documents on https://github.com/chaosim/daonode/wiki

mscdex

unread,
May 27, 2013, 10:49:00 PM5/27/13
to nodejs
On May 24, 11:08 pm, Simeon Chaos <simeon.ch...@gmail.com> wrote:
>         add = fun(2, (x, y) -> x+y)

Why not use `func.length` instead of passing in the arity manually?

曹星明

unread,
May 27, 2013, 11:55:35 PM5/27/13
to nod...@googlegroups.com
I don't know "func.length" before. Thank you for your advice.  I would allow to use func.length as the default case, and manually passing in if func.length is not expected. 


2013/5/28 mscdex <msc...@gmail.com>
On May 24, 11:08 pm, Simeon Chaos <simeon.ch...@gmail.com> wrote:
>         add = fun(2, (x, y) -> x+y)

Why not use `func.length` instead of passing in the arity manually?

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/1tphwNKm_6I/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Simeon Chaos

Simeon Chaos

unread,
Jul 29, 2013, 8:15:01 AM7/29/13
to nod...@googlegroups.com
I have release daonode 0.2.0. Now daonode can compile expression to javascript.

what'snew in daonode 0.2.0
* now daonode can compile expression(similar to lisp's sexpression) to javascript.
* stuffs in /lib is for the compiler
* Currently no document is written for the comiler, please refer to the document for the interpreter.
* original stuffs for the solver is moved to /lib/interpreter, and they still work.
* all tests is moved /test
* add .travis.yml and use travis-ci.org for Continuous integration, see https://travis-ci.org/chaosim/daonode
Reply all
Reply to author
Forward
0 new messages