Talk:Menu: Difference between revisions

 
(3 intermediate revisions by 3 users not shown)
Line 9:
 
==J implementation==
 
===Code removed===
because it didn't work in Beta-3: commercial/2017-04-10T17:51:14 and was flagged for improvement.
<lang j>require 'general/misc/prompt' NB. in older versions of J this was: require'misc'
showMenu =: i.@# smoutput@,&":&> ' '&,&.>
makeMsg =: 'Choose a number 0..' , ': ',~ ":@<:@#
errorMsg =: [ smoutput bind 'Please choose a valid number!'
select=: ({::~ _&".@prompt@(makeMsg [ showMenu)) :: ($:@errorMsg)</lang>
See [[Talk:Select#J_implementation|Talk page]] for explanation of code.
 
'''Example use:'''
<lang j> select 'fee fie'; 'huff and puff'; 'mirror mirror'; 'tick tock'</lang>
 
This would display:
 
0 fee fie
1 huff and puff
2 mirror mirror
3 tick tock
choose a number 0..3:
 
And, if the user responded with 2, would return: <tt>mirror mirror</tt>
 
--LambertDW 17:59, 8 September 2018 (UTC)
 
 
Note: this description of the code is based on an older version (the line below) and is now out of sync with the copy on the main page.
Line 22 ⟶ 48:
And, as written, it expects the user is displaying the code in a short, wide window (or that they can resize their window that way).
 
===provideProvide reference table===
 
The first part of the code to be executed is:
Line 106 ⟶ 132:
 
Here, we have printed each of the composed strings. A subtle distinction here is that they will be displayed before evaluation of the rest of the sentence.
 
===List indexing===
In all my years, I have never seen:
 
You have two choices:
 
0 go
1 don't go
 
Everybody (except "C" people) are used to choices starting with 1, not zero. Like a book, real people expect
the first page to be 1 (one). Ask anyone for a top ten list, and you won't see 0 --> 9.
 
[[User:Gerard Schildberger|Gerard Schildberger]] 17:38, 21 January 2011 (UTC)
 
:But given the topic of this site, it is ''very'' common to have to consider lists with a minimum index of zero as well as one. --[[User:Paddy3118|Paddy3118]] 21:22, 21 January 2011 (UTC)
 
===prompt user===
Anonymous user