Error "illegal variable type for this position " in prolog - visual-prolog

I try to make a search of animal, who has this property, but I have an error "illegal variable type for this position ".How to solve it?
domains
type=symbol
object=symbol
property=symbol
value=symbol
parent=symbol
predicates
nondeterm is_a(type, parent)
nondeterm has_prop(object, property, value)
nondeterm has_property(object, property, value)
clauses
is_a(dog,wolf).
is_a(dingo,wolf).
is_a(wolf,volki).
is_a(coyote,volki).
is_a(jackal,volki).
is_a(volki,dogs).
is_a(fox,dogs).
is_a(arctic_fox,dogs).
has_prop(dogs, travel, walk).
has_prop(dogs, food_for_child, milk).
has_prop(volki, size, medium).
has_prop(volki, color, brown).
has_prop(arctic_fox, color, white).
has_prop(arctic_fox, size, small).
has_prop(fox, color, orange).
has_prop(fox, size, small).
has_prop(wolf, color, grey).
has_prop(wolf, size, large).
has_prop(dog, color, brown).
has_prop(dog, size, small).
has_prop(dingo, color, orange).
has_prop(dingo, size, medium).
has_property(Object, Property, Value):-
has_prop(Object, Property, Value).
has_property(Object, Property, Value):-
is_a(Object,Parent),
has_property(Parent, Property, Value).
goal
has_property(X,size,medium).
I have an error "illegal variable type for this position " at this line:
is_a(Object,Parent),

Sorry I don't have Visual Prolog available for testing, so I'm not really sure about the solution, but I think the problem is that you should make clear that domains and predicates elements are ground terms.
So I suggest to either make them lowercase, or bracket them with hyphens, otherwise they are variables:
domains
type=symbol
object=symbol
...
predicates
is_a(type, parent)
...
or
domains
'Type'=symbol
'Object'=symbol
...
predicates
is_a('Type', 'Parent')
...
edit
If you have SWI-Prolog available, just comment out from start of file to domains included. Or see this notebook on SWISH.

The problem was in types and variables. I delete domains and work with simple types.
Right Code:
predicates
nondeterm is_a(symbol, symbol)
nondeterm has_prop(symbol, symbol, symbol)
nondeterm has_property(symbol, symbol, symbol)
clauses
is_a(dog,wolf).
is_a(dingo,wolf).
is_a(wolf,volki).
is_a(coyote,volki).
is_a(jackal,volki).
is_a(volki,dogs).
is_a(fox,dogs).
is_a(arctic_fox,dogs).
has_prop(dogs, travel, walk).
has_prop(dogs, food_for_child, milk).
has_prop(volki, size, medium).
has_prop(volki, color, brown).
has_prop(arctic_fox, color, white).
has_prop(arctic_fox, size, small).
has_prop(fox, color, orange).
has_prop(fox, size, small).
has_prop(wolf, color, grey).
has_prop(wolf, size, large).
has_prop(dog, color, brown).
has_prop(dog, size, small).
has_prop(dingo, color, orange).
has_prop(dingo, size, medium).
has_property(O, Property, Value):-
has_prop(O, Property, Value).
has_property(O, Property, Value):-
is_a(O,Parent),
has_property(Parent, Property, Value).
goal
has_property(X,size,medium).

Related

Is there a way to emmit a signal when a cell is edited with same value?

