revision 1 of the 9.1 manual corrects some typos
Lutz
Not sure where to post this, but I just noticed a primitive function (bind) in newLISP v9.1.1 on Win32. Checked the manual, searched the boards and the net, but I can't find any documentation on the function.
Am I missing something?
'bind' is in the code since 9.0 and not documented because I am not sure if it will stay. It binds all associations in a list of binary associations.
(bind '((x 1) (y 2))) => 2
x => 1
y => 2
The functions 'bind', 'expand', and 'unify' constitute a family of logic programming functions, which I am experimenting with. Don't count on having 'bind' in future versions.
Lutz
Hi Lutz
Is bind the same as this macro?
> (define-macro (my-bind _x) (dolist (z (eval _x)) (apply set z)))
(lambda-macro (_x)
(dolist (z (eval _x))
(apply set z)))
> (my-bind '((x 1)(y 2)))
2
> x
1
> y
2
>
NIgel
Yes, or like this (*):
(define (mybind L) (dolist (i L) (apply set i)))
or shorter faster:
(define (mybind L) (apply set (flat L)))
the built-in 'bind' is still much faster (~ 10x)
Lutz
(*) when all args of a 'define-macro' are evaluated anyway, a simple 'define' will do the same faster
my-bind macro can bind lists whereas using flatten can't
viz
> (define-macro (my-bind _x) (dolist (z (eval _x)) (apply set z)))
(lambda-macro (_x)
(dolist (z (eval _x))
(apply set z)))
> (my-bind '((x (+ 2 3))(y 7)))
7
> x
(+ 2 3)
> (bind '((x (+ 2 3))(y 7)))
7
> x
(+ 2 3)
> (define (mybind L) (apply set (flat L)))
(lambda (L) (apply set (flat L)))
> (mybind '((x (+ 2 3))(y 7)))
symbol expected in function set : 2
called from user defined function mybind
>
NIgel
yes, 'flat' flattens too much ;-), (+ 3 4) should stay unevaluated because 'bind' doesn't evaluate the value part of the association.
Lutz