Last week I learned Python. It's not perfect but it's pretty damn cool.
This week I'm starting on Ruby. I've just encountered blocks and I would approve if someone would answer this: are blocks merely an ugly kludge because the author did not know about lambda expressions, or can they do something lambdas can't?
Name:
Anonymous2005-04-12 15:54
for this to answer truthfully, i first need to know what python lambdas can do ruby blocks can't.
Lambda expressions implement Church's lambda calculus. As with any good feature they're ripped straight out of Lisp. From what I can tell blocks seem to produce a similar result only more ugly.
After I posted this blatant attempt to produce drama, I checked around on that ever useful resource: Google. Seems a bunch of people I never heard of agree with me.
Name:
Anonymous2005-04-12 19:25
I doubt that blocks can do more than lambda expressions. If they could do more, no turning machine could implement them.
Name:
Anonymous2005-04-13 4:23
I don't like the |name| notation for block arguments. It looks somewhat like an absolute value but has no place there. :(
Name:
Christy McJesus!DcbLlAZi7U2005-04-13 5:18
>>6
That's what got me. The whole idea of passing arguments into blocks seems semantically weird to me; the fact that it needs it's own special syntax should set off warning bells.
Actually this morning I thought of one way the two are different: lambda expressions may only be composed of expressions. In blocks you're allowed statements.
Not techically a limitation if you're coding in a clean, functional style, but I can see how it could be inconvenient. However if you do need to pass a more complicated function you can still do it the "normal" way by just giving it a name.
Next question: you use the "yield" statement to execute a block in ruby. Does this mean you can't have more than one block as a parameter to a ruby function? If so that's a limitation right there.
Name:
Anonymous2005-04-13 7:42
It looks somewhat like an absolute value but has no place there
the notation comes from smalltalk, where |variable| denotes a local variable afaik.
Does this mean you can't have more than one block as a parameter to a ruby function?
seems like it, though i haven't bothered much with research. i consider blocks syntactic sugar:
open "file" do |file_obj| puts file_obj.read end
instead of, say, open("file", proc {|f| puts f.read})
or something. of course, there may be more to it but if you really want to find out, ask on the ruby-ml or search the archives: http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml
ruby/tk objects for example evaluate blocks in the instance's context which i found fairly convenient. lf = TkLabelFrame.new(top_frame) do text "labelframe" end
if you *do* want to pass more than that, you can still use lambdas. they're called "proc" (or it's synonym "lambda") in ruby-speak. blafunc = proc {|x,y,z| puts x,y,z; puts "hello"} # { ... } can be replaced with do ... end blafunc.call "x", "y", "z" process_file(file, proc {|f| somecode()}, another_proc_obj)
essentially the same as in python/lisp i assume.
Name:
Anonymous2005-04-13 11:53
Python has 2000 attack 1000 defense, but ruby has 1000 attack 1200 defense and Ruby Beam Erementar Flush! Combine this with Shining White Ultimate Combine and you will counter anything!
I've also been finding Python's class system is really annoying, especially when compared to Ruby's. I'm starting to feel Ruby is gonna be the way to go for me, especially with all the commotion Rails is causing.>>11
Name:
Anonymous2005-04-17 16:32
Just try this:
Python: [ x**2 for x in xrange(100000) if x % 2 == 0]
Ruby: (1..100_000).select { |x| x % 2 == 0 }.map { |x| x**2 }
RUBY WINS! Python is ten times slower!
Name:
Anonymous2005-04-17 16:36
Seriously, you can store blocks in variables and give multiple blocks to a function. There is no real difference with lambda functions in functionnal programming, I guess the creator just wanted to be original or try a different syntax.
>>8
lambda, procs and Blocks are the same thing in Ruby!
Name:
Anonymous2005-04-18 1:26
lambda functions are anonymous functions that are restricted to one line. what the fuck is so great about that?
>>14
I know this, it just seems weird, and not in a good way. It's like matz was too object obsessed to allow for functions, as opposed to methods, and invented the idea of blocks to serve the exact same purpose except with a weird syntax and they're not called functions. Wrapping a block in a lambda/proc lets you call it just like a function, so why not make it a function in the first place?
Seriously it's just a little niggle, but you notice such things more when the rest of the language is so well designed.
Name:
Anonymous2005-04-19 10:06
>>16
Blocks were copied from Smalltalk. Ruby is pretty much a mix of Smalltalk and Perl.
Name:
Christy McJesus!DcbLlAZi7U2005-04-19 17:42
>>17
o rly.
I knew the object system is lifted straight from smalltalk, and I'm pretty impressed with it to be honest.
Name:
Anonymous2005-05-10 8:07
Please learn Lisp.
You can't compare Python's lambda to Lisp's becasue there are no let blocks. So assignments are pretty much impossible, which restricts lambda blocks a lot.
Name:
Christy McJesus!DcbLlAZi7U2005-05-10 12:00
>>19
Not forgetting that Python relies on statements instead of making everything an expression, which is hardly a difficult feat. Yes you're right, Python's lambdas are pretty much crippled. But the lambda calculus, when implemented properly in a real language, is very powerful. Which is why I suggested that the good sir >>15 should learn lisp :-)
>>11
Guido is a fucker in this respect, there'll be a lot of outcry if Guido actually removes lambdas. So I don't think he'll do it. Lambdas were a compromise in the first place and Guido doesn't like them so he wants 'em gone.
rsplit = lambda S, I=' ', C=-1: (lambda L: len(L) == 1 and L or L.extend(map(lambda L: L.pop(), (L,)*(len(L)-1))) or L)((lambda L: L.insert(0, I.join(L.pop(0))) or L)((lambda L: L[0].reverse() or L)((lambda L: L.insert(0, L.pop(0).split(I)) or L)((lambda L: L.insert(0, L.pop()) or L)(I.join((lambda L: L.reverse() or L)(list(S.split(I)))).split(I, C))))))
Because I should be able to. I'm told ZOMG EVERYTHING IS AN OBJECT YOU CAN SUBCLASS EVERYTHING EVEN BUILT IN TYPES but when I try to subclass Integer it doen't work :(
Name:
Anonymous2005-06-06 6:20
You need to make Integer WANT to be subclassed.
Name:
Anonymous2005-06-06 19:19
>>30 Dressed like that? It's pretty clear what Integer WANTS. ;)
Name:
Anonymous2005-06-08 21:34
It should be a bug then
Integers are not treated the same way as other objects. A normal object is reference to a structure or something, but integers are not.
Name:
Anonymous2005-06-09 4:27
>>32
I don't disagree if that's what the language specification says, but... Why on holy Earth do you want to make an integer a reference to a structure!?!?
No wonder why crapware is that slow.
Name:
Christy McJesus!DcbLlAZi7U2005-06-09 7:51
>>32
That's true, but the language semantics are supposed to hide the fact that numbers are done at machine level.
Name:
Anonymous2005-06-09 12:04
>>34
They could make a special option, --with-real-integers, which would wrap all basic types so you can subclass them, at the cost of 15% slower programs. I personally wouldn't use it.
But I can still speculate that the problem is because Integer wraps up Fixnum and Bignum.
Name:
abez!XWEgiX8ArQ2005-06-20 16:59
When there is Perl and Ruby, why do you need python?
Name:
Anonymous2005-06-20 20:31
because Guido brainwashed everybody
Name:
Anonymous2005-06-21 4:07
I took a look at the most popular scripting languages, here's what I thought of them:
- Perl: Nice and powerful, but write-once, so it's not that good for large applications.
- PHP: Perl's syntax fixed, less useful stuff, but the very best for web apps due to productivity and the ability to accomodate both basic and real programmers to get stuff done, and working good.
- Ruby: Unnecessarily cOOmplex. Looks like I'll create an ActionCreator object to create an Ignore action implementing the DoStuff interface, and send a doThis message to it.
- Python: Looking good. On second thoughts, I love the fact you're forced to indent your code. I'm tired of reading noob code.
I went for Perl at first, but quickly switched over to PHP because I'm getting paid to do stuff, not to brag at what I'm using. I'll learn Python as soon as I can, it looked good too.
Name:
abez!XWEgiX8ArQ2005-06-21 4:16
If you haven't use packages, objects or classes in Perl you should be careful of the assertions you make about its suitability for large applications.
Name:
Christy McJesus!DcbLlAZi7U2005-06-21 4:29
>> Ruby: Unnecessarily cOOmplex. Looks like I'll create an ActionCreator object to create an Ignore action implementing the DoStuff interface, and send a doThis message to it.
You sure do like assuming all OO is like Java don't you.
Java is not a good example of OO - get over it.
Name:
Anonymous2005-06-21 7:22
ruby is awesome no wonder why japaneses are dominating the
lenguage, beyond abstract, a lot of one liners, of course
its a one man lenguage, but being it a very abstract lenguage
it offers a lot of quick weird ways for doing things.
doing 10 things with one line is plain fucking awesome.
for me u are just noobs, if you dont see the power of ruby
(not as an all purpose lenguage of course)
Is this some kind of ``let's see who can age more threads from the fucking Bronze Age'' contest? Suddenly, the front page is almost filled with ancient threads.
I lovehate it when I start reading a post, think "lol what a tard", continue reading, think "hmm this seems familiar", then notice the name field and it's me from back when I was a tripfag.
>>54
Well since then I decided that Ruby was indeed superior to Python, then went and fapped over Smalltalk, later tried to get back into Scheme again but was forced to admit that however beautiful it is I'll never use it for anything more than toys.
Now I'm having insane amounts of fun with Haskell. It's a bit syntaxful for someone used to Lisp and code generators are a pain to write when you're not dealing in sexps, but apart from that it's pure win.
Name:
Eleo2007-06-12 17:58 ID:Uz0m3D6+
You guys always have conversations that are way over my head. How come every time I come to this board it seems like I know so little?
Name:
Anonymous2007-06-12 19:05 ID:Q3MUZOzz
>>1
Mostly a matter of syntax. Ruby's syntax sucks, but its feature set is somewhere in the middle of "pretty fucking similar" and "exactly the same" as Python, at least for today's Python.
WTF, now I realize I'm replying to McJesus from a very long time ago. I remember him, but he hasn't been around, or he stopped being a name/tripfag. After reading >>53 , I'm glad to find he's still around, though he has become a Haskellfag ;__;
I miss the old times, when you achieved satori with LISP.
>>59
Hay buddy. Yeah I joined the Anonymous hoard awhile back after finally accepting that it's the right way. But it's nice to revisit old times by using my old tripcode. Thanks >>51 for giving me this opportunity to relive my faggy past.
Oh and I still love Lisp, I just find Haskell more suitable for getting Real Work Done (TM)
Name:
Anonymous2007-06-13 4:41 ID:YRDwhzuo
In Soviet Russia, Integer Subclasses YOU!!
Name:
Anonymous2007-06-13 4:54 ID:KbX2kcpU
>>58
I learnt most of what I know thanks to fags mentioning in here in /prog. Believe it or not, this troll board proved to be more useful than years of uni for me.
Name:
Anonymous2007-06-13 6:40 ID:qsCeF0U5
>>62
We should start giving out EXPERT PROGRAMMER degrees, with a variety of majors such as haskellfaggotry.
Name:
Anonymous2007-08-23 10:17 ID:vIk9pSAb
>>62
Same here, I never would've got into Haskell if it weren't for this shithole board. Ha!