Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!portal!portal!cup.portal.com!pgl From: pgl@cup.portal.com (Peter G Ludemann) Newsgroups: comp.lang.prolog Subject: Re: incrementing values Message-ID: <26542@cup.portal.com> Date: 3 Feb 90 02:41:19 GMT References: <17467@megaron.cs.arizona.edu> <31462@shemp.CS.UCLA.EDU> <34699@iuvax.cs.indiana.edu> Organization: The Portal System (TM) Lines: 31 In IBM-Prolog, I wouldn't dream of using assert/retract; instead, I would use the internal database (similar to record, but better): term_get(name, Value) & term_assert(name, ? Value + 1) % "?" triggers functional evaluation It's actually quite efficient (maybe it shouldn't be so efficient; we don't really want to encourage this kind of thing). As a variant, if I do: term_get(name, Value) & term_put(name, ? Value + 1) the change is undone on backtracking (or when the query has no more solutions). Not only that, but I could tell the system that term_get_f(name) is a functional abbreviation for term_get(name,Value) and do this: term_put(name, ? term_get_f(name) + 1) By the way, IBM-Prolog allows multiple keys. As an example, all the pragma and scanner values are kept in this internal data base. So, to change the scanner to accept [a!b] instead of [a|b] (for example, on a Japanese keyboard which is missing the bar character), I just enter: <- term_assert(assignable,6,"!") . % 6 is the cons char's index In fact, that's how IBM-Prolog implements Edinburgh syntax: there's a built-in predicate which just does a series of such term_assert()s. - peter ludemann pgl@cup.portal.com