Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can define operator '.', but it doesn't parse #23

Closed
Jean-Luc-Picard-2021 opened this issue Aug 22, 2022 · 5 comments
Closed

Can define operator '.', but it doesn't parse #23

Jean-Luc-Picard-2021 opened this issue Aug 22, 2022 · 5 comments

Comments

@Jean-Luc-Picard-2021
Copy link

Jean-Luc-Picard-2021 commented Aug 22, 2022

Tried to run this:

{"quote":"Winning isn’t everything, but wanting to win is.","author":"Vince Lombardi"}.
{"quote":"I am not a product of my circumstances. I am a product of my decisions.","author":"Stephen Covey"}.
{"quote":"You miss 100% of the shots you don’t take.","author":"Wayne Gretzky"}.
{"quote":"Every strike brings me closer to the next home run.","author":"Babe Ruth"}.
{"quote":"Whether you think you can or you think you can’t, you’re right.","author":"Henry Ford"}.

member_comma(Z, (X,_)) :- member_comma(Z, X).
member_comma(Z, (_,Y)) :- !, member_comma(Z, Y).
member_comma(X, X).

:- op(100,yfx,'.').
:- op(800,xfx,':=').
X := A.B :- member_comma(B:X, A).

main :- statistics(wall, W), N is W mod 5+1, call_nth({ X }, N), Q := X."quote", A := X."author",
   write(Q-A), nl.

But I got errors:

?- ['quotes.pl'].
Warning: singleton: X, near line 13, file 'quotes.pl'
Warning: singleton: A, near line 13, file 'quotes.pl'
Warning: singleton: X, near line 13, file 'quotes.pl'
Warning: singleton: A, near line 13, file 'quotes.pl'
Error: '.', line 13, '
'
   true.

If Trealla cannot parser operator '.', wouldn't it make more sense to
throw already an error during op/3.

@infradig
Copy link
Contributor

Ok, fixed. Nice little dictionary.

tpl
?- [quotes].
true.
?- main.
"Winning isn’t everything, but wanting to win is."-"Vince Lombardi"
true

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Aug 22, 2022

I don't know whether wall is some de facto standard.
This is a little ad-hoc from one of my systems.

Also I have edited the source code just now. In case
wall gives some negative number, who knows?

Its mod/2 now:

?- X is -1 mod 5.
X = 4.

@flexoron
Copy link

flexoron commented Aug 23, 2022

That was located out of sight, Jean-Luc.
Thank you for this impulse: X = (Y is B+_)

$ cat is.pl
{_ is _+1}.
{_ is _+2}.
{_ is _+3}.
{_ is _+4}.
{_ is _+5}.
main :- between(1,5,N), call_nth({X}, N),
        X = (Y is B+_),
        write('+'), between(1,3,B), X, write(Y), fail.

$ tpl
?- "is".
   true.
?- main.
+234+345+456+567+678   false.
?-

@infradig
Copy link
Contributor

infradig commented Aug 24, 2022 via email

@Jean-Luc-Picard-2021
Copy link
Author

I can consult and run it now.
Maybe the code itself needs a little bit more cuts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants