(no title)
yogsototh | 2 years ago
1 + x * 2 - 3 % x
is longer to decipher than (% (- (+ (* x 2) 1) 3) x)
which is itself harder than (-> x (* 2) (+ 1) (- 3) (% x))
But it takes a while to be used to it.
And yes, it really helps writing macros, but I wouldn't say this as always be a good thing. Macros are far from being the alpha and omega of programming, as they add an implicit layer of transformation to your code making it easier to write but very often harder to read and reason about.
perrygeo|2 years ago
It was the ah-ha moment for me... why not express the source cost directly as that AST? Most languages require lots of ceremony and custom rules just to get here. Sexps are a step ahead (inherently simpler) since they're already parsable as an unambiguous tree structure. It's hard to unsee - reading any non-Lisp language now feels like an additional layer of complexity hiding the real logic.
munificent|2 years ago
Sure, s-exprs are much easier to parse. But the compiler or runtime still needs to report an error when you have an s-expr that is syntactically valid but semantically wrong like:
Kicking that down the road is a feature because it lets macros operate at a point in time before that validation has occurred. This means they can accept as input s-exprs that are not semantically valid but will become after macro expansion.But it can be a bug because it means later phases in the compiler and runtime have to do more sanity checking and program validation is woven throughout the entire system. Also, the definition of what "valid" code is for human readers becomes fuzzier.
packetlost|2 years ago
baq|2 years ago
sbergot|2 years ago
zelphirkalt|2 years ago
Paul-Craft|2 years ago
digdugdirk|2 years ago
Is there a recommended "intro to understanding lisp" resource out there for someone like myself to dive in to?
Capricorn2481|2 years ago
So it basically breaks this down into a list of instructions to do to x. You will multiply it by 2, add 1 to it, take 3 from it, then do the modulus by the original value of x (the value before any of these steps).
Clojurists feel like this looks more readable than the alternative, because you have a list of transformations to read left to right, vs this
Which is the most unreadable of them all, to me.teamonkey|2 years ago
andsoitis|2 years ago
Practical Common Lisp - https://gigamonkeys.com/book/
Casting SPELs in Lisp - http://www.lisperati.com/casting.html
Structure and Interpretation of Computer Programs - https://mitp-content-server.mit.edu/books/content/sectbyfn/b...
One of many prior discussions here on HN: https://news.ycombinator.com/item?id=22913750
... amongst many resources for learning LISP.
nkh|2 years ago
https://www.braveclojure.com/clojure-for-the-brave-and-true/
kazinator|2 years ago
The expression (% (- (+ (* x 2) 1) 3) x) corresponds to the parse
I would simplify that before anything by folding the + 1 - 3: Thus: Also, in Lisps, numeric constants include the sign. This is different from C and similar languages where -2 is a unary expression which negates 2: two tokens.So you never need this: (- (+ a b) 3). You'd convert that to (+ a b -3).
Trailing onstant terms in formulas written in Lisp need extra brackets around a - function call.
_dain_|2 years ago
"take x, times it by 2, add one, subtract 3, take modulus with the original x".
It's pretty much how you'd type it into a calculator.
EDIT: care to explain the downvote?
Ologn|2 years ago
This is the main thing I use Lisp (well, Guile Scheme) for. I used to use bc for little scratch pad calculations, now I usually jump into Scheme and do calculations. I don't recall if I thought it looked like gibberish at first but it's intuitive to me now.
_aaed|2 years ago
mlajtos|2 years ago
x * 2 + 1 - 3 % x
https://mlajtos.mu/posts/new-kind-of-paper-2
rileyphone|2 years ago
x.*(2).+(1).-(3).%(x)
Unfortunately our brains are broken by pemdas and need clear delineations to not get confused; this syntax also extends to multiple arguments and is amenable to nesting.
todd8|2 years ago
Tainnor|2 years ago
But if we're talking more generally, if I have an expression like
a trained eye immediately can read off the coefficients of the polynomial and I'm not sure if that's true ofzelphirkalt|2 years ago
drBonkers|2 years ago
Love the single pipe operator. What language works this way?
Folcon|2 years ago
agumonkey|2 years ago
mmphosis|2 years ago
Tyr42|2 years ago
Or use flip -. But you can avoid growing the stack long enough to be confusing.
kazinator|2 years ago
"Start with 10; add 5; divide by 3; ..."
:)
rpz|2 years ago