freenode/#lisp - IRC Chatlog
Search
17:12:24
pjb
LdBeth: about RPN, just try to implement a macro (rpn c a ² b ² + √ +) -> (+ c (√ (+ (² a) (² b))))
17:12:53
pjb
LdBeth: also, there would be a problem with side effects and left-to-right evaluation rule of lisp…
17:22:50
LdBeth
asarch: it’s easy from sexp to RPN, but hard from RPN to sexp without prior knowledge about which are operator
17:35:31
pjb
asarch: arity = number of parameters. But in lisp, arithmetic operators take any number of arguments from 0 to call-arguments-limit, and in general, a macro cannot know how many mandatory argument are required for a given operator (function or macro), notably because it may be macroexpanded before the operator is defined!
17:35:57
pjb
This is why we kept using lists: so that macros (and code walkers) could be implemented easily.
17:42:06
aeth
The macro for an RPN-style s-expression would just do something like: `(,(car (last foo)) ,@(butlast foo))
17:43:55
pjb
(defun rreverse (sexp) (if (atom sexp) sexp (mapcar (function rreverse) (reverse sexp)))) (rreverse '(+ c (√ (+ (² a) (² b))))) #| --> ((((b ²) (a ²) +) √) c +) |#
17:44:10
aeth
You don't want true RPN outside of a calculator imo so this is a better way of doing it. And it's not hard to apply to every element. Just every ,@(every #'my-transformation (butlast foo))
17:46:55
aeth
CL's confusing because it has nicer named things that have no difference (like first) and nicer named things that are different
17:49:26
aeth
(defun r-expression-to-s-expression (r) (typecase r (cons `(,(car (last r)) ,@(mapcar #'r-expression-to-s-expression (butlast r)))) (t r))) ; put this in a macro and add a special case for dotted lists if you want to support them in r-expressions
17:51:39
pjb
Of course, you can implement a rpn language, but you will have to explicitely define all your rpn operators. You cannot just call random lisp functions.
17:52:20
pjb
(define-rpn-operator + 2 +) (define-rpn-operator - 2 -) (define-rpn-operator neg 1 -) etc…
18:05:35
aeth
pjb: Just one clarification. I don't think r-expressions would reverse everything, just put the first item last in an evaluated list (which means I need to add a special case for QUOTE (and FUNCTION), which I didn't do). If they're like RPN the only difference is that the operator is at the end, e.g. in my RPN calculator 4 2 / => 2
18:07:25
aeth
So going to an r-expression would be a bit trickier. Naively, this: (let ((foo '(+ 1 2 3))) (append (cdr foo) (list (car foo))))
18:14:39
pjb
aeth: well this means you have to delay the evaluation of variables. Usually in RPN, variables are evaluated and their value is stacked. If you want to use the quote operator after, unless you look ahead, you would have to let allt the operators evaluate the variables. I'd say this would set a bad precedent.
18:18:13
aeth
pjb: The main problem is that ((1 2 3) quote) becomes '(3 1 2) and another problem is that people are used to ' and #' as syntax, but they can't just write '(1 2 3) in r-expressions without a custom reader and writer.
18:18:57
aeth
You can do that, but you're still going to have to deal with QUOTE as a special case to avoid the '(3 1 2) problem
18:19:44
pjb
But the point is that RPN is a new syntax, you have to parse it, and you cannot just convert a kind of rpn sexp into a sexp. It's antithetical to the S-exprs and lisp.
18:20:24
pjb
And the Texas Instrument patent on parentheses in calculators is over since a long time.
18:20:48
aeth
Polish notation would have the same problem. * + 1 1 2 when you can just (* (+ 1 1) 2)
18:22:01
aeth
RPN is a write-only language. A very useful one, but definitely write-only. That's why it's mainly used in calculators and programs like dc. And people accuse Perl of being write-only!
18:23:19
stylewarning
Functions (known as “words”) are orders of magnitude shorter than their Lisp equivalents
18:26:13
aeth
I use nested brackets even with my infix arithmetic. Never trust your knowledge of precedence to always work. And never trust the reader to understand all of those rules, too. And this example would need it in infix, anyway. (1 + 1) * 2
18:27:35
pjb
C has 27 precedence levels. C++ even more. Smalltalk is quite unintuitive too. Infix is bullshit.
18:27:35
stylewarning
Brackets can also blur cases where you actually don’t care about order, as with associative operators
18:28:11
aeth
Mathematics is two dimensional. It's a lot easier to express something clearly on paper or generated from LaTeX than it is to express it in one line of ASCII that pretends to be mathematics.
18:29:41
stylewarning
A reminder that there exists CMU-INFIX for Lisp https://github.com/rigetticomputing/cmu-infix
18:30:07
pjb
So when you're fed up with all this bullshit, you just write (+ 2 (* 3 5)) or (* 5 (+ 2 3)) and go on with your life.
18:31:44
aeth
If I met someone with a degree from "CMU" I'd say "When did you get that? 20 years ago? Should've gone to Steel Bank instead."
18:33:08
aeth
shka_: Yeah, but it's not like it's one of the top computer science universities in the United States.
18:34:25
aeth
I think traditionally, MIT, CMU, Berkeley, and one other are considered "tied". Can't think of the last one at the moment.
18:36:16
aeth
e.g. https://www.usnews.com/best-graduate-schools/top-science-schools/computer-science-rankings
18:55:18
aeth
This was just on HN, about the history of T, and one of the early points a few paragraphs in is that the move to 32-bit changed everything in how you represent your data. http://www.paulgraham.com/thist.html
19:02:41
pjb
Spreadsheets, word processors, IDE including editors, compilers and debuggers all ran in 64 KB (actually usually much less, since some memory space was taken by devices or video memory).
19:04:10
pjb
Notice that the 7090 on which LISP 1.5 ran had only 32 KW of memory, so just a tad over twice that memory. (32 KW @ 36-bit = 144 KB).
19:04:31
aeth
pjb: but I want unboxed single-floats and large unboxed fixnums, so I wouldn't want to time travel to before 2003 or so. And this is 64-bit vs. 32-bit. 16-bit sounds like a nightmare.
19:06:17
aeth
Well, if you had expensive hardware you could probably get by in the past after 1985 or so.
19:07:51
pjb
But really, in 1975, you'd be happy with a 6502 and 1 KB of SRAM, and writing programs directly in hexadecimal…
19:08:29
pjb
The alternative was access to mainframes, which means, writing fortran or cobol on paper and waiting a day or two to know if you had compilation errors.
19:11:16
aeth
pjb: In 1975 I wouldn't know what I was missing and I'd happily program in a high level language like Fortran.
19:44:13
aeth
I wonder when Lisp became an acceptable Fortran. Or at least, close enough that with modern hardware we don't care.
19:47:59
p_l
AMEX was using Symbolics Common Lisp as dev platform and Allegro CL as late as around 2000
19:49:15
aeth
Yeah, but big companies are always a decade behind in tech so that doesn't surprise me.
19:53:20
Demosthenex
funny, i teach my son lisp, and we compare it to python. i show him how he can edit "blocks" of code with emacs, and they snap together, but python you have to hand write and move everything. he says lisp is easier and makes more sense
19:54:25
p_l
Demosthenex: Python has the (general) advantage of providing what once commercial compilers arrived with - a complete teaching manual
19:54:34
Demosthenex
we've been working on a text mode game, and he was interested in the A* and dijkstra's pathing algos
19:55:12
aeth
Demosthenex: I probably already showed this to you, but have you seen this? https://borodust.org/projects/trivial-gamekit/
19:55:42
Demosthenex
we're just doing a text game as a demo, interactive fiction style, like zork or a mud
19:55:45
p_l
Unfortunately, the emacs manual doesn't explain how the original approach worked, so people do whatever... And it often leads to pain
19:56:36
Demosthenex
atm in my pet project, i'm outgrowing views to allow me to query json data in postgres. so i may have to remap and parse the json and use postmodern to maintain several other tables. fun stuff
19:57:27
Demosthenex
it's pretty sweet that postgres can read raw json in a column, and you can use views to create a "virtual" table from that... but the operations are slow, especially with numbers.
19:58:06
Demosthenex
postmodern includes the new upsert syntax, and i've already hacked it to do dynamic table creation with column dedup, so why not just spam into real tables ;]
20:00:00
Demosthenex
was nice to make a POC using 100 lines of CL with a rest api and postmodern though
1:14:44
dim
Demosthenex: do it the other way around, store data in a normalized relational design and build JSON as a query output
1:15:38
dim
Demosthenex: have a read of https://tapoueh.org/blog/2017/09/on-json-and-sql/ to see how to normalize JSON documents in a relational database
4:09:12
csgator
hi all, I am a young programmer and I want to learn lisp as a hobby project because I read about it in paul graham's book hackers and painters. The way he describes lisp it seems to be the holy grail of languages , what do you guys think does learning lisp make you a better programmer ?
4:10:40
csgator
haha fair point. I just want to know as an outsider why you guys think lisp is so good ?
4:12:56
no-defun-allowed
learning lisp made my datefriend think about other languages weird, and they told me they couldn't stand C++ after. it likely will make you hate every other language on the planet but hey go for it.
4:13:02
beach
csgator: The condition system is also quite good. Much better than the exception feature of languages like Java.
4:13:47
csgator
so noob question here : let's say I want to build a REST API can I do it in lisp ? does it have enough libraries to do anything one would require in a normal application building ? what I am trying to ask maybe is can I use it to build stuff ? I am convinced that programming languages are increasingly becoming more lisp like
4:13:47
beach
Oh, sure, if you compare to a language without automatic memory management, Common Lisp looks even better. But most sane languages these days have that.
4:15:24
beach
csgator: Not my domain of expertise, but I am pretty sure there are libraries for that. Other languages won't become Common Lisp until they also look like it, and then they might as well *be* Common Lisp.
4:16:06
csgator
so what do you guys use lisp for ? just trying to gather info on where it is being used :)
4:16:08
beach
csgator: It is trues that for *almost* every feature of Common Lisp, you will find some language that has it. But you won't find a language other than Common Lisp that combines all those features.
4:16:31
no-defun-allowed
i use hunchentoot but caveman2 is also an option (if you can mind the god awful Python @tagging things)
4:17:06
beach
csgator: Here is a nice quotation from Kent Pitman: https://www.wisdomandwonder.com/link/1018/please-dont-assume-lisp-is
4:17:20
csgator
beach : that is exactly the point paul graham mentions in his book which made me wonder, why is the software world going backward and if so why even bother with a fancy new language every year, we could just use lisp for everything
4:18:35
beach
csgator: Because there are strong psychological forces at work. People are not rational and they are willing to waste arbitrary amounts of time not to learn Common Lisp.
4:18:58
beach
csgator: There is an entire domain now called "behavioral economics" that will explain such behavior.
4:19:43
beach
In the meantime, here is a short essay on the subject: http://metamodular.com/Essays/psychology.html
4:21:03
no-defun-allowed
still they don't quite get why we avoid SETF and friends when possible in lisps but they know a lot of CL and scheme
4:21:58
no-defun-allowed
i said it's easier to analyse since SETF can set whatever but they say understanding functional code is hard already
4:22:18
csgator
beach: got your point, thanks. I am going to spend the next few weeks learning lisp just for the fun of it and also because many smart people I know have suggested learning lisp. I'll be using this channel to get help when stuck