accessing a list number by a symbol for a list

Started by Tim Johnson, May 03, 2010, 02:56:46 PM

Previous topic - Next topic

Tim Johnson


> (set 'record '(("name" "Tim")(age 61)))  
(("name" "Tim") (age 61))
> (set 'indices '(1 0))
(1 0)
> (record indices)
age    ;; correct
> (set 'ndxs '(a b))
(a b)
> (record ndxs)
ERR: value expected :  ;; duh!

So how may I 'bind' the values in 'ndxs to the implicit indexing of 'record?

I'm hoping there is a tie-in to the previous question, I.E. I might want to

index 'record by a slice of the values in 'ndxs also.

thanks

tim
Programmer since 1987. Unix environment.

Sammo

#1
Would this work?
> (set 'record '(("name" "Tim")(age 61)))
> (set 'ndxs '(a b))
> (set 'a 1 'b 0)
> (record (map eval ndxs))
age

Tim Johnson

#2

> (record (map eval ndxs))

Sure does. 'map threw me for a bit of a loop because
(record (map (eval ndxs)))
generates an error.

thanks.
Programmer since 1987. Unix environment.

Tim Johnson

#3
And we use 'slice as in
(slice (map eval ndxs) 1)

Implicit indexing is great feature. I might add to the documentation of

this subject something of the subject here.



I.E. use of symbols, etc.



:)But then, I'm a real noob when it comes to the functional programming paradigm.
Programmer since 1987. Unix environment.