Comma quibbling: Difference between revisions

Content deleted Content added
Line 1,246:
val it : string = "{ABC, DEF, G and H}"</lang>
===or Another===
====The Function====
<lang fsharp>
let quibble quibbler quibblee = Seq.zip quibblee quibbler //Sorry, just too good a line to miss, back in my Latin classes
let quibble n=
</lang>
let fN=List.mapi(fun n _->match n with 0->"" |1-> " and " |_->", ") n |> List.rev
====The Task====
printf "{"; List.iter2(printf"%s%s") n fN; printfn "}"
<lang fsharp>
quibble["ABC"; "DEF"; "G"; "H"]
let fN n = quibble (List.mapi(fun n _->match n with 0->"" |1-> " and " |_->", ") n |> List.rev) n
quibble["ABC"; "DEF"; "G"]
printf "{"; fN ["ABC"; "DEF"; "G"; "H"] |> Seq.iter(fun(n,g)->printf "%s%s" n g); printfn"}"
quibble["ABC"; "DEF"]
printf "{"; fN ["ABC"; "DEF"; "G"] |> Seq.iter(fun(n,g)->printf "%s%s" n g); printfn"}"
quibble["ABC"]
printf "{"; fN ["ABC"; "DEF"] |> Seq.iter(fun(n,g)->printf "%s%s" n g); printfn"}"
quibble[]
printf "{"; fN ["ABC"] |> Seq.iter(fun(n,g)->printf "%s%s" n g); printfn"}"
printf "{"; ListfN [] |> Seq.iter2iter(fun(n,g)->printf "%s%s") n fNg); printfn "}"
</lang>
{{out}}