Comments (1)
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)
- Non-record/list values in record/list tail position
- Document the language
- Performance improvements HOT 2
- Bug in record tails through calls?
- Record/list indexing HOT 1
- Record update
- Make the Lumber instance Sync/Send
- Cannot glob import from a module in a library
- Singletons are not detected in facts
- Better exporting
- Globbed imports get re-exported privately
- Failing test
- Don't use the AST for evaluation
- CLP(Z) and CLP(B) implementation
- Standard Library
- Unification with records grammar issue
- Use less boxes
- Opt-in occurs check HOT 1
- Predicate guards
- Incorrect alias loop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lumber.