-
-
Save enolan/126924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Goal: Turn Array `["foo", "bar", "baz"]` into String `"ordered: 1=foo 2=bar 3=baz"`. | |
; Clojure | |
;; Read arguments from command line | |
;; (def argv *command-line-args*) | |
;; Fake command-line arguments for use in REPL | |
(def argv (seque ["foo" "bar" "baz"])) | |
(println "ordered:" | |
(apply str | |
(interpose " " | |
(map | |
#(str (first %) "=" (last %)) | |
(map vector | |
(iterate inc 0) | |
argv))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plain Ruby | |
a = [] | |
%w[foo bar baz].each_with_index do |word, i| | |
a << "#{i}=#{word}" | |
end | |
puts "ordered: #{a.join(' ')}" | |
# Ruby with Facets | |
require 'rubygems' | |
require 'facets/enumerable/map_with_index' | |
puts "ordered: " + %w[foo bar baz].map_with_index{|word, i| "#{i}=#{word}"}.join(" ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
main = getArgs >>= | |
putStrLn . ("ordered: "++) . unwords . zipWith (\a b->show a++"="++b) [1..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment