Prolog - Finding specific elements index [closed] - prolog

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
helllo
iam new to prolog and iam trying to make a function returns a specific elements index
for example
indexof (4,[3,4,5],X)
X is 1
any help is really appreciated

Use nth0/3
?- nth0(X,[3,4,5],4).
X = 1 ;
false.
If you go to the documentation page and click on it will take you to the Prolog source code that implements nth0/3. (link)

Related

Why log is considered as an impure function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
As i know, pure functions return the value that you insert in. However, log do also the same thing as for example finding sin(x). Why log is considered impure
Read haha some articles

Calculate % of number in Scala programming [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
How to do 50% of 120 in scala code..need proper syntax ,& runnable code for same.
Eg :
int k = (int)(120*(50.0f/100.0f));
This is in java need scala code for same.
The answer would be:
(120*(50.0f/100.0f)).toInt

How to remove the first element of sub-list in prolog [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
List like this:[1,[2,3,4]]
Remove the first element of sub-list which is 2,
Result like this:[1,[3,4]]
This should get you an idea of how to do it:
rem_sublist_first([], []).
rem_sublist_first([X|Y], [X|Y2]):-
\+ X = [_|_],
rem_sublist_first(Y, Y2).
rem_sublist_first([[_|Y1]|Y2], [Y1|Y3]):-
rem_sublist_first(Y2, Y3).
test:-
rem_sublist_first([1,[2,3,4]], [1,[3,4]]),
rem_sublist_first([1,2,3,[4,5,6]], [1,2,3,[5,6]]).
I advise you to study prolog lists, they are essential for any type of prolog program so it is a worth investment if you are goind to write prolog code.

What are the best uses for Go Imaginary Literals? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
It would be fine for me if the code below returned true.
Since it has not, what are the best uses for this feature? What am I missing?
a := 10.52i
b := 10i
fmt.Println(a == b)
//false
Based on #Tashi, #Arkku and #axiac's comments, I realized that I am missing Math knowledge to understand this feature.

What would be the language generated by Σ*-x? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Say, for example, Σ={x,y}.
And you carried out the operation Σ*-x. What would be the resulting language? Would it essentially be y* or would it just minus one occurrence of x in all strings generated in Σ*?
i.e xxyyxx to xyyxx.
It would be the language of all strings generated by Σ* minus the string x. (so: xx, epsilon, xyx, y, etc... but not x)

Resources