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

DOM API: How get last child efficiently? #340

Closed
Jean-Luc-Picard-2021 opened this issue Jan 11, 2023 · 1 comment
Closed

DOM API: How get last child efficiently? #340

Jean-Luc-Picard-2021 opened this issue Jan 11, 2023 · 1 comment

Comments

@Jean-Luc-Picard-2021
Copy link

I find this DOM API:

parent_of( +htmlObject, ?htmlObject )
parent_of( ?htmlObject, +htmlObject )
http://tau-prolog.org/documentation/prolog/dom/parent_of/2

But I guess the mode (-,+) doesn't provide an efficient way
to get the last child. On the other hand in JavaScript I can simply call:

    return at.lastElementChild;

What is the recommended way to do this in Tau Prolog?

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Jan 11, 2023

Ha Ha ChatGPT is trolling me. You can search last_child
in Tau Prolog current GitHub, not a single find.

https://github.com/tau-prolog/tau-prolog/search?q=last_child

Or try this:

:- use_module(library(dom)).
?- last_child(foo, bar).
uncaught exception: error(existence_error(procedure,last_child/2),top_level/0)

Nevertheless ChatGPT halucinates something perfectly plausible:

Q: How get DOM last child in Tau Prolog programming language.

A: In Tau Prolog, you can use the built-in predicate
"last_child/2" to get the last child of a DOM element.

The predicate takes two arguments:

The DOM element for which you want to get
the last child (the parent element)
A variable that will be bound to the last child element

Example usage:

Copy code
last_child(parent_element, LastChild),
You have to unify the parent element with a variable
that has been initialized as a DOM element .

Please note that my knowledge cut off on Tau-Prolog is
from 2021 and this predicates could be deprecated or
changed so I recommend to check in the documentation
of the library you're using or check the version of
Tau-Prolog you're working with.

LoL

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

1 participant