Defining “let expressions” in Prolog
问题 In many functional programming languages, it is possible to "redefine" local variables using a let expression: let example = let a = 1 in let a = a+1 in a + 1 I couldn't find a built-in Prolog predicate for this purpose, so I tried to define a let expression in this way: :- initialization(main). :- set_prolog_flag(double_quotes, chars). replace(Subterm0, Subterm, Term0, Term) :- ( Term0 == Subterm0 -> Term = Subterm ; var(Term0) -> Term = Term0 ; Term0 =.. [F|Args0], maplist(replace(Subterm0