A Logo program, "choices":
###
to choices :menu
foreach crossmap "sentence :menu "print
end
###
Invoke the program like this:
###
choices [[small medium large]
[vanilla [ultra chocolate] lychee [rum raisin] ginger]
[cone cup]]
###
The program responds with:
###
small vanilla cone
small vanilla cup
small ultra chocolate cone
small ultra chocolate cup
small lychee cone
small lychee cup
small rum raisin cone
small rum raisin cup
small ginger cone
small ginger cup
medium vanilla cone
medium vanilla cup
medium ultra chocolate cone
medium ultra chocolate cup
medium lychee cone
medium lychee cup
medium rum raisin cone
medium rum raisin cup
medium ginger cone
medium ginger cup
large vanilla cone
large vanilla cup
large ultra chocolate cone
large ultra chocolate cup
large lychee cone
large lychee cup
large rum raisin cone
large rum raisin cup
large ginger cone
large ginger cup
###
If you want to see solutions posted in various languages, go here:
choices(`small`medium`large;`vanilla`ultra_chocolate`lychee`rum_raisin`ginger
(`small `vanilla `cone
`small `vanilla `cup
`small `ultra_chocolate `cone
`small `ultra_chocolate `cup
`small `lychee `cone
`small `lychee `cup
`small `rum_raisin `cone
`small `rum_raisin `cup
`small `ginger `cone
`small `ginger `cup
`medium `vanilla `cone
`medium `vanilla `cup
`medium `ultra_chocolate `cone
`medium `ultra_chocolate `cup
`medium `lychee `cone
`medium `lychee `cup
`medium `rum_raisin `cone
`medium `rum_raisin `cup
`medium `ginger `cone
`medium `ginger `cup
`large `vanilla `cone
`large `vanilla `cup
`large `ultra_chocolate `cone
`large `ultra_chocolate `cup
`large `lychee `cone
`large `lychee `cup
`large `rum_raisin `cone
`large `rum_raisin `cup
`large `ginger `cone
`large `ginger `cup)
"pineapple" <pineapp...@yahoo.com> wrote in message news:a3076ded-d9b9-49e5...@a29g2000pra.googlegroups.com...
choices=: >@,@{
format=: ([: }.@; ' ' ,&.> ])"1
format choices ('small';'medium';'large');('vanilla';'ultra
chocolate';'lychee';'rum raisin';'ginger');<('cone';'cup')
A slightly simpler version of format:
format=: ((<' ') }.@;@,. ])"1
Of course there is no need to reinvent the wheel for format. You could
use existing utilities from the strings script, or the tables/dsv
addon.
load 'strings tables/dsv'
arg=: ('small';'medium';'large');('vanilla';'ultra
chocolate';'lychee';'rum raisin';'ginger');<('cone';'cup')
' 'joinstring"1 >,{ arg
or
' 'makedsv >,{ arg
>choices [[small medium large]
> [vanilla [ultra chocolate] lychee [rum raisin] ginger]
> [cone cup]]
Your encoding appears to be a bit inconsistent: inner inner list
seem to encode mutli-word strings instead of alternives, if I look
at your requested output. I'll take liberty to simplify this aspect;
in order to save columns and calories, I'll also drop the ultra choc:
]options =. ;:each 'sml med lrg';'van lyc rum_raisin ginger';'cone cup' +-------------+---------------------------+----------+
|+---+---+---+|+---+---+----------+------+|+----+---+|
||sml|med|lrg|||van|lyc|rum_raisin|ginger|||cone|cup||
|+---+---+---+|+---+---+----------+------+|+----+---+|
+-------------+---------------------------+----------+
>to choices :menu
> foreach crossmap "sentence :menu "print
>end
The "crossmap" equivalent in J is "{" aka Catalogue:
{ options
+---------------------+--------------------+
|+---+---+----+ |+---+---+---+ |
||sml|van|cone| ||sml|van|cup| |
|+---+---+----+ |+---+---+---+ |
+---------------------+--------------------+
|+---+---+----+ |+---+---+---+ |
||sml|lyc|cone| ||sml|lyc|cup| |
|+---+---+----+ |+---+---+---+ |
+---------------------+--------------------+
...yadda yadda, shape 3 4 2 of length-3 box lists.
The rest just takes care of unpacking the boxes into nice strings:
;:^:_1 > , { options
sml van cone
sml van cup
sml lyc cone
...
lrg rum_raisin cup
lrg ginger cone
lrg ginger cup
Martin Neitzel
I like ;:^:_1 !!!
monadic ;: is Words (box a string/sentence into J "words")
^:_1 is inverse so ;:^:_1 is the inverse of Words and unboxes words
into a string/sentence.
Identify this language. Is it K?
reminds me of an example in the VAX APL manual (page 1-178), defined as an
"odometer"
http://www.softwarepreservation.org/projects/apl/book/199106_VAX%20APL%20Reference%20Manual_AA-GV09C-TE.pdf
Funny, when I implemented a solution to this off the top of my head, I
modeled an odometer.
the example is on numbers only,
,/{shoe}{jot}{dot}, /{iota}{each} V (V e.g. 1 2 3)
1 1 1 1 1 2 1 1 3 1 2 1 1 2 2 1 2 3
but I guess on strings it will need a slight modification
jk
oops!
should be ,{shoe}{jot}{dot},/{iota}{each} V
and {take},{shoe}{jot}{dot},/{iota}{each} V
gives us