Talk:Menu: Difference between revisions

 
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.
Anonymous user