dcg Questions

4

My professor gave this as an example of Prolog. It is a program that solves the Tower of Hanoi puzzle, where you have to move a stack of disks to another peg by moving one disk after the other, wit...
Coy asked 28/5, 2016 at 13:17

3

Solved

I would like to hear from people who have real world programming experience in using SWI-Prolog's semantic library. Edit: The reason for this question is, among the many people I talked to with pro...
Ivanivana asked 26/1, 2011 at 16:52

5

Solved

I'd like to read a plain text file and apply a predicate to each line (the predicates contain write which does the output). How would I do that?
Shafer asked 26/1, 2011 at 14:24

4

Solved

In Prolog, there are traditionally two ways of representing a sequence of characters: As a list of chars, which are atoms of length 1. As a list of codes, which are just integers. The integers are...
Fania asked 21/2, 2021 at 10:16

4

Solved

I'm writing a Lisp to C translator and I have a problem with handling strings. This is a code that transforms an unary Lisp function to a C equivalent: define(F) --> fun_unary(F), !. fun_unary...
Shennashensi asked 16/1, 2011 at 21:38

4

Solved

Interview question! This is how you normally define the member relation in Prolog: member(X, [X|_]). % member(X, [Head|Tail]) is true if X = Head % that is, if X is the head of the list member(...
Soares asked 16/11, 2009 at 19:11

1

I have a CSV file that look something like below: i.e. not in Prolog format james,facebook,intel,samsung rebecca,intel,samsung,facebook Ian,samsung,facebook,intel I am trying to write a Prolog p...
Valonia asked 20/3, 2020 at 18:25

4

I've got a small problem with left recursion in this grammar. I'm trying to write it in Prolog, but I don't know how to remove left recursion. <expression> -> <simple_expression> &l...
Postbellum asked 19/5, 2012 at 8:29

4

Solved

I am trying to build a DCG which recognizes all lists which match this form : a^n b^2m c^2m d^n. I have written up the following rules: s --> []. s --> ad. ad --> a, ad, d. ad --> bc. b...
Fugger asked 3/1, 2011 at 23:39

5

Solved

I am trying to write a predicate palindrome/1 in Prolog that is true if and only if its list input consists of a palindromic list. for example: ?- palindrome([1,2,3,4,5,4,3,2,1]). is true. An...
Selfemployed asked 29/12, 2011 at 15:26

1

Solved

Suppose I want to write a custom operator for composing DCG rules in a way that would otherwise be repetitive. For example, suppose I had I a DCG, ws such that: ws --> []. ws --> " ", ws. ...
Azotemia asked 27/7, 2018 at 17:30

3

Solved

I've already gotten my feet wet with functional programming; I am familiar (though not proficient) in Haskell and PLT Scheme. I've used PLT Scheme to build little interpreters for toy languages (re...
Attila asked 4/11, 2011 at 22:14

2

Solved

I learned the hard way that with SWI-Prolog the location for the Prolog directive set_prolog_flag matters in a source code file. The only documentation I found of value about loading source code f...
Fearful asked 29/7, 2017 at 13:54

1

Solved

I'm working on implementation of the Google Protobuf compiler for proto files in Prolog for generating Prolog programs. Prolog is SWI-Prolog. I'm translating EBNF definitions into DCG and ran acro...
Shiftless asked 28/4, 2017 at 6:31

2

Solved

This question starts from Mat's answer to Algorithm improvement for enumerating binary trees which has only one input value that determines the number of all nodes for the binary tree, and the need...
Sabaean asked 8/3, 2017 at 13:22

3

Solved

I've wrapped my mind a lot and couldn't figure it out. Is it possible to make a script that with backtrack generates lists in this format: [a] [a,b] [a,b,a] [a,b,a,b] ... I've made one that gene...
Janice asked 18/1, 2017 at 19:2

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

1

Solved

In working with Prolog DCG to parse input it is nice to have an accompaning BNF of the grammar. For example: BNF <Sentence> ::= <Noun_phrase> <Verb_phrase> <Noun_phrase&g...
Defilade asked 10/1, 2017 at 17:54

2

Solved

I have a predicate that finds the correct solution but then goes on to find solutions which are not right. ?- data(D),data_threshold_nonredundantbumps(D,5,Bs),write(D). [3,6,7,8,2,4,5,6,9,4,7,3] D...
Koch asked 23/7, 2016 at 15:50

4

Solved

It seems to me one ought to be able to process binary data with DCGs on a list of bytes. To make it work generally, though, one has to use bitwise operations which means is/2 is involved, which mea...
Podophyllin asked 31/10, 2014 at 21:35

2

Solved

I am attempting to write an adaptive parser in Prolog: in other words, a parser that can modify its own parsing rules at runtime. In order to do this, I'll need to generate new predicates at runti...

5

Solved

I implemented function to get sublist of list, for example: sublist([1,2,4], [1,2,3,4,5,1,2,4,6]). true sublist([1,2,4], [1,2,3,4,5,1,2,6]). false look at my solution: my_equals([], _). my_e...
Langston asked 13/5, 2016 at 11:30

3

Solved

I'm trying to wrap my brain around Prolog for the first time (SWI-Prolog) and I'm struggling with what I'm sure are the basics. I'm trying to take a string such as "pie" and print out the military ...
Elegancy asked 13/4, 2016 at 16:45

1

Was playing around with lenses in Prolog. Lenses are a kind of microscope that allow to zoom into a structure and do some reads or writes in a functional fashion. Basically my point of departure wa...
Baskerville asked 17/2, 2016 at 17:16

2

Solved

I'm trying for the moment to keep my lexer and parser separate, based on the vague advice of the book Prolog and Natural Language Analysis, which really doesn't go into any detail about lexing/toke...
Janeth asked 14/12, 2015 at 23:5

© 2022 - 2024 — McMap. All rights reserved.