r/Clojure • • Sep 08 '21

The only time I get tripped up by prefix notation...

Post image
82 Upvotes

18 comments sorted by

12

u/BipedPhill Sep 08 '21

Simple visual mnemonic. The left part of < is smaller than the right, and < is true if the left arguments are smaller than the right arguments.

5

u/childofsol Sep 08 '21

This is how I handle it, the symbol shows me the order the numbers should be in

10

u/v4ss42 Sep 08 '21

So much this. My thought process is something like: “imagine the > or < is infix, then make sure the crocodile is eating the bigger arg”.

3

u/zeekar Sep 08 '21

That's a cute mnemonic, but it makes more sense to me that the lines get farther apart in the direction of bigger numbers. I just picture the numbers getting taller as their values get bigger.

(< 1 2)

(> 2 1)

which works for any number of numbers... (< 1 2 3 4 5), (> 10 9 8 7 6),

1

u/vvwccgz4lh Sep 14 '21 edited Sep 14 '21

I don't know if I had written much code that was comparing constants to other constants. I think the only way is testing.

It could be used in the context of debugging. But it's too specific and I don't think clojure uses much live debugging.

16

u/Psetmaj Sep 08 '21

I think of them as "ascending args" and "descending args", but double-check in my REPL with something like (< 1 2 3) (read as (ascending? 1 2 3))

6

u/_mhok_ Sep 08 '21

I think of them very similarly as well, i.e. as crescendo and decrescendo from music notation

4

u/NoahTheDuke Sep 08 '21

I hack around this by always using < and writing all such checks in ascending order, even when it’s more “natural” to write it another way, lol.

1

u/Daegs Sep 08 '21

<= (not <) is inverse of >, so you can't just blindly reorder things to <

1

u/NoahTheDuke Sep 08 '21

When it’s needed I use <=, my point is more that I always write my inequalities in ascending order.

3

u/zeekar Sep 08 '21

Just be glad you're not coding for the RPN calculator dc, where "3 2 -" means "3 - 2", but "3 2 >a" means "run a if 2 > 3", for some reason!

2

u/nzlemming Sep 09 '21

I got sick of trying to remember cute mnemonics and now I usually just write the comparison I want in infix and then move the comparison symbol to the front.

1

u/tabidots Sep 08 '21

the one situation where I cave and use an anonymous 1-arity function rather than partial.

1

u/vvwccgz4lh Sep 14 '21 edited Sep 14 '21

The crocodile wants to eat the bigger number

The crocodile can easily eat the smaller number

The crocodile tail wants to run away from the bigger number

The crocodile wants to kick the smaller number using his tail

(< 9000 9001) The crocodile tail has hit the wall and can't run away so easily anymore

(> 9000 9001) The crocodile has turned his head out of desperation because it's the wall already and he wants to run away

-7

u/lgstein Sep 08 '21

Should better not be writing a PhD thesis

8

u/sherdogger Sep 08 '21

And this is why hiring is broken in our industry...someone thinks they know everything they need to know about a person using a "signal" like this.

1

u/lgstein Sep 09 '21

And is right > 50% of the time.