revision 1 of Manual and Reference 9.1

Started by Lutz, April 06, 2007, 12:55:13 AM

Previous topic - Next topic

Lutz

revision 1 of the 9.1 manual corrects some typos



Lutz

m35

#1
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?

Lutz

#2
'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

nigelbrown

#3
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

Lutz

#4
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

nigelbrown

#5
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

Lutz

#6
yes, 'flat' flattens too much ;-),  (+ 3 4) should stay unevaluated because 'bind' doesn't evaluate the value part of the association.



Lutz