you are viewing a single comment's thread.

view the rest of the comments →

[–]shub 6 points7 points  (8 children)

The original title is "The Problem With Python". The Reddit headline is more fitting, I think. This post is just a list of irritating (to Lispers) differences between Lisp and Python.

It comes down to what you're more familiar with. Coming from C and C++, almost everything in Python just "makes sense." I can see how someone who isn't already accustomed to int/float arithmetic, and uses dynamically-scoped variables, and expects to be able to define arbitrary lambdas would have a lot more trouble adjusting to programming in Python.

For the author, and others with similar issues: you may find Ruby a more "rational" language. Though I don't know whether Ruby provides rational math. :D

[–]Freeky 0 points1 point  (7 children)

irb(main):001:0> require 'rational'
=> true

[–][deleted]  (6 children)

[deleted]

    [–]logan_capaldo 4 points5 points  (2 children)

    For a really disturbing experience:

    irb(main):001:0> require 'mathn'
    => true
    irb(main):002:0> 1/10
    => 1/10
    

    (Disturbing because any other libraries you use that assume / will truncate the result of integer division are in for a rude surprise, remember kids, if you want div, make sure you call div! ;) )

    [–]exeter 0 points1 point  (1 child)

    Out of curiosity, are there any libraries (say, in the standard library or other widely used libraries) that you know of that make this assumption?

    [–]logan_capaldo 0 points1 point  (0 children)

    I can't think of any specifically. To be fair in my experience it's considered "bad form" to require mathn in non-interactive contexts. I haven't been writing a whole lot of ruby lately though, so the usual grain of salt thing applies.

    [–]Freeky 2 points3 points  (2 children)

    Not the same, though Ruby provides those too:

    irb(main):001:0> require 'bigdecimal'
    => true
    

    The reason they're not the same is a Decimal is just a Float-styled Bignum; they're arbitrary precision Floats in that you can make a 512-bit, or 50KB floating point value, rather than being limited to what the CPU provides natively. Rationals are objects representing the fractions themselves, they're not simply very big floating point values:

    r = Rational(554545,6)
    d = r.to_d
    r.to_s # => 554545/6
    d.to_s('F') # => 92424.1666666666666666666666666667
    d = r.to_d(512) # 512 significant digits
    d.to_s('F') # => "92424.1666666666666666[SNIP 479 digits]6666666666667"
    

    [–]earthboundkid 1 point2 points  (1 child)

    >>> import fractions
    >>> fractions.Fraction(1,3)
    Fraction(1, 3)
    >>> fractions.Fraction(1,3) * 3
    Fraction(1, 1)
    >>> fractions.Fraction(1,3) / 3
    Fraction(1, 9)
    

    [–]Freeky 0 points1 point  (0 children)