Page 1 of 1

accessing a list number by a symbol for a list

Posted: Mon May 03, 2010 9:56 pm
by Tim Johnson

Code: Select all

> (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

Re: accessing a list number by a symbol for a list

Posted: Tue May 04, 2010 1:19 am
by Sammo
Would this work?

Code: Select all

> (set 'record '(("name" "Tim")(age 61))) 
> (set 'ndxs '(a b))
> (set 'a 1 'b 0)
> (record (map eval ndxs))
age

Re: accessing a list number by a symbol for a list

Posted: Tue May 04, 2010 2:13 am
by Tim Johnson

Code: Select all

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

Code: Select all

(record (map (eval ndxs)))
generates an error.
thanks.

Re: accessing a list number by a symbol for a list

Posted: Tue May 04, 2010 3:34 pm
by Tim Johnson
And we use 'slice as in

Code: Select all

(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.