Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^7: Array/List Strangeness

by jethro (Monsignor)
on Aug 05, 2009 at 13:06 UTC ( [id://786096]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Array/List Strangeness
in thread Array/List Strangeness

Well, Taulmarill was questioning Ikegamis words 'non-existing array element'. So I'm just pointing out that there is a real difference between non-existing array element and undef'd array element (even if we would wish otherwise to have more consistency).

++ for what you are saying after 'Basically:', an excellent description of the situation

Replies are listed 'Best First'.
Re^8: Array/List Strangeness
by Taulmarill (Deacon) on Aug 05, 2009 at 13:29 UTC
    I admit that i might have misunderstood something here .... although i'm not sure what....

    Could we from now on agree not to talk about (non)existing array elements, but about elements <= $#array and elements > $#array. That might make things easier for my twisted, sleep deprived mind.

    update: also i'd like $[ to stay 0.
      Could we from now on agree not to talk about (non)existing array elements,

      Well we have an exists function, why shouldn't we talk about (non)existing array elements? :-)

      Existence is an an important point to describe the behaviors of slicing, i.e. mostly returning undef for non-existing elements. (And I think what ikegami meant)

      Let's express it in LRTs (Lanx's Rule of Thumb ;-)

      1. Arrayslices (and hashslices) always return values for all requested elements. Not existing elements are represented as 'undef'.

      DB<1> @a=1..2 DB<2> x @a[0,1] 0 1 1 2 DB<3> x @a[0,3] 0 1 1 undef DB<4> x @a[2,3] 0 undef 1 undef DB<5> @a=() DB<6> x @a[1,2] 0 undef 1 undef
      2. Listlices work alike if and only if at least one of the requested elements exists. Otherwise it returns an empty list.

      DB<5> x (1,2)[0,1] 0 1 1 2 DB<6> x (1,2)[0,3] 0 1 1 undef DB<7> x (1,2)[2,3] # DIFFERENT! empty array DB<8> x ()[0..3] # DIFFERENT! empty array DB<9> x (undef,undef)[0,2] 0 undef 1 undef

      Note: Maybe the x command in the debugger should better say "empty list" instead of "empty array"....

      Please correct me if I missed something with this "model" of slice behavior.

      Cheers Rolf

Re^8: Array/List Strangeness
by LanX (Saint) on Aug 05, 2009 at 16:36 UTC
    ++ for what you are saying after 'Basically:', an excellent description of the situation

    Actually it should be defined what "empty" means. undef can be an existing element of a list!

    DB<1> p scalar ( ()=(undef,undef) ) 2

    Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://786096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-20 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found