Page 1 of 1
revision 1 of Manual and Reference 9.1
Posted: Fri Apr 06, 2007 7:55 am
by Lutz
revision 1 of the 9.1 manual corrects some typos
Lutz
bind
Posted: Sun May 06, 2007 1:35 pm
by m35
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?
Posted: Sun May 06, 2007 2:00 pm
by Lutz
'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.
Code: Select all
(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
Posted: Sun May 06, 2007 9:50 pm
by nigelbrown
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
Posted: Sun May 06, 2007 10:07 pm
by Lutz
Yes, or like this (*):
Code: Select all
(define (mybind L) (dolist (i L) (apply set i)))
or shorter faster:
Code: Select all
(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
Posted: Mon May 07, 2007 12:32 am
by nigelbrown
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
Posted: Mon May 07, 2007 12:40 am
by Lutz
yes, 'flat' flattens too much ;-), (+ 3 4) should stay unevaluated because 'bind' doesn't evaluate the value part of the association.
Lutz