Im trying to check if its a list in prolog - list

So I started by creating a base case. Then came up with this:
list([]).
list([_|_]):-
list([_],true),
list([_|_],true).
So when I run it its supposed to do this
-list([1,2,3]) → True.
-list(hello) → False.

Related

mapbox-gl - how to instantiate a Map for a simple test

I'd like to start by asking Mapbox - please - to put documentation on their site that explains how to set up and start doing a simple test. There are many tests in their code on Github, but after days of reading and attempting to test I have failed to understand how they work.
I have a very simple method that:
updates some geoJson with some new coordinates and a new heading (rotation) for a marker.
uses setSource to set the changed Json to the Map
I would like to run my little method in a test and then check that the new coordinates have arrived in the Map.
Should be a piece of cake!
Now a Map needs a browser or similar. Yes, there's jsdom, which is almost certainly what is needed, but I have not discovered how you give the dom to the Map.
If I try to instantiate either window, which I found in mapbox-js utils, or Map, I get
ReferenceError: self is not defined. - 'self' appears to be the window object.
I use mocha, with babel 7, for what it's worth, but I think that all I need is to solve the mystery of setting up a Map instance so that I can then interrogate it.
Any help would be gratefully received.

autocompletion of parameter : list static fields without typing a ClassName::

How to make auto-completion list all (static) fields of a certain class that has appropriate variable-type when ctrl+space at a slot of parameter in a certain function?
Example
I tried to ctrl+space in the below code :-
(Code as text is here.)
Question: How to make it show E_1 E_2 E_3?
I don't mind another plugin if I really need one.
It currently works but only for enum :-
My workaround
In practice, to get smart clue, I have to type more (PrototypeList::) :-
Bounty Reason
Here is the result of the current answer (citizenmatt's):-
It is different, but still not show E_1 E_2 E_3.
Have you tried Smart Completion? This feature will only show completion items that are valid for the current context. I think it works in C++, too.
In fact, ReSharper does help you here. All of E_1, E_2 and E_3 are in the completion list, but not on the top of it - they are assigned lower scores because they need an additional qualifier. That said, looks like there is still an issue with scoring:
E_2 and E_3 are in the list too, but they are not shown alongside E_1. We'll investigate this (RSCPP-19501).

Expected 'collections.Iterable', got Optional[list] instead

I received this error in Pycharm Community Edition 5.0.3 today and was wondering whether it was just something I'm doing wrong/not realizing, or if it is a PyCharm lint issue. The code to reproduce the error is
mylist = list()
# fill mylist, or do nothing here, either way the error persists
if mylist:
# if something in the list...
mylist.append(2)
else:
# list is empty, add something
mylist.append(1)
# warning at the loop here
for val in mylist:
print val
Is this because it's thinking that mylist is a union of type ?
Optional[list] is a typing annotation that signals PyCharm found mylist to be either None or a list object.
This appears to be caused by the if mylist: test; I'd say this is PyCharm making an incorrect inference here, since you clearly set mylist to a list instance only one line before. if tests for emptiness, not if the object is None.
This is a bug, filed with the PyCharm project as issue PY-21897, and fixed in PyCharm verson 2017.1.
If you place something like this:
""":rtype: list"""
in the docstring for the function that produces your list, that should make pycharm realize you really are expecting a list.

appending strings to lists in prolog

i'm a new on Prolog, and i'm already having some problems to understand, the thing
is, i was making a test on appending some strings introduced by console:
append_str([],Adder,Adder).
append_str([Head|Tail],Adder,Result):-
append_str(Tail,[Head|Adder],Result).
sread_str(String):-
read(String),
atom(String).
sinput:-
sinput_str([]).
sinput_str(Lista):-
sread_str(String),
sinput_str([String|List]).
sinput_str(List):-
append_str(List,[],Result),
nl,
display(Result),
nl.
And eventually always getting this output:
|-? sinput.
sinput.
hello.
hello.
world.
world.
9.
9.
'.'(hello,'.'(world,[]))
The number is just for the console to end asking for some more values, i don't know what is wrong, thank you guys in advance.
you should try to understand what happens when you enter a number, forcing sread_str to fail.
Prolog explores all the alternatives available to prove a given goal, and doing so change the variables, undoing such changes when a path fail. Such model it's complicated by side effects required by IO (the read/display builtins).
Then attempt first to have a working sinput_str, something like this
sinput_str([String|List]):-
sread_str(String),
sinput_str(List).
sinput_str([]).

Prolog lists (using stemming function)

I know this is a very simple question but I seem to be having some problems.
I am trying to stem a list of words using porter_stem but I am getting an error:
Out of local stack
This is my code:
stemming([],[]).
stemming([H|T], A) :-
stemming(T,Answer),
porter_stem(H,S),
append(Answer,S,A).
Basically the pseudocode for this is as follows:
for all items in list
stem item
add item to list2
return list2
Can anyone please point me in the right direction please?
Consider using maplist/3 or equivalent depending on your prolog implementation: something like maplist(porter_stem, List, Result). would suffice.
If you're interested in learning how to build a proper recursion, post a comment and I'll try to expand my answer :)