[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]

/techbunker/ - Technology (Bunker)

Technology (Bunker)

Email
Comment *
File
Password (Randomized for file and post deletion; you may also set your own.)
Archive
* = required field[▶Show post options & limits]
Confused? See the FAQ.
Oekaki
Show oekaki applet
(replaces files and can be used instead)
Options

Allowed file types:jpg, jpeg, gif, png, webp,webm, mp4, mov, pdf
Max filesize is16 MB.
Max image dimensions are15000 x15000.
You may upload3 per post.


File: e5cd051c8ff5175⋯.jpg (110.64 KB,500x753,500:753,Summer Glau Cameron.jpg)

 No.1043

Hi, let's try if I can open a thread about learning Prolog (Programming Language). I'm currently learning it and sometimes I should ask people about it. There are books and tutorials, but it would help to have some study group. The tutorials I found often contain errors or aren't explaining stuff very well. Since AI is becoming more and more important others might be interested in it as well. I don't mind if someone posts questions about other rather exotic languages with rather poor tutorials in this thread.

Let's start with this:

?- member(a, [a, b, c]).

true

?- member("Alita", ["Alita","Isla","Chi","Cameron"]).

true

?- [user].

|: alist(["Alita","Isla","Chi","Cameron"]).

?- member("Alita", alist).

false. Why?

?- member("Alita", alist(A)).

false.

?- alist(A).

A = ["Alita", "Isla", "Chi", "Cameron"].

?- member("Alita", (A = alist(A))).

false.

____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1045

I've learned Mercury rather than Prolog, but it looks like you have a list inside of a structure, a dynamic alist/1 term or something, and so need to pattern-match it out before you can look for a member of it. Otherwise you may as well be asking of "Alita" is a member of 42. No, there's no "Alita" in that thing that can't even contain strings like "Alita".

I don't understand the

?- [user].

syntax, but based on later statements, this should work:

member("Alita", A).

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1046

Yeah, but as I showed:

?- alist(A).

returns: A = ["Alita", "Isla", "Chi", "Cameron"].

?- member("Alita", alist(A)).

returns: false

BTW: ?- [user]. is just to switch to another mode where one can put in rules. |: shows one is in this mode. The standard mode is for putting in "questions" or tests.

I didn't know about Mercury, I'm looking into it for a bit. But Prolog seems to be used by quite some people and being taught in CS classes.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1047

>>1046

>but as I showed

what contradiction do you see there?

alist(X) is not X.

member finds members of lists. it doesn't know about alist/1

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1048

Oh, I forgot:

?- member("Alita", A).

returns: A = ["Alita"|_6022]

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1052

When I write this:

?- alist(X), member("Alita", X).

It should create X='the list I want'. Well, it does, it gives back:

X = ["Alita", "Isla", "Chi", "Cameron", …]

But it does not use it in the second term or command.

Another try:

|: sublist(A,B) :- alist(A),member(A,B).

?- sublist("Alita", alist).

false.

?- sublist("Alita", alist(X)).

false.

Well, probably I understood something in those tutorials wrong. I get the tests in those right, but as soon I try something on my own it fails. Getting useful answers from guys which know Prolog on the other hand seems to be rather difficult. However, I downloaded some books now, so I'll try it with those. Maybe this works better for me.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1053

>>1052

you keep saying alist(X), I think you're very confused about how Prolog works.

consider:

$ cat list.pl
alist([alita, isla, chi]).
anotherlist([isla, chi]).

waifu :-
alist(L),
member(alita, L),
print('waifu found').

bad :-
anotherlist(L),
member(alita, L),
print('waifu found?').

marry(L) :-
member(Waifu, L),
print('I guess I\'ll marry...'),
print(Waifu).

$ gprolog
GNU Prolog 1.4.5 (64 bits)
Compiled Jan 18 2020, 18:52:18 with gcc
By Daniel Diaz
Copyright (C) 1999-2020 Daniel Diaz
| ?- consult(list).
compiling list.pl for byte code...
list.pl compiled, 17 lines read - 1645 bytes written, 4 ms

yes
| ?- waifu.
waifu found

true ?

yes
| ?- bad.

no
| ?- alist(L), marry(L).
I guess I'll marry...alita

L = [alita,isla,chi] ?

yes
| ?-

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.1055

Ah, thanks. Now I've got it.

This is working:

?- [user].

|: fembots(["Alita", "Isla", "Chi"]).

|: buildfembot(X) :- fembots(L),member(X, L),print("Start building…").

|: ^D% user://9 compiled 0.06 sec, 3 clauses

?- buildfembot("Alita").

"Start building…"

true .

The variable for the list only needs to be on the right side. I got confused with the idea of singelton variables. I thought I need the same on both sides, but it's only important that they occur more than once.

I nearly had this part: buildfembot(X) :- fembots(L),member(X, L)

Here: sublist(A,B) :- alist(A),member(A,B). Doesn't work.

Also doesnt work: sublist(A,B) :- alist(B),member(A,B).

I didn't need the variable for the list I wanted to retrieve, and it might even not possible to hand it over that way. If it is possible, then I still don't know that part. However, that's no problem. The right style in Prolog seems to be to break these things in little parts anyways.

I started reading "Prolog Programming - A First Course, Paul Brna"

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.



[Return][Go to top][Catalog][Nerve Center][Random][Post a Reply]
Delete Post [ ]
[]
[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]