-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use higher-order predicates for more convenience #1
Comments
Oh, those are great, I'll refactor it tomorrow! Also, do you know if this free var manipulation (detecting free vars and replacing them with atoms) is something which is normal in Prolog or is there a more idiomatic way to do it? |
The best way to reason about variables within your program is to choose a good representation for your data. In an initial conversion step, you will likely need impure checks like Throughout the remainder of your program, you can simply distinguish the cases symbolically: some_predicate(a(Atom)) :- ... some_predicate(v(Var)) :- ... |
That's a pretty cool trick, another thing I wondered is how prolog-y is using dicts (I used assoc lists, because I wanted to support SWI 6, so I guess dicts are a recent addition, but on the other side dict data structures are very popular in most other languages lately, including lisps: Clojure) |
Association lists are a fine and also very portable way to do such lookups, and their performance is often completely acceptable. Dicts may be useful if you do a let of web programming and JSON interactions, but they will chain you to a specific Prolog system. |
The following two higher-order predicates may turn out very helpful, also in future extensions:
maplist/3
, for example in:maplist(pretty_type, Ls0, Ls)
, avoiding an auxiliary predicatefoldl/4
to avoid or shortenreplace_vars_/6
I hope this helps to make the code a bit shorter and more readable.
The text was updated successfully, but these errors were encountered: