Talk:Search a list: Difference between revisions

"indexable, ordered collection" vs. "indexable ordered collection"
(→‎REXX Version 3: new section)
("indexable, ordered collection" vs. "indexable ordered collection")
 
(3 intermediate revisions by 3 users not shown)
Line 5:
:::You may be right. The collection type is obviously not the focus of this task, so it shouldn't be restricted if collections other than arrays fit the bill. It shouldn't be restricted to "haystack[i]" because first, some languages don't use that syntax and second, some collections which do support indexing do it through functions and methods (like nth from List or ArrayList.get() from Java). It should work for collections where if I run this function and get an index, then add an element to the "end" of the collection (that is, add an element to an end of the collection so that its index is greater than the index I got when I ran the function), then run the function again with the same arguments, I should get the same number. If that sounds like an OK specification, then which collections match it? --[[User:Mwn3d|Mwn3d]] 16:59, 26 November 2008 (UTC)
:I have changed the wording to indexable ordered collection which would include arrays, lists, tuples, hashes/dictionaries ... and removed access syntax which does not apply in some manguages. I hope it is suitably generic. --[[User:Paddy3118|Paddy3118]] 06:46, 27 November 2008 (UTC)
::The actual phrase on the Task page is "indexable, ordered collection", with a comma, implying a collection that's both indexable and in order (presumably ascending). All the solutions here seem to have copied each other in reading it as "indexable ordered collection" — an ordered (as opposed to labelled) collection that's also (superfluously?) described as indexable. Which is meant? --[[User:Nig|Nig]] ([[User talk:Nig|talk]]) 08:51, 9 July 2020 (UTC)
 
:P.S. I couldn't help extending the task too. --[[User:Paddy3118|Paddy3118]] 06:46, 27 November 2008 (UTC)
Line 23 ⟶ 24:
<br>Using '0' instead of '_' would be safer. _gold is a valid variable name, 0gold is not.
<br>--[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 18:57, 20 August 2015 (UTC)
 
-----
 
The full quote from the original statement is:
 
:: ''This method pre-prends an underscore (underbar) to avoid collision with any REXX variable names''. &nbsp; ''Therefore, there shouldn't be any REXX variable names (in this program) that have a leading underscore &nbsp; (_)''.
 
The underscore &nbsp; (_) &nbsp; was chosen to make the REXX code more readable,
<br>it was not claimed that &nbsp; ''_gold'' &nbsp; wasn't a valid REXX variable name.
<br>The use of a pre-pended zero makes the elements harder to read/peruse. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 21:19, 25 August 2015 (UTC)
 
==Raising an exception?==
 
The task description says "''Raise an exception if the needle is missing.''" - however, many of the solutions don't do this. Instead, they rather print a string like "needle not in haystack" to STDOUT in this case and resume the program. The Python solution, for example, even goes out of its way to ''suppress'' the exception that would naturally be thrown. Also, some languages don't even <i>have</i> exceptions.<br>
I propose changing that sentence of the task description, to: "''Print an appropriate message if the needle is missing.''" Any objections?<br>
--[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 11:14, 5 August 2016 (UTC)
 
* It's a good suggestion, and the reference to exceptions was probably always a bit parochial - exception-raising is more relevant to imperative languages and coding idioms than to function composition and functional languages. (A functional language might more typically, for example, use an option type (Maybe etc) and pass the invalid/undefined status of a result up through the composition chain). Hout
557

edits