<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1714081408739029334</id><updated>2011-11-24T09:28:40.395-08:00</updated><category term='worlds papers'/><category term='left recursion'/><category term='v8'/><category term='javascript'/><category term='worlds'/><category term='papers'/><category term='prolog'/><category term='ometa'/><title type='text'>Oh, meta...</title><subtitle type='html'>Alex Warth's Blog</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-4323973283715501477</id><published>2010-09-03T12:15:00.000-07:00</published><updated>2010-09-03T13:51:50.412-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='worlds papers'/><title type='text'>New paper about Worlds</title><content type='html'>Here's the link: &lt;a href=http://www.vpri.org/pdf/tr2010001_worlds.pdf&gt;http://www.vpri.org/pdf/tr2010001_worlds.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And here's what's new compared to Chapter 4 of my dissertation:&lt;br /&gt;&lt;bl&gt;&lt;br /&gt;&lt;li&gt; a better semantics for the &lt;i&gt;commit&lt;/i&gt; operation &amp;mdash; it now includes a serializability check that makes programming with worlds much safer/saner,&lt;br /&gt;&lt;li&gt; a new section that describes a more efficient, Squeak-based implementation, and&lt;br /&gt;&lt;li&gt; a neat case study that shows that our new implementation is fast enough to do interesting things with worlds.&lt;br /&gt;&lt;/bl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-4323973283715501477?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/4323973283715501477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=4323973283715501477' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/4323973283715501477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/4323973283715501477'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2010/09/new-paper-about-worlds.html' title='New paper about Worlds'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-1547394832697687877</id><published>2010-06-08T00:00:00.000-07:00</published><updated>2010-06-08T00:05:44.439-07:00</updated><title type='text'>Seth Godin on the Kindle</title><content type='html'>&lt;a href="http://sethgodin.typepad.com/seths_blog/2010/06/paperback-kindle.html?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed:+typepad/sethsmainblog+(Seth's+Blog)&amp;utm_content=Google+Feedfetcher"&gt;I hope the folks at Amazon are listening.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-1547394832697687877?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/1547394832697687877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=1547394832697687877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/1547394832697687877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/1547394832697687877'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2010/06/seth-godin-on-kindle.html' title='Seth Godin on the Kindle'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-7998332185506716873</id><published>2009-01-08T19:11:00.000-08:00</published><updated>2009-01-08T19:12:21.074-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='left recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='papers'/><category scheme='http://www.blogger.com/atom/ns#' term='worlds'/><category scheme='http://www.blogger.com/atom/ns#' term='ometa'/><title type='text'>Dr. OMeta</title><content type='html'>On December 23rd, 2008, I filed my Ph.D. dissertation, "&lt;a href=http://www.vpri.org/pdf/tr2008003_experimenting.pdf&gt;Experimenting with Programming Languages&lt;/a&gt;"!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-7998332185506716873?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/7998332185506716873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=7998332185506716873' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7998332185506716873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7998332185506716873'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2009/01/dr-ometa_08.html' title='Dr. OMeta'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-5332321712983148541</id><published>2009-01-08T18:48:00.000-08:00</published><updated>2009-01-08T18:49:32.095-08:00</updated><title type='text'>Use of Prolog for developing a new programming language</title><content type='html'>Some time ago I came across a really interesting paper, "&lt;a href=http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3972&gt;Use of Prolog for developing a new programming language&lt;/a&gt;", by Joe Armstrong et al. Definitely worth a read.&lt;br /&gt;&lt;br /&gt;It tells the story of a group of crazy Swedes who decided to use Prolog to build a prototype of this language that they were working on. They used this prototype to do lots of experiments, and because it was nice and tiny, they were able to rapidly evolve the language and its implementation. Rinse and repeat. (It was only about three years later that they finally had to do a "real" implementation.)&lt;br /&gt;&lt;br /&gt;It's a great story about how great life can be when you ignore conventional wisdom and avoid premature optimization at all costs... BTW, the language was, of course, Erlang. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-5332321712983148541?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/5332321712983148541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=5332321712983148541' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/5332321712983148541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/5332321712983148541'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2009/01/use-of-prolog-for-developing-new.html' title='Use of Prolog for developing a new programming language'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-3668690279396937988</id><published>2008-09-24T15:18:00.000-07:00</published><updated>2008-09-24T15:57:44.670-07:00</updated><title type='text'>The Omnidebugger</title><content type='html'>We intend to use a number of different programming languages in the &lt;a href=http://www.vpri.org/pdf/tr2007008_steps.pdf&gt;STEPS project&lt;/a&gt;. Even right now, if we only look under the hood (in what we call the "engine room"), we're already using three: Pepsi, Coke, and an OMeta-like language for parsing. Coke plays a special role among these languages, since the semantics of the other languages are defined via translation into Coke. &lt;br /&gt; &lt;br /&gt;One thing programmers&amp;mdash;especially Smalltalkers&amp;mdash;really care about is debugging. Coke has recently started to get some debugging capabilities, and we can expect that these will soon be on par with (hopefully even better than) Smalltalk's. This is definitely a good thing, but we can't stop there; the other languages also need support for debugging, and making this work in under 20K LOC is not a trivial task. &lt;br /&gt; &lt;br /&gt;Consider a JavaScript implementation on top of Coke, for instance. Our translation might map a single JavaScript statement to a group of three or four Coke expressions that must be evaluated in sequence. So if we use the Coke debugger on the code generated for a JavaScript program, its notion of “single-stepping” won’t make sense at the JavaScript source level. Similarly, inspecting the temporary variables on the stack won’t work unless JavaScript’s temps are represented directly as Coke temps, which may not be the case. Things are even worse for languages whose semantics are significantly different from Coke’s. For example, a debugger for Prolog should support all kinds of features (e.g., unification) that don’t really make sense in the Coke debugger.&lt;br /&gt; &lt;br /&gt;The “conventional” way around these problems would be to implement a separate debugger for each language, which clearly isn’t good enough for STEPS. But what if we went with a kind of pluggable debugger architecture that allows each “Language X”-to-Coke translator to associate inspecting and debugging functionality, along with all kinds of useful meta-data, with the Coke parse trees it generates? (The Coke compiler would of course have to maintain these associations when it converts the parse trees to code.) This would enable a single debugger implementation, including its GUI, to customize itself to the language that is being debugged. It would also enable programmers to debug the same piece of code at different levels of abstraction (e.g., at the JavaScript level, hiding all “scaffolding” or at the Coke level, in gory detail), which would be extremely valuable to language implementers.&lt;br /&gt;&lt;br /&gt;Scheme programmers often implement little DSLs using macros, so I hope that we can get some inspiration from Dave Herman's &lt;a href=http://calculist.blogspot.com/2008/09/debugger-as-library.html&gt;debugging library for PLT Scheme&lt;/a&gt;, which seems very interesting.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-3668690279396937988?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/3668690279396937988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=3668690279396937988' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/3668690279396937988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/3668690279396937988'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2008/09/omnidebugger.html' title='The Omnidebugger'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-7602040321185329883</id><published>2008-09-11T16:03:00.000-07:00</published><updated>2009-01-10T10:05:15.752-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='papers'/><category scheme='http://www.blogger.com/atom/ns#' term='worlds'/><title type='text'>Worlds: Controlling the Scope of Side Effects</title><content type='html'>&lt;a href=http://www.vpri.org/pdf/rn2008001_worlds.pdf&gt;Here&lt;/a&gt; is a (very informal, not conference-style) paper about &lt;i&gt;worlds&lt;/i&gt;, which is something that I've been working on lately. I'm pretty excited about this stuff... Please let me know if you have any comments, suggestions, etc.&lt;br /&gt;&lt;br /&gt;Tap, tap, tap &amp;mdash; is this thing on?&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;&lt;u&gt;Update&lt;/u&gt;:&lt;/b&gt; Chapter 4 of &lt;a href=http://www.vpri.org/pdf/tr2008003_experimenting.pdf&gt;my dissertation&lt;/a&gt; is an improved version of this paper. It contains more examples, a formal semantics for property/field lookup in the presence of worlds, and a proper Related Work section.&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-7602040321185329883?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/7602040321185329883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=7602040321185329883' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7602040321185329883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7602040321185329883'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2008/09/worlds-controlling-scope-of-side.html' title='&lt;i&gt;Worlds&lt;/i&gt;: Controlling the Scope of Side Effects'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-1384088463048772909</id><published>2008-09-06T00:47:00.000-07:00</published><updated>2008-09-29T00:45:10.034-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='v8'/><category scheme='http://www.blogger.com/atom/ns#' term='ometa'/><title type='text'>Modified V8 Shell w/ translateCode</title><content type='html'>This week Dan Ingalls came down to visit us at VPRI, and we got to chat about &lt;a href=http://code.google.com/p/v8/&gt;V8&lt;/a&gt; for a little bit. We're both really excited about it. "It's like they just gave you a new horse", he said. :)&lt;br /&gt;&lt;br /&gt;So tonight I was looking at the source code of the V8 shell, and it turned out to be pretty easy to modify it to support my &lt;tt&gt;translateCode&lt;/tt&gt; idea. In case you don't know what I'm talking about, there really isn't much to it: &lt;tt&gt;translateCode&lt;/tt&gt; is just a user-defined function that's called (implicitly) by the shell/workspace. It takes as an argument the code that the user typed in, and returns the code that should run in its place. It's extremely useful for playing with source-to-source translators. &lt;a href=http://jarrett.cs.ucla.edu/ometa-js/v8-shell.cc&gt;Here's a link&lt;/a&gt; to my modified shell.cc, if you're interested.&lt;br /&gt;&lt;br /&gt;The following transcript shows this modified shell in action. &lt;a href=http://jarrett.cs.ucla.edu/websvn/filedetails.php?repname=ometa-js&amp;path=%2Fometa-rhino.js&amp;rev=31&amp;sc=0&gt;&lt;tt&gt;ometa-rhino.js&lt;/tt&gt;&lt;/a&gt; is just a file that loads the OMeta/JS implementation and defines &lt;tt&gt;translateCode&lt;/tt&gt; just like I do in the browser, i.e., so that both OMeta and JavaScript are accepted.&lt;pre&gt;  ./v8 ometa-rhino.js --shell&lt;br /&gt;  V8 version 0.3.0&lt;br /&gt;  &gt; ometa M { ones = (1 -&gt; 2)* }&lt;br /&gt;  [object Object]&lt;br /&gt;  &gt; M.matchAll([1, 1, 1, 1], "ones")&lt;br /&gt;  [2, 2, 2, 2]&lt;br /&gt;&lt;/pre&gt;Now if only these guys at Google would hurry up and get Chrome to work on my Mac...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-1384088463048772909?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/1384088463048772909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=1384088463048772909' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/1384088463048772909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/1384088463048772909'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2008/09/modified-v8-shell-w-translatecode.html' title='Modified V8 Shell w/ &lt;tt&gt;translateCode&lt;/tt&gt;'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1714081408739029334.post-7730877520142389395</id><published>2008-08-30T17:54:00.000-07:00</published><updated>2008-09-12T11:13:40.985-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='prolog'/><category scheme='http://www.blogger.com/atom/ns#' term='worlds'/><title type='text'>asserts and retracts with Automatic Rollback</title><content type='html'>Lately I've been working on a paper about &lt;span style="font-style:italic;"&gt;worlds&lt;/span&gt;&amp;mdash;more on this soon&amp;mdash;and while I was looking around for related work I came across something really interesting.&lt;br /&gt;&lt;br /&gt;Consider the different ways of representing state in Prolog. First, there's the &lt;span style="font-style:italic;"&gt;functional&lt;/span&gt; way, in which the state of the entire program is passed around from predicate to predicate in the form of additional arguments. Although burdensome, this approach interacts well with backtracking: when a failure occurs, changes to the program's state are automatically rolled back.&lt;br /&gt;&lt;br /&gt;Another way to represent state in Prolog is to use the built-in database manipulation predicates &lt;tt&gt;assert&lt;/tt&gt; and &lt;tt&gt;retract&lt;/tt&gt;. This &lt;span style="font-style:italic;"&gt;imperative&lt;/span&gt; approach has the advantage of not requiring predicates to take additional arguments, but it unfortunately does not interact well with backtracking. This is because &lt;tt&gt;assert&lt;/tt&gt; and &lt;tt&gt;retract&lt;/tt&gt; are &lt;span style="font-style:italic;"&gt;destructive operations&lt;/span&gt;, i.e., they survive backtracking. So when a failure occurs, the programmer must make sure that each &lt;tt&gt;assert&lt;/tt&gt; is &lt;tt&gt;retract&lt;/tt&gt;ed and vice versa, which is not easy to get right.&lt;br /&gt;&lt;br /&gt;If only the programmer had access to special variants of &lt;tt&gt;assert&lt;/tt&gt; and &lt;tt&gt;retract&lt;/tt&gt; that automatically undo their side effects when backtracked over, the imperative approach would enable some really interesting programming styles that you could never get away with in a "real" imperative language. Interestingly, Tim Menzies shows us how to implement these variants in &lt;a href="http://gollem.science.uva.nl/SWI-Prolog/mailinglist/archive/old/0475.html"&gt;just a few lines of standard Prolog&lt;/a&gt;. (I had never come across this trick before, but Tim's nonchalance makes me think that it's well known in the Prolog community.)&lt;br /&gt;&lt;br /&gt;Here is a variant of the &lt;tt&gt;assert&lt;/tt&gt; predicate that automatically &lt;tt&gt;retract&lt;/tt&gt;s itself upon backtracking:&lt;br /&gt;&lt;pre&gt;  assert2(X) :- assert(X).&lt;br /&gt;  assert2(X) :- retract(X), fail.&lt;/pre&gt;The first clause above makes &lt;tt&gt;assert2&lt;/tt&gt; behave like a regular &lt;tt&gt;assert&lt;/tt&gt; if the query in which it is used succeeds. But if the query fails, the program will eventually backtrack to the point where &lt;tt&gt;assert2&lt;/tt&gt; was used and try the second clause, which &lt;tt&gt;retract&lt;/tt&gt;s the fact &lt;tt&gt;assert&lt;/tt&gt;ed by the first clause.&lt;br /&gt;&lt;br /&gt;Similarly, we might define &lt;tt&gt;retract2&lt;/tt&gt; as follows:&lt;br /&gt;&lt;pre&gt;  retract2(X) :- retract(X).&lt;br /&gt;  retract2(X) :- assert(X), fail.&lt;/pre&gt;But consider what happens if &lt;tt&gt;retract2&lt;/tt&gt;'s argument is not already in Prolog's database. The first clause (which uses &lt;tt&gt;retract&lt;/tt&gt;) will fail, so the program will try the second clause, which will &lt;tt&gt;assert&lt;/tt&gt; a fact that was never &lt;tt&gt;retract&lt;/tt&gt;ed in the first place! We can fix this problem by refactoring &lt;tt&gt;retract2&lt;/tt&gt; into two predicates, as shown below:&lt;br /&gt;&lt;pre&gt;  retract2(X)       :- X, reallyRetract2(X).&lt;br /&gt;  reallyRetract2(X) :- retract(X).&lt;br /&gt;  reallyRetract2(X) :- assert(X), fail.&lt;/pre&gt;And that's that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1714081408739029334-7730877520142389395?l=awarth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awarth.blogspot.com/feeds/7730877520142389395/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1714081408739029334&amp;postID=7730877520142389395' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7730877520142389395'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1714081408739029334/posts/default/7730877520142389395'/><link rel='alternate' type='text/html' href='http://awarth.blogspot.com/2008/08/asserts-and-retracts-with-automatic.html' title='&lt;tt&gt;assert&lt;/tt&gt;s and &lt;tt&gt;retract&lt;/tt&gt;s with Automatic Rollback'/><author><name>Alessandro Warth</name><uri>http://www.blogger.com/profile/05850439404872913450</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_gniDW0J1qOE/SLoBXb4fe6I/AAAAAAAAAIE/QyjqygUXe-s/S220/alex.jpg'/></author><thr:total>0</thr:total></entry></feed>
