revision 1 of Manual and Reference 9.1

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

revision 1 of Manual and Reference 9.1

Post by Lutz »

revision 1 of the 9.1 manual corrects some typos

Lutz

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

bind

Post 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?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Lutz

Locked