newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on December 01, 2006, 12:50:53 AM

Title: Lookup ?
Post by: newdep on December 01, 2006, 12:50:53 AM
Hi Lutz,



Why are these examples below not working? the lookup explanation says:



"Finds in assoc-list an association the key element of which has the same  value as exp ........."





The (sym "10") returns also an Atom called 10, or is it an evaluation issue

in 'lookup..?



The confusing part is that they are all atoms.. but not symbols ofcourse,

so does 'lookup like symbols? or only atoms? If only atoms then it should

work with (sym "10")









(setq order '( 10    (0 1 2 11 20 19 18 9)))

(setq R (sym "10"))







> (symbol? (order 0 0))

nil

> (atom? (order 0 0))

true

> (symbol? (sym "10"))

true

> (atom? (sym "10"))

true







> (lookup (sym "10") order)

nil



> (lookup R order)

nil



> (lookup (first (list (sym "10"))) order)

nil





This is working, but officialy '10 is an invalid atom! ircc...



> (lookup '10 order)

(0 1 2 11 20 19 18 9)



These are the only one working..but for me just the same as the examples above..



> (lookup 10 order)



> (lookup (first (flat '((10)))) order)

(0 1 2 11 20 19 18 9)





Norman.
Title:
Post by: Lutz on December 01, 2006, 08:44:14 AM
'order' in your example is not an association list. An association list is a list of lists. 'lookup' will check the first member to find the matching association, then takes by default the last element.  If you define 'order' correctly it will work:



> (setq order '( (10) (0 1 2 11 20 19 18 9)))
((10) (0 1 2 11 20 19 18 9))
> (lookup 10 order)
10
> (lookup 0 order)
9
> (lookup '0 order)
9
> (lookup '10 order) ; lookup evaluates args and takes the quote off
10
> (lookup (sym 0) order) ; expected because 'order' has numbers
nil
> (lookup (sym 10) order) ; expected becuase 'order' has numbers
nil
>


Lutz