Skip to content

y u no terminate?? #2484

Closed Answered by hurufu
jjtolton asked this question in Q&A
Aug 14, 2024 · 1 comments · 9 replies
Discussion options

You must be logged in to vote

This variant of your first example terminates:

numthings(Things, Num) :-
        phrase(numthings_(Num, nonterminal(Things)), [0], [Num]).

numthings_(_, nonterminal([])) --> [].
numthings_(Max, terminal(_)), [N] --> [N0], { N0 #=< Max, N #= N0 + 1 }.

numthings_(Max, nonterminal([H|T])) -->
        numthings_(Max, terminal(H)),
        numthings_(Max, nonterminal(T)).

UPDT: I pasted wrong chunk of text

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@hurufu
Comment options

@jjtolton
Comment options

@jjtolton
Comment options

@hurufu
Comment options

Answer selected by jjtolton
@hurufu
Comment options

@jjtolton
Comment options

@jjtolton
Comment options

@hurufu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants