Code Monkey home page Code Monkey logo

Comments (1)

foxfriends avatar foxfriends commented on September 23, 2024

Better yet, stealing the templates/meta-predicates idea from Prolog but making the syntax more explicit gives a more powerful feature. The problem with Prolog's version is that there really isn't a way to syntactically differentiate a template passed to a higher-order function from a regular pattern. By either separating the template parameters into a separate parameter list, or using a different syntax for them, we could avoid this problem.

A few possibilities:

Put templates into their own arguments list, requiring to reference them with $.

all<_, _>([]).
all<P, C>([X, ..Xs]) :- $P =:= X, $C -> all<$P, $C>(Xs).

allGt3(Xs) :- all<A, (A > 3)>(Xs).

Prefix the template pattern with $, and require the template argument to also be prefixed (also with $). Note that reusing a template argument requires two $ (one for the reference and one for the syntax).

all($_, $_, []).
all($P, $C, [X, ..Xs]) :- $P =:= X, $C -> all($$P, $$C, Xs).

allGt3(Xs) :- all($A, $A > 3, Xs).

Could use any separator here, not necessarily the ugly #. Maybe remove named parameters (#31) and then use the :, or use a | instead (if that won't cause problems with expressions).

all(_, _ # []).
all(P, C # [X, ..Xs]) :- #P =:= X, #C -> all(#P, #C, Xs).

allGt3(Xs) :- all(A, A > 3 # Xs).

Might be a bit more difficult, but more powerful:

all($_, $_, []).
all($P, $C, [$P, ..Xs]) :- $C -> all($P, $C, Xs).

allGt3(Xs) :- all(A, A > 3, Xs).

from lumber.

Related Issues (20)

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.