accessing a list number by a symbol for a list

Q&A's, tips, howto's
Locked
Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

accessing a list number by a symbol for a list

Post 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
Programmer since 1987. Unix environment.

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

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

Post 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

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

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

Post 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.
Programmer since 1987. Unix environment.

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

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

Post 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.
Programmer since 1987. Unix environment.

Locked