Stream: Elpi users & devs

Topic: Recursive Predicate


view this post on Zulip Théo Laurent (Jul 20 2022 at 10:10):

Is it something reasonable to define a predicate recursively on integers? Something like

pred enum i:int,o:list int.
enum 0 [].
enum N L :- enum (N - 1) L', L = [N|L'].

I can't make it work...

view this post on Zulip Enrico Tassi (Jul 20 2022 at 12:32):

pred enum i:int,o:list int.
enum 0 [].
enum N L :- M is N - 1, enum M L', L = [N|L'].

It happens that N - 1 if the right type, but is not evaluated. That is the role of is.

view this post on Zulip Enrico Tassi (Jul 20 2022 at 12:33):

Also, IIRC, this function exists as std.iota

view this post on Zulip Théo Laurent (Jul 20 2022 at 13:00):

Thanks!


Last updated: Oct 13 2024 at 01:02 UTC