difference-lists Questions
6
Solved
If I have a list in Prolog such as X = [1, 2, 3, 4], how do I add the element 5 to the end of the list to have X = [1, 2, 3, 4, 5]?
The append function needs two lists, ie append(A,B,C) to get A ...
Gregarious asked 22/2, 2013 at 16:30
3
In Haskell, difference lists, in the sense of
[a] representation of a list with an efficient concatenation operation
seem to be implemented in terms of function composition.
Functions and (d...
Marcellusmarcelo asked 12/5, 2017 at 15:35
7
Solved
I've only been working with Prolog for a couple days. I understand some things but this is really confusing me.
I'm suppose to write a function that takes a list and flattens it.
?- flatten([a,[b...
Crt asked 30/1, 2012 at 5:2
4
I'm reading this tutorial on context free grammars in Prolog, and they mention at the bottom of the page implementing a context free grammar in Prolog using difference lists, with the following cod...
Nila asked 12/5, 2015 at 22:29
5
Solved
I have this homework in LISP where I need to sort out atoms and then sublists from a list. I'm sure this is supposed to be easy task but as I'm not much of a programmer then this is really taking q...
Semiaquatic asked 13/5, 2012 at 15:59
2
Solved
I'm trying to understand difference lists in Prolog, but I'm struggling to actually implement one properly, everytime I try to do it, I get a list of lists, but that's not what I want. I'm trying t...
Thornberry asked 17/11, 2014 at 5:22
3
Solved
What is the difference between "open-ended lists" and "difference lists"?
Proscenium asked 27/12, 2012 at 17:13
2
Solved
I'm having trouble understanding difference list, particularly in this predicate:
palindrome(A, A).
palindrome([_|A], A).
palindrome([C|A], D) :-
palindrome(A, B),
B=[C|D].
Could anyone help m...
Cranmer asked 24/11, 2013 at 0:59
3
Solved
This question refers to the material in chapter 3 of the book:
Programming in Prolog, Clocksin and Mellish, Ed 5
In page 72 of this book, a program using difference list is displayed:
partsOf(X,...
Ostracod asked 21/1, 2014 at 18:29
3
Solved
Consider the following programs, one using difference lists, and the other is not:
reverse1(List1,R) :- rev1(List1, R-[]).
rev1([], A-A).
rev1([H|T], C-A) :-rev1(T, C - [H|A]).
reverse2(List1,R) ...
Ellon asked 18/1, 2014 at 2:54
2
Solved
The dlist package contains the DList data type, which has lots of instances, but not Foldable or Traversable. In my mind, these are two of the most "list-like" type classes. Is there a performance ...
Levitt asked 23/3, 2013 at 17:3
2
Solved
I was reading the answer to this question,
p(X) :- read(A), q(A,X-[]).
q(end,X-X) :- !.
q(A,[A|X]-Y) :- read(B), q(B,X-Y).
The code above uses the syntax List-List. I somewhat understand what...
Thunell asked 16/3, 2013 at 23:38
2
Solved
I am currently working my way through the Learn you a Haskell book online, and have come to a chapter where the author is explaining that some list concatenations can be inefficient: For example
(...
Proficiency asked 14/12, 2012 at 13:4
2
Solved
I was thinking about flattening a binary tree to a list, for latter processing.
I first thought of using (++) to join the left and right branches, but then thought in the worse case that would tak...
Absorbefacient asked 15/5, 2012 at 1:2
3
Solved
I am learning haskell and the function definition I see is:
quickSort (x : xs) = (quickSort less) ++ (x : equal) ++ (quickSort more)
where less = filter (< x) xs
equal = filter (== x) xs
mo...
Stitch asked 3/10, 2011 at 23:51
2
Solved
I've been reading about how great difference lists are and I was hoping to test some examples from the books. But it seems that you can't pass lists as input in just the same way as, for instance a...
Vatic asked 9/7, 2011 at 14:46
1
© 2022 - 2024 — McMap. All rights reserved.