3 ms·
> The reverse predicate from this section should not be used in practice - most Prolog implementations actually provide a built-in version which is a lot more p
by brabel 2y ago
> The reverse predicate from this section should not be used in practice - most Prolog implementations actually provide a built-in version which is a lot more performant than our implementation.
That feels like cheating. If you shouldn't use the implementation shown, then why do you even show it? Let us see the performant version!
That's like Haskell's quickSort implementation in a couple of lines... beautiful but horrendously non-performant as it doesn't actually implement the algorithm, it just implements the "idea" (while losing all the performance of the actual algorithm, which requires in-place mutation).
- derdi 2y agoNo built-in is needed for an efficient reverse. It's just one or two lines longer because you need to write a tail-recursive helper with an accumulator, same as in functional languages: https://stackoverflow.com/a/74777180 https://stackoverflow.com/a/74777180