Thinking about unify example for newLISP, I found, that Erlang style unification can perfectly fit newLISP.
The very cool usage proposal for unification in Erlang is extracting parameters from complex list/touple structures.
I.e.:
Code: Select all
{IP, Port, {Type, Request}} = {"127.0.0.1", 8658, {"GET", "something"}}
will result in bindings:
IP = "127.0.0.1", Port = 8658 and Type= "GET" and Request = "something".
In the other hand, if pattern structure and bound variables/constants will not match, the unification will fail.
But, let's return to newLISP...
newLISP have a good proposal for wide usage of similar unification because it's major and the best data structure is a list, which can be structured.
Say,
Code: Select all
("127.0.0.1", 8658, ("GET", "something"))
Unfortunately, current unify syntax is not so laconic as Erlang.
In short, I propose the new unify engine where
- unification variables (that's are bounded or may be binded) will be represented as regular newLISP symbols, prefixed with "~" (or another one).
The "bound" state of this variables must be handled implicitly. And I suspect, that this variables possible should be local to current function in stack.
- all other newLISP symbols, used in unify will be treated as constant, given by value.
- the short name (say "~") for "unify" ;-)
- the form of define (say define~) which defines the function like an Erlang/Prolog predicate.
- the form of case (say case~) which have variants based on unification patterns.
Consider this virtual example:
Code: Select all
(set 'ip "127.0.0.1")
(set 'rq '('test-assign 1234))
(~ (~ip ~port ~request) (ip 8658 ('SET rq)))
(print ~ip ":" ~port)
# will print 127.0.0.1:8658
(if (member ~ip allowed-ip-list)
(execute-command ~request))
....
(set 'something '("def" 25 4))
(case~ something
(("abc" ~second) (do-something ~second))
(("def" ~second ~third) (+ ~second ~third))
# will return 29
....
(define~ (execute-command ('GET ~what))
(lookup ~what global-prop-list))
# this one will be called for our example
(define~ (execute-command ('SET (~what ~to-what)))
(push (list ~what ~to-what) global-prop-list))
(define~ (execute-command ('CHECK (~what ~to-what)))
(u~ (~what ~to-what) (assoc ~what global-prop-list)))
# here identical to
# (= (list ~what ~to-what) (assoc ~what global-prop-list))
# but in common may be much powerful
I mean' that when we call execute-command, newLISP will pass through all versions of it, trying to unify arguments, and execute the first where unification succeeded.
To Lutz: Probably, this innovation may introduce the new interesting technics into a language, and also will not break other features and preserve backward compatibility.