The "Create your own collection" series should help a bit - these collections all use lib/settable-fn.arc, and with minimal modification should be useable with lib/settable-fn2.arc
'= is a macro, and therefore it needs to know how to assign to the variable at compile time, but the type information is known only at run time, but it should be possible to get something like:
(= (my-table tab 'test) "foo bar baz")
to work. It's a little more verbose and if you changed the name of the type from my-table to something else you would have to change every assignment.
The Problem with unification and logical variables would be that they have to be dynamic in scope and work with a call-by-name evaluation strategy, at least in Prolog.
Anyway, you could build a Prolog-Like DSL with pat-m and amb
While logic Programming in Arc can make problem-solving easier, i think it introduces problems for libraries:
- How should you call functional functions from logical functions?
- How should you call logical functions from functional functions without violating referential transparency?
- Do closures over logical variables make any sense?
- Should goals be limited in scope? Lexical or dynamic? If I call 2 logical functions from different modules I may or may not want the first to be retried when the second fails, depending on the context.
It seems like you want to re-create an idiom from another programming language in arc. What is the language you come from and how would the standard solution to your problem look in it?
That doesn't actually address my concern, but this (from the same page) does:
(if (amb #f #t)
1
(amb))
This has to force the first amb to return #t, or the whole expression would fail. I still find it somewhat odd, though, that I can (fail) on the next line, but I suppose there's not a better way to handle it; after all, that's probably just because the interpreter is sequential.