Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: What's wrong with Ruby

From: Michael_Chean:msn at: 26-Mar-2007 10:13

It would be interesting to see some of the other examples ----- Original Message ----- From: Paavo Nevalainen<mailto:Paavo.Nevalainen-saunalahti.fi> To: rebolist-rebol.com<mailto:rebolist-rebol.com> Sent: Monday, March 26, 2007 5:58 AM Subject: [REBOL] Re: What's wrong with Ruby I taught students some basic principles of programming, including concepts of algorithm, function, and such. One result of the course was list of small programing tasks implemented in various languages. An example was to pseudonymize one's name with these rules: 1) invert all words 2) initial letters to capitals 3) sort the shortest ones first As you see, Perl equivalent is not done. You can add it and post to me, if you wish. The codes do not have exactly same behaviour when input is completely odd (more than one capital letter per word, too short words and such). ;---------------------- Rebol equivalent --------------- do load %aids.r pseudonymize: function [ fullname [string!] ][ names ][ names: parse lowercase reverse copy fullname "" names: map func [x][ return uppercase/part x 1 ] names sort/compare names func [x y][(length? x) < length? y] return rejoin fill-in-between names " " ] ; fill-in-between left as an exercise to the reader ;) test: does [ print pseudonymize ask "Your name: " ; An example: pseudonymize "Masutatsu Oyjama bin Laden" ; --> "Nib Nedal Amajyo Ustatusam" ] -- Lua equivalent -------------------------------- function pseudonymize(name) name0= string.reverse(string.lower(name)) words= {} for w in string.gmatch(name0, "%a+") do words[#words + 1]= string.upper(string.sub(w,1,-#w)) .. string.sub(w,2,-1) end table.sort(words, function(w1,w2) return #w1 < #w2 end) return table.concat(words, " ") end -- test: print( pseudonymize("Veronica von Wassenshaft")) -- result: "Nov Acinerov Tfahsnessav" # Ruby: ----------------------------------------- def pseudonymize(name) names= Array.[] name.reverse.downcase.each(' ') { |s| names << s.chomp(" ").capitalize } names.sort {|x,y| x.length <=> y.length} names= names.reverse out= "" names.each {|x| out << x << " "} out.chomp(" ") end p pseudonymize("Abu Baba Imaam") # Python equivalent ------------------------------------ def pseudonymize(name): name= string.join(list(name.lower()).reverse())) Words= [] for word in string.split(name): word= word[1:1].upper() + word[2:] return string.join(words) Perl -------------------------------- ?? not done yet, do it yourself please ?? -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject.