« first day (210 days earlier)      last day (2056 days later) » 

3:04 AM
What is the order of proving things? From left to right?
 
3:16 AM
I just found a faster way to convert to/from decimal: use @P as the codepoint finder
 
 
4 hours later…
7:09 AM
@LeakyNun "Split at character, split into size, split into lengths (can be grouped together by overloading)"
Can you give an example for each of the behavior you want?
 
7:30 AM
@LeakyNun btw string predicates are called string predicates because they are operations that are most common on strings (same for math predicates)
but most also work on lists or integers too
 
7:52 AM
Denote @s to be the new splitting operator
The following would be true
"abcb":"b"@s["a":"c":""]
"abcdef":2@s["abc":"def"]
2:"abcdef"@s["ab":"cd":"ef"]
I left out edge cases for your freedom
@Fatalize
 
8:05 AM
the third one is basically n-chotomize right?
 
the second one
 
right
 
8:18 AM
Although the third one is basically zipped second one
 
 
4 hours later…
11:57 AM
@LeakyNun I thought about implementing curtail before, the only problem is coming up with a sensible name for it
Right now there is k, n, q and u available
Or I could use t for that (trim) and u to get the last element (ultimate)
but that would obviously break previous answers
 
12:42 PM
@Fatalize kurtail
 
@LeakyNun ಠ_ಠ
Quurtail
 
@Fatalize nkurtail
cUrtail
 
1:25 PM
@LeakyNun I guess I could call it unappend
 
@Fatalize uh, speaking of that:
where the hell is append?
 
:[C]c
stop annoying me with that :p
 
@Fatalize Nope.
 
@LeakyNun Power of 2
Power of 10
example?
 
1:53 PM
@LeakyNun I implemented @w for writeln, which replaces w@Nw
(I mean the latter still works it's just longer)
 
@Fatalize 3@d1000
10@b1024
@Fatalize Nice, I didn't even request it xd
Added 3 requests, all random @Fatalize
 
@LeakyNun Acknowledged
@LeakyNun So a thing that generates powers basically?
 
@Fatalize yep
Oops, I meant $d and $b instead of @d and @b
 
what's the most commonly used direction, 3$d1000 or 1000$d3
the first one probably?
 
@Fatalize j'y pense aussi
 
2:03 PM
je*
 
thanks
 
j'y would be if you're thinking about a particular thing
not for "I think so"
 
I see
 
3
A: Fix my IPv4 address's missing periods

Leaky NunBrachylog, 110 bytes :ef:{".",@N.|.}ac:3f:{@n:"."rz:cacb.}a. ,4yeN,?:N:6i.@nMl4,M:{:7&<256}a ~c[A:B]h:@N:Bc. :ef:{,"0":"9"y:.m?}ac. Try it online!

That seems damn long
 
@Fatalize 2nd line: insert newlines so that there are 3 newlines
4th line: string to integer
1st line: replace dots with newlines, call 2nd line, replace newlines with dots
because there is not a way to split at dots
 
2:07 PM
there is
but not yet
:p
 
alright
Help, why does prolog keep matching the same pattern after I caused it to fail
 
wat
 
maybe I didn't cause it to fail
how do I negate something
I used \+
 
\+ is "it is impossible to prove"
which is negation in Prolog
 
What if I proved it?
 
2:10 PM
then \+ is false
 
Ok, I think I identified the problem, wait
Brilliant
P07 KO
a([],[]).
a(S,[S]):- \+is_list(S).
a([S],[S]):- \+is_list(S).
a([H|T],L):-
  a(H,Hf),
  a(T,Tf),
  append(Hf,Tf,L).
Let me try to remove the 3rd clause
 
I take it that this is a deep append predicate?
 
Yes
 
note that \+ is_list(S) is false if S is a free variable
wait
no it's not
nevermind
 
a([],[]).
a(S,[S]):- \+is_list(S).
a([H|T],L):-
  a(H,Hf),
  a(T,Tf),
  append(Hf,Tf,L).
This works
@Fatalize Then what is it?
 
2:16 PM
it's true
well
 
Alright
 
is_list for a free variable is false so \+ makes it true
 
Can I write it in a way that would not produce a(b,[b]).?
 
which is a non-pure behavior of is_list because that makes it seem as if lists don't exist
@LeakyNun what do you mean?
 
@Fatalize I mean, the current approach makes non-lists flatten to be lists
 
2:21 PM
well if it's not a list is it even defined what the result should be?
 
It shouldn't be defined since the domain of flatten should be lists
This is throwing me syntax error
a([],[]).
a ([H|T],L):-
  (is_list(H),a(H,Hf);Hf=[H]),
  a(T,Tf),
  append(Hf,Tf,L).
on the third line
never mind
@Fatalize Halp
a([],[]).
a([H|T],L):-
  (is_list(H),a(H,Hf);Hf=[H]),
  a(T,Tf),
  append(Hf,Tf,L).
?- a([b,[c,[d,e]],f],X).
X = [b, c, d, e, f] ;
X = [b, c, [d, e], f] ;
X = [b, [c, [d, e]], f].
 
that's expected
 
Why?
 
the ; leaves a choice point so if you backtrack it will try Hf = [H] instead of a(H,HF)
 
Oh, right
 
2:25 PM
a([],[]).
a([H|T],L):-
  (
    is_list(H)
    -> a(H,Hf)
    ;
    Hf = [H]
  ),
  a(T,Tf),
  append(Hf,Tf,L).
Here ;)
 
@Fatalize Here?
I don't see any difference
 
the ->
 
Oh, thanks; it worked
 
the -> basically means and like the comma but removes the choice point created by the ;
 
so -> prevents backtracking
 
2:26 PM
only inside the parenthesis
 
only works on the immediate ;?
 
! removes all choice points of the current rule
 
what if there are two semilcolons after it?
 
only removes the first
you can try by adding ; write(test) after the Hf = [H]
 
I see, thanks
 
Wait, it's the same in Brachylog?
 
in Brachylog there is `
which does what *-> does in Prolog
and there is ! like ! in Prolog
 
What does *-> do?
Will you implement split? That doesn't seem difficult
seeing that you already have split by newlines
 
like -> but you can still backtrack on the choice points in the if part
 
I see
 
2:31 PM
note that if you don't have -> like in Brachylog for example
you can do that instead
a([],[]).
a([H|T],L):-
  (
    is_list(H),
    a(H,Hf)
    ;
    \+ is_list(H),
    Hf = [H]
  ),
  a(T,Tf),
  append(Hf,Tf,L).
 
Thanks
And what the ****, Brachylog was written in Java?!
 
originally yes
the parser was
 
Ridiculous
 
and it generated Prolog code that you then had to run in Prolog's REPL
At that time I wasn't confident enough to write the parser in Prolog
didn't think I could do it
 
@Fatalize CMC: fast_pow in prolog
(Don't use the built-in one)
 
2:33 PM
As it turns out it only took me a few days to make most of it work
@LeakyNun Just look at the code for split_lines
 
@Fatalize I looked at it
so you just implemented split
and hardcoded lines
 
Good thing I looked at split_lines again
with my last commits I reintroduced a bug that I had fixed
because I used old code…
 
@Fatalize Félicitation?
 
+s
 
alright thanks
@Fatalize What about this?
  (
    is_list(H),
    a(H,Hf);
    Hf = [H],
    !
  )
 
2:39 PM
doesn't work
(
    is_list(H),!,
    a(H,Hf)
    ;
    Hf = [H]
  ),
this does but there's no reason to use ! when you can use ->
 
@Fatalize thanks
 
generally you don't want to use ! if possible
@LeakyNun fixed
 
what if I have if(pred0){pred1,pred2}else{pred3,pred4}?
 
pred0 -> pred1,pred2 ; pred3,pred4
 
ok thanks
do variables defined locally share?
I defined a variable at pred1, can pred2 use it?
 
2:44 PM
yes
 
Sorry, I meant pred3 instead of pred2
 
Yes too
wait
 
ok
 
no
if it's in pred1 and somehow something fails so that you end up in pred3
then the variables available are the one that were available right after pred0 is done
as if pred1, pred2 never existed
 
Thanks
Do you have any idea how Prolog assigns the numbers to the free variables?
Just their indices in the stack?
compress([],[]).
compress([S],[S]).
compress([H,I|T],Y):-
  append([I],T,IT),
 (H=I ->
    compress(IT,Y)
   ;
    compress(IT,Temp),append([H],Temp,Y)
  ).
P08 KO
?- compress([a,a,a,a,b,c,c,a,a,d,e,e,e,e],X).
X = [a, b, c, a, d, e] ;
false.
 
 
1 hour later…
4:05 PM
@Fatalize This is my implementation of to_base:
a(X,B,L):-
   X<B -> L=[X]
   ;
   divmod(X,B,Q,R),a(Q,B,K),append(K,[R],L).
where X is the number to be converted, B is the base, L is the resulting list.
 
4:32 PM
@LeakyNun the thing is, if I were to implement base conversion it would be cool that it would still be integers that you can sum multiply etc. etc.
 
@Fatalize That's true
 
but that would take some effort
 
And I don't know of a language who implements this
You could be the first
to create a whole new number type
The question is: what difference does it make?
You could multiply them before converting
 
 
1 hour later…
5:36 PM
@Fatalize How would I code it so that I could find X given B and L?
You said ideally that should be possible.
 
n_base_digits(Expr, Base, Ds) :-
   Base #> 1,
   Ds = [_|_],
   N #=  Expr,
   N #>= 0,                                   % N is non-negative
   n_base_ref_acc_digits(N, Base, Ds, [], Ds).

n_base_ref_acc_digits(N, Base, Ref, Ds0, Ds) :-
   zcompare(Order, N, Base),
   order_n_base_ref_acc_digits(Order, N, Base, Ref, Ds0, Ds).

order_n_base_ref_acc_digits(<, N,    _, [_]   , Ds0,   [N|Ds0]).
order_n_base_ref_acc_digits(=, _,    _, [_,_] , Ds0, [1,0|Ds0]).
order_n_base_ref_acc_digits(>, N, Base, [_|Rs], Ds0, Ds) :-
 
@Fatalize What is #=?
 
Constraint equals from CLPFD
 
No, that isn't Prolog
Can it be done in Prolog?
 
... that's Prolog
 
5:40 PM
Can it be done in SWI-Prolog?
Isn't CLPFD a bunch of add-ons
 
that's SWI-Prolog
CLPFD is just a library
 
I don't have #
 
:- use_module(library(clpfd)).
in your code
now you do
 
Do I have to use it?
 
with CLPFD you can write X*X # = 2
in basic Prolog you can't write X*X is 2
 
5:42 PM
can I do it basic Prolog?
 
Brachylog's arithmetic is completely based on CLPFD
 
Can I do it in basic Prolog?
 
@LeakyNun Yes, but probably not nearly as nicely
 
How would I use it?
@Fatalize Still returning false for integer(X)
 
5
Q: is_list/1 and free variables

FatalizeHere is a first observation: ?- is_list([]), is_list([_,_,_]). true. Here is another observation: ?- [] = _, [_,_,_] = _. true. Therefore, why would is_list/1 be implemented such that ?- is_list(_). false. or ?- is_list([_|_]). false. when _ can clearly be unified with a list? Wouldn'...

This unfortunate trait is shared by all hereditary type checking predicates like atom/1, integer/1 etc.
 
5:51 PM
So how can I do it?
 
do what
 
Assert that X is an integer
 
why would that be needed
X will be an integer if it needs to
 
Alright
:- use_module(library(clpfd)).
a(X,B,L):-
  X #>= 0,
  (X #< B -> L #= [X]
     ;
     divmod(X,B,Q,R),
     a(Q,B,K),
     append(K,[R],L)
  )
  .
Why doesn't this work
Ideally it should see L #= [X] and then fails
and then proceed to after semicolon
Prolog why you do things top to bottom
 
?- a(13,2,L).
L = [1, 1, 0, 1].
remove the # in L = [X]
L is a list, #= is for integers
 
5:58 PM
I mean if I specify B and L
it can't find X
 
because you cut the choice after X #< B
which will always be true when X is free
so it tries L = [X] which is false, then no other choice point
 
which means, no -> in CLFPD
or CLPFD
 
no
it means your -> is in the wrong place
but anyway
if you change it a bit it still doesn't work because divmod doesn't work if X is free
 
where should I put it?
@Fatalize .....
 
X #< B, L = [X] -> true
 
6:01 PM
instead of divmod(X,B,Q,R)
I would write X #= B*Q+R
Right?
 
Hint: [1,1,0,1] * [8,4,2,1] = 13
so code that instead of divmod
 
@Fatalize Ugh
 
Warning: leading zeroes
= infinite choice points
 
How to make it O(log(n))
 
don't know, don't care about complexity
 

« first day (210 days earlier)      last day (2056 days later) »