comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: code snippet
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: code snippet [message #25295 is a reply to message #25294] Tue, 29 May 2001 14:21 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Hi,

Ken Mankoff wrote...

> Hi everyone,
>
> i just ran across this in an IDL (its inside 'map_continents.pro')
> procedure, and thought its behaviour was pretty neat. [...]
>
> IDL> key = 2
> IDL> ;;; set 'key' to 0 or 1 or 2 or ...
> IDL> possibilities = ['first','second','third','fourth']
> IDL> choice = (possibilities)[key]
> IDL> help, choice
> CHOICE STRING = 'third'

Perhaps less neat is the (equivalent) simple array access:

choice = (possibilities)[key]

But neater still is subscripting an array built on-the-spot
(again equivalent to the original):

choice = (['first','second','third','fourth'])[key]

Note that all parentheses and brackets are required here.

Cheers,
--
-Dick

Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: how to set path?
Next Topic: Sorting and image rescaling

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:05:01 PDT 2025

Total time taken to generate the page: 0.00423 seconds