1. Length & Shortcircuit
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Jun 23, 1998
- 440 views
- Last edited Jun 24, 1998
atom a a = 123 ? length(a) Why does this generate an error anyways. I would prefer if it would return 1, since an atom operates the same as an one element sequence! This would make short-circuit even less usable. I often type something like this integer len if atom (x) then len = 1 else len = length(x) end if I can't think of any reason to crash when I request a length, actually. Ralf
2. Re: Length & Shortcircuit
- Posted by Falkon <Falkn13 at IBM.NET> Jun 24, 1998
- 417 views
From: Ralf Nieuwenhuijsen Subject: Re: Length & Shortcircuit >atom a >a = 123 >? length(a) >Why does this generate an error anyways. >I would prefer if it would return 1, since an atom operates the >same as an one element sequence! Nope! They don't always operate the same. If atoms worked the same as one-element sequences, what would this do? atom a a = 123 for count = 1 to length( a ) do a[count] = {} end for Defining objects as one-element sequences, and having them work the same way might make a little more sense...except that a sequence is defined as a set of objects, so you'd have recursive definitions and that'd be confusing... I don't mind calling "if sequence() then" before testing lengths. It's consistent with other sequence functions. Any other function that requires the parameter to be a sequence will do a type-check crash if you pass an atom. Internally, it's something like this: global function length( sequence s ) return( peek(s_address+length_offset) ) end function