timoniq / laurelang Goto Github PK
View Code? Open in Web Editor NEWA pure logical, compact language / research. Further descendant TBA
Home Page: https://laurelang.org
License: MIT License
A pure logical, compact language / research. Further descendant TBA
Home Page: https://laurelang.org
License: MIT License
Proposed syntax to parse included/secluded boundaries of integer domains with complicated expressions including: variables, predicate calls, other domains.
int[] arr = [1, 2, 3];
int range = 0..(length of arr)>;
inner predicate call can be applied via additional logic variable or common predicate usage (..
and between
).
For example, generics are essential to work with by_idx
predicate at ease.
arr[1] = e;
Without generic you have to declare e
logic var universum which is redundant in most cases.
x = map([[[1,2], [3]], [[4, 5, 6], [7, 8]]], flatten{int[]})
flatten{int}
will bound int
to predicate generic T
.
predicate{T=int, P=string}()
Also such operations should be supported:
flatten_int ~ flatten{int}.
: ? married(person, person).
? married(p1_uid, p2_uid) {
db:Marriage(partner_id=p1_uid, partner2_id=p2_uid);
}%
? married(p1_uid, p2_uid) { married(p2_uid, p1_uid); }
$ InMarriage {
person(name, _) person_1;
person person_2;
} where {
married(person_1, person_2);
not({
divorced(person_1, person_2)
| dead(person_1)
| dead(person_2);
});
}
? InMarriage:repr(in_marriage) -> format("{in_marriage:name} is happily married with {partners_name}") {
person(partners_name, _) = in_marriage:person_2;
}
Consider a predicate flatten non trivial:
: ?flatten_nt(int[][]) -> int[].
?flatten_nt([]) -> [].
?flatten_nt([x]) -> x.
?flatten_nt(array) -> flattened {
flattened = append<int>(x, y);
y = flatten_nt(t);
linked(x, t) = array;
}
Predicate will fail if we try to instantiate array from flattened:
?- flatten_nt(x) = [1,2,3]
* too broad error *
to change this behaviour queries should be reordered
?flatten_nt(array) -> flattened {
linked(x, t) = array;
y = flatten_nt(t);
flattened = append<int>(x, y);
}
the idea is to do that automatically
qcontext may have order field (a vector with order calculated on scope entering)
[2, 1, 0]
$ structure {
string name;
'T' field1;
'T'[] field2;
}
Expected and real behaviour:
query as_boolean(prime, x) = @false
must produce only natural solutions for x
due to prime signature ?prime(natural)
.
but it also produces integer results.
How to reproduce:
as_boolean(prime, x) = @false
-- to fix 'x' can be predefined
x ~ natural, as_boolean(prime, x) = @false
laurelang: dev
OS: unix
Let's consider an example:
predicate1(predicate2(A))
Predicate predicate2
must have response argument for relation above to be valid.
Proposed syntax is to mark argument different from response one taking part in relation as $
.
Considering predicate signature : ?predicate3(int, int)
. We can build a relation:
predicate1(predicate3($, 42))
Currently laurelang resolves only one generic type.
Using this example:
?- {jealous(x, y) -> jealous(y, x)}, jealous(var1, var2)
var1 = "vincent",
var2 = "marcellus";
var1 = "marcellus",
var2 = "vincent";
var1 = "vincent",
var2 = "marcellus";
var1 = "marcellus",
var2 = "vincent";
Two solutions are excess. They are created due to excess choicepoint creation in set.
Variables in choicepoint (x
and y
) have no references in future reasoning so choicepoint is redundant.
I don't like this solution because sometimes choicepoints are created to emulate a loop and this solution constrains this.
Proposed syntax:
&{jealous(x, y) -> jealous(y, x)}
Set will use its own context with no variables tracked. The terminal statement of the evaluation will be the terminal statement of the set. After that the control will be yielded back to the previous context.
Different expressions may have different weight.
API for expression specific weight coefficients / calculators should be implemented.
(map_abs(arr) = x) ~ (map(arr, absolute) = x)
: ?transpose('T'[x][y]) -> 'T'[y][x].
To make size variables invisible in predicate case's scope their names should start with underscore, such as _x
.
Implementation. After such cast matrix will gain matrix-confirmation.
Builtin union template โ external datatype sets union operator.
union<'T', ...>
optional<'T'>
s = 1 .. 3;
optional<s> a;
Declaration of a optional<'T'>
template
none_T ~ @{none}.
optional<'T'> = union<'T', none_T>
Solutions: @none
, 1
, 2
, 3
.
: ?transpose_array('T'[][]) -> optional<'T'>[][].
todo
Example:
: ?divmod(int, int) -> ${int div; int mod}.
To implement non-monotonous predicates, cutting endpoint could be implemented.
: ?predicate(int) -> int.
?predicate(42) -> 1%
?predicate(x) -> 2 when even(x).
case with 42 -> 1
is a case of cut. Other cases won't be checked if it succeeds.
In weighted search case of cut should be avoidable with loss, its weight should be calculated separately, see #14
Method can be implemented for any kind of datatype.
: ?increment(int) -> int.
?increment(i) -> i + 1.
First argument is automatically assigned to the current instance.
int boo = 2;
message( repr of boo:increment() );
// 3
Methods of atomic instances are freely accessible from nested instances.
int[] shelf = [1, 2, 3, 4..5];
message( repr of shelf:increment() );
// [2, 3, 4, 5]
// [2, 3, 4, 6]
Currently type schemes can be implemented like this:
: #some_constraint('T') -> 'T'[].
#some_constraint(_) -> _.
(see @/abstract package)
The case for the constraint is to some extent looks redundant, so some shortcut maybe useful.
: ##some_constraint('T') -> 'T'[].
Sometimes predicate may have multiple meanings and an ability to set non-logical determinators when calling the predicate or constructing new bound predicate instance would be useful.
Queryset bound to logical names.
[ experimental proposed syntax: ]
!use <prime>.
-- `x` and `y` are meant to be bound names as predicate determinators
g ~ Goal{x, y};
g = {
int p = 1..15;
prime(p);
x sized_bagof p = y;
x >= 2;
};
g?;
message(
format("x = {g:x}, y = {g:y}")
);
inline version
Goal{x, y} {
...
}(a, b);
New notation for predicates:
: #lt(int) -> int.
#lt(x) -> y when y < x.
int[] a = [1,2,3,4,5].
a = lt(5)[].
num = 1 .. a[3];
num[][] list;
s = no_repeat[];
Predicate usage in declarations and automatic linked vars resolution.
: ?person(string name, natural age) -> ID.
!datalink([person], "...").
: ?reason_field(string).
?reason_field("reason1").
?reason_field("reason2").
: ?some_predicate(person, person).
?some_predicate(person p1, person(name, _) _).
$ ... {
person(name, _) person1;
person(_, _) person2; -- or `person person2`
reason_field reason;
}
Creating new logical variable as a substring of s
using pattern:
string s = "hello, world!";
s = format("hello, {something}!")
&all something { something = "world" };
Creating formatting
:
formatting p = "hello, {smt}!";
smt = "abc" | "def";
format(p) = s;
message(s);
In the predicate:
: ?pred(string) -> string.
?pred(s) -> format("wrapped {s}").
pred("hello") = "wrapped hello";
pred(x) = "wrapped abc";
x = "abc";
pred(x) = "wrapped" -> fail();
New trace message example:
in recursive call:
pred(a, b, c)
in Imaging:
a ~ (?(int, unk))
in Predicate Primitive:
(?(int, unk))
^ error: undefined( unk )
Progress:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.