GithubHelp home page GithubHelp logo

`member` usage about julog.jl HOT 5 CLOSED

ztangent avatar ztangent commented on May 20, 2024
`member` usage

from julog.jl.

Comments (5)

hiiroo avatar hiiroo commented on May 20, 2024

I just check the tests/lists, and member defined there as follows;

clauses = @julog [
    member(X, [X | Y]) <<= true,
    member(X, [Y | YS]) <<= member(X, YS),
    append([], L, L) <<= true,
    append([X | XS], YS, [X | ZS]) <<= append(XS, YS, ZS),
    reverse(X, Y) <<= reverse(X, [], Y),
    reverse([], YS, YS) <<= true,
    reverse([X | XS], Accu, YS) <<= reverse(XS, [X | Accu], YS)
]

and, a test case as follows;
resolve(@julog(member(banana, [avocado, banana, coconut])), clauses)[1] == true

It only works when member explicitly defined in the clauses. I thought it was a default feature?

from julog.jl.

ztangent avatar ztangent commented on May 20, 2024

I believe member is a default feature of most variants of Prolog, but it's not implemented that way in Julog! Currently the only built-in predicates that Julog supports are those that can't really be defined as clauses (cut, apply, etc.). This could change in the future, but I would like to have a more modular and performant way for users to load libraries of clause definitions (as is done in Prolog), rather than building everything in.

from julog.jl.

hiiroo avatar hiiroo commented on May 20, 2024

I see, that's a good design approach. Actually, I was confused by the docs, where I read "member(b, [a, b, c]), are parsed in the same way as Prolog." I though member is there by default. I believe stating it explicitly could be better.

Other than that, loading user defined types could also be good. Such as units from Unitful.jl. So that constant can be defined with a generic type such as Constant{T} ?

using Unitful
using Julog
w = @julog [ meter(1u"m") ]

from julog.jl.

ztangent avatar ztangent commented on May 20, 2024

Happy to change the README to make that more clear!

As for user-defined types like units, this is definitely possible if you manually construct constants using Const. However, the parser defined by the @julog macro doesn't really support calling other macros within it, and supporting this would take a fair amount of work. You're welcome to try and make that change if you would like!

(Note that making Const a parametric types seems to slow things down for some reason, so it's something I haven't done in this library.)

from julog.jl.

ztangent avatar ztangent commented on May 20, 2024

Added the clarification to the README in 07bb2f1. I'm marking this issue as closed -- feel free to open a separate issue or PR to extend the parser to support user-defined types!

from julog.jl.

Related Issues (13)

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.