syntax,prolog , What is the difference between _ and _variable in prolog?

What is the difference between _ and _variable in prolog?


Tag: syntax,prolog

I have encountered a lot of problems with a literal that starts with a _ such as _Peter. So what exactly would be the difference between:




Thank you for answering my question!


_ alone is an anonymous variable. Multiple occurrences in the same clause (or the same read-term) represent different variables.

A variable starting with _ but containing further characters is not an anonymous variable. Several occurrences represent the same variable.

By convention, many Prolog systems require that variables occurring only once need to start with a _. But this is a convention leading in most implementations to warnings only.


How does pruning choice points in the code below make it more efficient (Prolog)?

In the code given below, there is the ! (cut) that prunes the choice point for efficiency. I am pretty certain that the reverse predicate and the agent_do_moves predicate are essential. solve_task(Task,Cost):- agent_current_position(oscar,P), solve_task_a(Task,[b(0,0,P)],[],R,Cost,_NewPos),!, % prune choice point for efficiency reverse(R,[_Init|Path]), agent_do_moves(oscar,Path). ...

Prolog rules and query

I need some help to find the rules and/or query for knowledgebase in Prolog with information about Costumers in a supermarket. For example I have: Customer(Name,Age,Sex,Wage). customer(John,30,M,2000). customer(Mary,35,F,2500). customer(Mark,40,M,2500). invoice(Number, CostumerName, Product, Price). invoice(001, John, Potatoes, 20). invoice(002, John, Tomatoes, 10). invoice(003, Mary, Soap, 50). invoice(004, Mark, Potatoes, 20). invoice(005,...

Prolog-iterating through list

Let's say i have list Xs = [a,b,c]. Now i want to iterate through all elements and call another function for this elements. My question is: how to do this using head and tail? I would be grateful for help.

make all elements in list equal with minimal cost

I am trying to create a prolog program that allows to convert a list into a list with the same length consisting of only 1 element from the original list. This element must be chosen in such a way that a minimal number of elements from the original list needs...

C# No value given for one or more required parameters

Is there anything Wrong in SQL Syntax ? Sql syntax : UPDATE Table1 SET Username='Diana' , Email='[email protected]' , FirstName='' , LastName='' , CrediCardNum='' Where Username='Diana' it Keeps Giving me the Error: No value given for one or more required parameters. I tried restarting visual studio but keeps giving the same...

Translating a list to another list in prolog

I Tried to write a simple code in Prolog which translate a list to another list. for instance, if we call listtrans([a,b,c],L), L will become [1,2,3]. (a,b,c is replaced with 1,2,3). But i faced with a syntax error in last line. what is the problem? here is my code: trans(a,1)....

Unwanted logical variable in Prolog output

I have to do a Prolog homework for College and I'm mostly done, but i keep getting a _G variable in the output. We need to compare a List - L - to a regular term - K -, and, if the item in the list is bigger than the...

Python stats.linregress syntax error

I am trying to calculate the regression of the x and y variables, trace_no and twwt, respectively. The variable are 151 x 1 arrays. The code is outputting a syntax error: File "./", line 32 slope, intercept, r_value, p_value, std_err, Syy/Sxx = stats.linregress(trace_no,twtt) SyntaxError: can't assign to operator I have...

How to specify the prior probability for scikit-learn's Naive Bayes

I'm using the scikit-learn machine learning library (Python) for a machine learning project. One of the algorithms I'm using is the Gaussian Naive Bayes implementation. One of the attributes of the GaussianNB() function is the following: class_prior_ : array, shape (n_classes,) I want to alter the class prior manually since...

accessing program listing in prolog

I'm having some strange (or not so strange) problems defining variables in SWI-Prolog. Example: I'd like to do something like below: :- initialization(main). main :- X = listing(main), write(X). but it's simply printing "listing(main)" ...

What does `\+` signify as an operator in prolog?

I have encountered the symbol \+ in prolog and am not sure as to what it signifies. I have gone through the prolog documentation and am either not being too resourceful or have not really noticed it. Thank you for your answer! ...

Get operator operands

I have list: List = [a=3, b=2, c=0]. For example, first element a=3, how can I get value Left = a, Right = 3. Left side is atom and right side is number....

Javascript For Loop with Iterator In the Middle and Decrement Operator to the Left of i?

For a non-recursive example of a factorial function I found this example and am having a little difficulty tracing through the code: function fact(x) { if(x == 0) { return 1; } if(x < 0 ) { return undefined; } for(var i = x; --i; ) { x *= i;...

gprolog: Getting a stacktrace after an exception

While using gprolog I often have exceptions without any kind of line numbers or context like this one: uncaught exception: error(instantiation_error,(is)/2) Without any kind of context. I know I can do a trace but it would take very long to debug it with trace since I need to execute a...

PROLOG: Summing up the series procedure

I have been trying to work on this problem that I found in a book, but am not able to make sense of it in my head. The problem asks me to use series(N, Total) for this procedure; 1 + 1/2 + 1/3 + 1/4 + ... + 1/(N-1). Any...

What is the correct way to create a object array in java? [duplicate]

This question already has an answer here: Difference between int[] array and int array[] 23 answers I've seen examples such as: Type arrayname[] = new Type[]; also as written as: Type[] arrayname = new Type[] I am quite confused about such expressions! Where exactly should I put the []?...

What is the difference between _ and _variable in prolog?

I have encountered a lot of problems with a literal that starts with a _ such as _Peter. So what exactly would be the difference between: good(_,_). and good(_,_Peter). Thank you for answering my question!...

Syntax Error, Operator Expected

I am trying to query the MS SQL Server database using Prolog. Prolog Code lemmas:- odbc_query('my_db', 'SELECT * ,case when ActualCost<EstimatedCost then 'true' else 'false' end as Value from Work_Order ' ). It gives an error that operator is expected after 'true' . Note: The Query works in SQL-Server but...

Assigning a value to an object of type AnyObject

I have a variable var post :AnyObject? which is an object that I got back from a Parse API call. I want to do this post["caption"] = captionTextView.text but I get the following error message Cannot subscript a value of type 'AnyObject?' with an index of type 'String' I already...

Python method that can be called on a list of objects

When a method is called on an object in python as: obj.func() then python passes the obj as the first argument to the func(). I want to do something like: [obj1, obj2].func() and have it processed as: [obj1.func(), obj.func()] Is there a way of defining this kind of methods in...

Regex - the difference in \\n and \n

Sorry to add another "Regex explanation" question to the internet but I must know the reason for this. I have ran this regex through RegexBuddy and with no help. I came across the following regex ("%4d%[^\\n]") while debugging a time parsing function. Every now and then I would receive...

ANSI escape characters in gprolog

Trying to print bold and underlined text in prolog but can't write them write('\033[1mbold\033[0m') Makes this (expected) error: syntax error: \ expected in \constant\ sequence What's the correct way to do it with gprolog ? Maybe with format ?...

How does the predicate 'repeat' create infinite choice points in prolog?

I do not understand how the predicate repeat evaluates to be true at all times and create infinite choice points. For example, when I call: :- repeat, reset, do(task,job). Thank you for your help! ...

Solving constraints with string concatenations in Prolog

Here, I tried to solve some simple string constraints in Prolog. While this problem seems to be straightforward, the main predicate still does not print the value of FinalString, which should be "hello world". Is it possible for Prolog to solve constraints that contain string concatenations, like this one? :-...

Why was the ISO standard for prolog a failure? [closed]

In the introduction here, it states that the ISO standard for Prolog was a failure. Can anyone elaborate on this?

Yaml syntax to create this array

Given the following simple yaml data, foo: 1 bar: - one - two if I want to create an array of the exact same data structure, what's the correct way? I've tried first: foo: 1 bar: - one - two - three second: foo: 2 bar: - one1 - two2...

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative?

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative? (This kind of equivalence is valid in a popular idiom with plain $, but currently $ is right-associative!) <*> has the same associativity and precedence as <$>, but behaves differently! Example:...

SyntaxError: invalid syntax?

Good afternoon, I am developing a script in python and while I am trying to compile it from the terminator/terminal i always get this error, but I cannot understand where is the syntax error? File "", line 128 print ('########################') ^ SyntaxError: invalid syntax Then I just change the position...

How to add a print command to DCG syntax

I want to add a print command to my DCG syntax, here is what I have: program( (R0 --> R) ) --> [begin],instructs(( R0 --> R )),[end]. instructs( ( R0 --> R ) ) --> instr(( R0 --> R )). instructs( ( R0 --> R ) ) --> instr(( R0...

MySQL - Querying for names for a different table corresponding to their ids

I need to get names of from and to users to display messages. I have two tables one user table CREATE TABLE IF NOT EXISTS USERS( USER_ID INT UNSIGNED NOT NULL, USER_EMAILID VARCHAR(100) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NOT NULL, USER_FIRST_NAME VARCHAR(100) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL, USER_LAST_NAME...

Where does the syntax for expressions in SSRS come from?

The syntax for the expressions in SSRS seem to be very different to the other products that Microsoft produces. For example, I am not aware of any other tool that uses IIF() for an if statement and using 'is nothing' to assess if value is NULL. Is there any history...

Prolog- singleton variable in branch warning

Hello here is my code in Prolog: arc(a,h). arc(b,c). related_to(X, Ys) :- setof(Y, arc(X, Y), Ys). cut([H|T],Y) :- check(H,Y), T = [] -> cut(T,Y). check(X,Y) :- related_to(X,Xs), member(Y,Xs) -> write('There is a road'); cut(Xs,Y). When I am trying to run check(a,b) it doesn't run. I get the message Singleton variable...

Prolog- Returning elements from facts

i encounter a problem with facts. Let's say i got 3 facts and check(X) question. fact(a,b). fact(b,c). fact(a,d). check(X):- //some calculation with fact() How to make above question to return list of elements for given X from all facts? For instance: check(a) would give result b and d. So i...

prolog rules as arguments

I'm building an expert system shell based on Luger & Stubblefield's ExShell. In their system, they define rules in the following way: rule((Goal :- (Premise)), CF_Rule). Ignore the CF_Rule. An example of this syntax is: rule((fix(Advice) :- (bad_component(X),fix(X, Advice))), 100). I want to add an OR in certain rules, but...

changing letter into an encryption in java. simple call

What is the other way to change "a" to e.g."\n65" or other call in java which is based on ascii? this is not taught to java developers anymore but it was nice to know. i just forgot, but i need to use it for our project

Java syntax to Groovy syntax

I am not really sure how to translate this to groovy syntax. Have checked this differences with java page already. Thanks! TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String...

Avoid recursion in predicate

I have the following question for the following predicate, how can i drop the recursive call f(T,S1) from both predicates. Flow model: (i,o) f([],0). f([H|T],S):- f(T,S1), S1 > 2,!, S is S1 + H. f([_|T],S):- f(T,S1), S is S1 + 1. This is a trick question, and I am not...

Is it possible to define a CAPL function returning a text string?

I develop CAPL scripts in Vector CANoe, and I need to define several functions returning text strings. In C, I would write something like this: char * ErrorCodeToMsg(int code) or char [] ErrorCodeToMsg(int code) In CAPL, both definitions fail with a parse error. The only working solution I came up...

How can I call a function random inside other function in prolog?

I'm trying to call the random function inside another function. For example I want to do this assert(fact(random()). But it does not work. How can I insert a random number this way? Thanks.

Is this Swift syntax efficient?

Would this for loop fire each time the getter is accessed ? Or does Swift cache it 'behind the scenes' ? var colors: [UIColor] { get { var colors = [UIColor]() let palette = [UIColor.redColor(), UIColor.greenColor(), UIColor.blueColor(), UIColor.orangeColor(), UIColor.purpleColor(), UIColor.yellowColor()] var paletteIndex = 0 for _ in 0..<photos.count { colors.append(palette[paletteIndex])...

Count variable Invalid Syntax [on hold]

I'm back again with what you probably see as a stupid question. I have been working on a sim import random def main() game() def game(): suite_list() money = (100) count = (0) suite_list() card1 = random.randint(1,6) card2 = random.randint(1,6) card3 = random.randint(1,6) while user_money>start_bet: guess = int(input(""" Pick One!...

Show the data from two date fields ordered by the name of the month

I have two date fields. need to pull the data based on this two date fields and display it on monthly order (in words) like JAN , FEB... in MySQL. As of now my query is: SELECT `firstname` , `gender` , MONTH( `dol` ) AS 'month' FROM `student_details` WHERE `doa`...

Prolog: Summing elements of two lists representing an integer(restrictions inside not regular sum!!)

I was solving a problem: A list is representing an integer say 12345 by L=[12,34,5] each element should be from 0 to 99.The exercise is to write a function (sum) that sums two lists and gives the equivalent list of their sum which is representing the sum of two integers....

Checking, if optional parameter is provided in Dart

I'm new to Dart and just learning the basics. The Dart-Homepage shows following: It turns out that Dart does indeed have a way to ask if an optional parameter was provided when the method was called. Just use the question mark parameter syntax. Here is an example: void alignDingleArm(num axis,...

Does Maria DB support ANSI-89 join syntax

Does Maria DB support ansi-89 join syntax? SELECT sites.site_id, sites.site_name, pages.page_id, pages.page_title FROM sites, pages WHERE sites.site_id = pages.site_id; or only ansi-92 syntax? SELECT sites.site_id, sites.site_name, pages.page_id, pages.page_title FROM sites INNER JOIN pages ON sites.site_id = pages.site_id; ...

Getting four bits from the right only in a byte using bit shift operations

I wanted to try to get only the four bits from the right in a byte by using only bit shift operations but it sometimes worked and sometimes not, but I don't understand why. Here's an example: unsigned char b = foo; //say foo is 1000 1010 unsigned char temp=0u;...

Why does adding parentheses in if condition results in compile error?

The following Go code runs OK: package main import "fmt" func main() { if j := 9; j > 0 { fmt.Println(j) } } But after adding parentheses in condition: package main import "fmt" func main() { if (j := 9; j > 0) { fmt.Println(j) } } There is...

prolog misunderstanding. Split list into two list with even and odd positions. where is my mistake?

I'm trying to split a list into two other list. List Even with the elemnts in even possition and a List Odd with the others. I've been looking over iinternet a solution, but all seem to me like chinese, i can not understand the process. So this is what i've...