I need to change the font of a cell in a QTableWidget if the user change the text in it, EVEN if the text is the same as the default one.
I used to use itemChanged signal from the table for that kind of things, but here I'm stuck because the signal won't raise if the user type the exact same text.
item = QtWidgets.QTableWidgetItem("42")
self.my_table.setItem(0, 0, item)
self.my_table.itemChanged.connect(self.update)
def update(self, cell):
print("update")
self.my_table.itemChanged.disconnect(self.update)
font = cell.font()
if cell.text() == "":
cell.setText("42")
font.setUnderline(False)
else:
font.setUnderline(True)
cell.setFont(font)
self.my_table.itemChanged.connect(self.update)
knowing :
default text in the cell is "42"
default font is not underline, other one is
Case 1:
User type "3" -> text become underlined
User type "42" -> text stay underlined
Case 2:
User type "42" -> text should become underlined
Why it doesn't ? :
Because the ItemChanged signal won't raise if the user type exactly the same thing.
Should I use another Signal ? (didn't find any which could match my need)
Is there another way to do so ?
Why does it make sens to try to do so ? :
The user want to make the difference between a value that is the default value and a value that is FIXED to a value (and doesn't care if that fixed value is the default one or not, because the default value may change).
Also if the user want to set back the value to the default one, he can empty the cell.

Formatting "key: value" strings with middle spaces

I'm showing key-value pair in a QListWidget. Since key names have different lengths, numbers start in different positions:
TestParameter1: 1.2345
Param2: 6.7890
If it wasn't for the key name, I know that I can use format to introduce spaces with a syntax like '{:7.4f}'.format(value).
Is there any easy way (I mean, not switching to a table or creating my own implementation os a QListView) of achieving something like...?:
TestParameter1: 1.2345
Param2: 6.7890
I suggest you take a further look at string formatting here.
The first thing that comes to mind is to either use the \t (tab) to align as necessary; or to use something on the lines of the below as stated in the python docs.
>>> for align, text in zip('<^>', ['left', 'center', 'right']):
... '{0:{fill}{align}16}'.format(text, fill=align, align=align)
...
'left<<<<<<<<<<<<'
'^^^^^center^^^^^'
'>>>>>>>>>>>right'
>>>

MonoTouch.Dialog: Alignment of Text

I am trying to right align the value entered in a cell:
[Section]
[Entry ("Nickname")]
[Caption("Nick Name:")]
[Alignment(UITextAlignment.Right)]
string NickName;
But Left is used instead of Right? What am I missing?
The Alignment attribute only affects strings, it does not affect Entries.

What does the getMaxSize really returns about a TextArea?

The TextArea class has a method called getMaxSize() which returns an int value. I do not understand what does it really express ? Is it the width ( columns ) or the height ( rows ) or something else ?
There is also the setMaxSize(int maxSize) method.
So what does the size mean when working with TextArea ?
setMaxSize for set the maximum size of the TextArea. If you pass 20 means only 20 characters allow on the TextArea. And getMaxSize returns the maximum size of TextArea. That means its return 20. Don't confuse with column or row or somethings else. For more info, look at TextArea javadoc.
I think that the size attribute in TextArea means the number of characters that you can be placed within this component.
I think the same is true for the TextField.

String replacement in latex

I'd like to know how to replace parts of a string in latex. Specifically I'm given a measurement (like 3pt, 10mm, etc) and I'd like to remove the units of that measurement (so 3pt-->3, 10mm-->10, etc).
The reason why I'd like a command to do this is in the following piece of code:
\newsavebox{\mybox}
\sbox{\mybox}{Hello World!}
\newlength{\myboxw}
\newlength{\myboxh}
\settowidth{\myboxw}{\usebox{\mybox}}
\settoheight{\myboxh}{\usebox{\mybox}}
\begin{picture}(\myboxw,\myboxh)
\end{picture}
Basically I create a savebox called mybox. I insert the words "Hello World" into mybox. I create a new length/width, called myboxw/h. I then get the width/height of mybox, and store this in myboxw/h. Then I set up a picture environment whose dimensions correspond to myboxw/h. The trouble is that myboxw is returning something of the form "132.56pt", while the input to the picture environment has to be dimensionless: "\begin{picture}{132.56, 132.56}".
So, I need a command which will strip the units of measurement from a string.
Thanks.
Use the following trick:
{
\catcode`p=12 \catcode`t=12
\gdef\removedim#1pt{#1}
}
Then write:
\edef\myboxwnopt{\expandafter\removedim\the\myboxw}
\edef\myboxhnopt{\expandafter\removedim\the\myboxh}
\begin{picture}(\myboxwnopt,\myboxhnopt)
\end{picture}
Consider the xstring package at https://www.ctan.org/pkg/xstring.
The LaTeX kernel - latex.ltx - already provides \strip#pt, which you can use to strip away any reference to a length. Additionally, there's no need to create a length for the width and/or height of a box; \wd<box> returns the width, while \ht<box> returns the height:
\documentclass{article}
\makeatletter
\let\stripdim\strip#pt % User interface for \strip#pt
\makeatother
\begin{document}
\newsavebox{\mybox}
\savebox{\mybox}{Hello World!}
\begin{picture}(\stripdim\wd\mybox,\stripdim\ht\mybox)
\put(0,0){Hello world}
\end{picture}
\end{document}

Resources