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

## Question:

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:

`good(_,_).`

and

`good(_,_Peter).`

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.

# Related:

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

list,prolog
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....

## What is the difference between _ and _variable in prolog?

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: good(_,_). and good(_,_Peter). Thank you for answering my question!...

## Get operator operands

list,prolog,operators
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....

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

syntax,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! ...

## Python stats.linregress syntax error

python,syntax,regression,linear
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 "./seabed_dip_correction.py", 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...

## gprolog: Getting a stacktrace after an exception

prolog,gnu-prolog
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...

## Syntax Error, Operator Expected

sql-server,prolog
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...

## Prolog- singleton variable in branch warning

variables,prolog,singleton
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...

## Translating a list to another list in prolog

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)....

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

mysql,syntax
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`...

## Solving constraints with string concatenations in Prolog

prolog,swi-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? :-...

## Java syntax to Groovy syntax

java,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 java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String...

## Python method that can be called on a list of objects

python,oop,syntax
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...

## Checking, if optional parameter is provided in Dart

syntax,dart,syntax-error,questionmark
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,...

## Avoid recursion in predicate

prolog
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...

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

javascript,for-loop,syntax,decrement
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;...

## Yaml syntax to create this array

syntax,yaml
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...

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

list,split,prolog
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...

## Prolog rules and query

prolog
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,...

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

python,syntax,machine-learning,scikit-learn
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...

## prolog rules as arguments

prolog,artificial-intelligence,expert-system
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...

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

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! ...

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

prolog,prolog-cut
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). ...

## Count variable Invalid Syntax [on hold]

python,variables,syntax
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!...

## Assigning a value to an object of type AnyObject

swift,syntax,parse.com
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...

## make all elements in list equal with minimal cost

list,optimization,prolog
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...

## How to add a print command to DCG syntax

prolog,dcg
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...

## Regex - the difference in \\n and \n

php,regex,datetime,syntax,sscanf
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 Regex101.com 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

prolog,escaping,iso-prolog
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 ?...

## changing letter into an encryption in java. simple call

java,syntax,ascii
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

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

java,syntax
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 []?...

## 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; ...

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

mysql,syntax
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...

## SyntaxError: invalid syntax?

python,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 "_case1.py", line 128 print ('########################') ^ SyntaxError: invalid syntax Then I just change the position...

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

prolog,prolog-assert
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.

## Unwanted logical variable in Prolog output

prolog
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...

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

syntax,go,syntax-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...

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

c,syntax,bit-manipulation,bitwise-operators
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;...

## Prolog- Returning elements from facts

prolog,return,element,fact
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...

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

string,syntax,capl
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...

## Is this Swift syntax efficient?

ios,swift,syntax
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])...

## accessing program listing in prolog

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)" ...

## C# No value given for one or more required parameters

c#,sql,syntax,ms-access-2007,helper
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...

## 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.

## Where does the syntax for expressions in SSRS come from?

reporting-services,syntax
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: Summing up the series procedure

prolog
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...

## 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:...

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

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