libera/#commonlisp - IRC Chatlog
Search
21:57:32
Spawns_Carpeting
can the first element of a lisp expr be anything other than an atom in a valid program?
21:59:12
hayley
There wouldn't be a parent node, because there isn't a parent of this program fragment.
21:59:34
hayley
This code designates a call to the function (lambda (x) x) with the single argument 1.
22:00:47
Spawns_Carpeting
that's what I thought too dre, but I don't know how you could walk that tree to generate bytecode instructions
22:01:21
Spawns_Carpeting
a more convention style AST where each operator is a node, and its children are the parameters makes it easier to do that
22:01:55
hayley
Can't say more without knowing your bytecode, but in e.g. the Netfarm VM we would write (BYTE 1) (BYTE 2) (GET-PROC <code for LAMBDA function>) (CALL 2)
22:03:50
Spawns_Carpeting
I wonder if a non-lisp language would make a better first programming language to try to implement from scratch. Any thoughts about that?
22:04:13
Spawns_Carpeting
I figured the syntax would be trivial to parse but i find it maybe more confusing
22:05:00
Spawns_Carpeting
it doesn't help that I don't have any formal education in parsers or anything like that, and all of the resources I can find are creating ASTs for non-lispy langs
22:05:37
hayley
I don't think you really need an AST if you aren't doing much analysis on it. Just pattern match on the list structure you were given.
22:05:57
lisp123
Spawns_Carpeting: 1000s of people have tried to find a better approach than lisp. There isn't :)
22:06:53
Spawns_Carpeting
what order do you walk the tree to generate ops in the right order hayley? It might seem like a stupid question but I couldn't figure out a way to do that easily
22:07:29
Spawns_Carpeting
i think you just have to walk it backwards, from the bottom rightmost part to the first node? does that sound correct?
22:08:23
hayley
Arguments then the function, handling the most nested forms first. So (f x (g y)) compiles to (read Y) (call G) (read X) (call F)
22:09:55
hayley
Don't think of it as a global tree traversal though, with depth or breath-first search or whatever. Just think of each type of expression, and how you would generate code for it. e.g. for a form like (F X) I need to generate code to load X, then call F. For (F (G X)) I need to generate code to load (G X), which consists of loading X and calling G...
22:11:09
Alfr
hayley, you can't do that. You need to read and stash x before calling g on y; e.g. when x is special and g sets it.
22:11:53
hayley
Right, it depends on evaluation order of arguments, and CL is defined to use left-to-right evaluation.
22:23:36
hayley
It depends on the language you are implementing, and how the bytecode stores arguments. The Netfarm VM uses a stack machine, and the first argument is pushed first.
22:24:23
hayley
If I swapped around (read X) and (read Y) (call G), the arguments would be in the wrong order (which is what Alfr pointed out).
22:28:41
hayley
If you look at the definition for instruction #9 (CALL) in https://theemacsshibe.gitlab.io/documentation/Netfarm_script_machine.html#%28part._.Instructions%29 I specified that the last function argument is the first value on the stack after the function to call.
22:29:46
hayley
(Note that this specification is often too formal for human consumption, myself included.)
1:06:13
hayley
It depends on the encoding of the file, and the default encoding that SBCL uses on your computer.
3:44:04
beach
Spawns_Carpeting: What is your objective with this work of yours? I can tell you how the Cleavir AST would look for an expression like the one that hayley showed, but that may be pointless depending on your objective.
3:49:33
beach
The AST would have a parent node "function application", and it would have two children. The first child would be "function", and the second a list of arguments.
3:50:56
beach
The "function" node would then either be a "named function" AST if the operator is a symbol, or it would be an "anonymous function" AST if the operator is (lambda (x) x) as in the example hayley gavce.
4:01:46
Spawns_Carpeting
that makes sense, I think I keep getting the parse tree and the AST mixed up
4:02:18
Spawns_Carpeting
AST doesn't really care that much about lists or atoms and whatnot, just about expressions
4:03:17
Spawns_Carpeting
my first AST was a flat list for each sexpr rather than an actual tree for example
4:03:24
beach
Right. The Lisp "parse tree" for something like ((lambda (x) x) 1) is trivial, and completely specified.
4:04:51
beach
... It is a proper list of two elements. The first element is a list of three elements, and the second element is 1.
4:10:22
Spawns_Carpeting
i guess I should just ignore lambdas and more advanced stuff for a while anyways
4:17:49
Spawns_Carpeting
its just a bytecode thing for now, technically it's nothing because nothing does anything or works at all
4:18:12
Spawns_Carpeting
this is my first time doing anything related to programming langs and parsers and stuff
4:21:23
beach
Well, that's why I asked about the objectives. You can omit whatever you like if you just want to learn by tinkering a bit. But if you want to compile Lisp, you need to handle all possible constructs.
4:23:42
minion
Spawns_Carpeting: Cleavir: A project to create an implementation-independent compilation framework for Common Lisp. Currently Cleavir is part of SICL, but that might change in the future
4:23:55
minion
Spawns_Carpeting: SICL: SICL is a (perhaps futile) attempt to re-implement Common Lisp from scratch, hopefully using improved programming and bootstrapping techniques. See https://github.com/robert-strandh/SICL
5:53:36
hayley
Spawns_Carpeting: I sort of ignored functions with my first "Lisp" interpreter, and trying to write less trivial programs drove me up a wall.
6:07:34
hayley
I could also provide my own bytecode compiler, but it would be tricky to follow, as you'd need to keep the bytecode specification and intermediate languages in mind. But my (lazy) approach is to replace variable references in the input language with De Brujin indices, and then generate linear bytecode.
6:08:54
hayley
Spawns_Carpeting: See https://gitlab.com/Theemacsshibe/slacker-compiler#input-language and then the "Intermediate language" grammar.
6:09:33
gin
I too want to write my own tiny Lisp interpreter (or something like it) but don't know where to start. is it necessary to read the dragon book first?
6:10:49
hayley
Yes, in <https://gitlab.com/cal-coop/netfarm/netfarm/-/tree/master/Code/Scripts/Script-machine>. But it is a bit over-optimized, so I would prefer to refer people to <https://cal-coop.gitlab.io/netfarm/documentation/Netfarm_script_machine.html#%28part._.Script_execution%29>
6:10:59
gin
spiaggia: yes, a hobby project. yes, to learn how it is done and also to use it myself at least to write trivial programs
6:11:15
hayley
But, if you haven't written any interpreter before, I would also recommend you start with a "tree walking" interpreter which doesn't bother with bytecode.
6:11:47
gin
hayley: by tree walking, do you mean do a recursive descent in the abstract syntax tree and evaluate each node on the fly?
6:12:28
hayley
Yes, but you don't even have to bother with producing an AST. Just dispatch on the nested list structure.
6:12:42
spiaggia
gin: Lisp in Small Pieces is more modern, but I like them both for different reasons.
6:13:18
Spawns_Carpeting
I will check that out tomorrow hayley thanks. I am heading to bed right now and will be back tomorrow!
6:13:51
Spawns_Carpeting
also gin maybe we could chat sometime since we are both working on very similar things!
6:14:18
gin
lisp in small pieces - 500 pages. sounds like going to take hard work. have to plan time for it.
6:14:57
hayley
The book covers a few interpreters (tree walking and bytecode) and then compilation to C, so it makes good use of 500 pages to me.
6:15:41
gin
anatomy of lisp - 464 pages. so two hefty books. will start with only one. out of anatomy of lisp and lisp in small pieces which one do you recommend me, a beginner who has never implemented an interpreter?
6:16:42
Spawns_Carpeting
the VM is just a standard VM with asm like opcodes, the source language is what I want to be lisp like
6:17:54
Spawns_Carpeting
so you write lispy programs, it gets compiled to your standard PUSH/POP/JUMP style opcodes
6:18:17
gin
anyone has learnt programming with Logo here? always wanted to ask, is Logo really a dialect of Lisp? i see it mentioned often.
6:19:02
hayley
I dunno, but based on (fortunately) infrequent discussions, I sometimes wonder if Common Lisp is a dialect of Lisp.
6:19:10
spiaggia
gin: Good. And the translation was made by an excellent translator, making the English version better than the original.
6:20:00
gin
Spawns_Carpeting: goal is to create a small Lisp or Lisp-like language for fun, learning, and also using it to solve small problems like tiny calculations for which I usually use python these days.
6:20:01
spiaggia
gin: In fact, the translator was the only person who got promoted to "distinguished writer" at the French ILOG company that used to sell Lisp systems and tools.
6:20:34
hayley
(Of course, the answer is no, CL is very clearly Smalltalk. They both have late binding of most things, useful type systems, and no datum that isn't an object :)
6:21:24
spiaggia
gin: And if you bring your copy of Lisp in Small Pieces to ELS, she will sign it for you.
6:21:29
gin
spiaggia: woah! talk about combining two skills to create a very niche set of skills. i have often heard this advice is that the best way to make a mark in the world is to take two good skills you have and combine them because the combination would become a niche set of skills that very few other people may have
6:24:42
hayley
There's a physical location for ELS 2022 (the ELS this year happened last May), but no mention of an online part on the ELS website.
6:25:13
hayley
Oh, helps if I check my emails. Didier Verna said "We will also arrange to remain hybrid so that people can physically attend, or follow online!"
6:26:29
susam
I am new to this community, by the way. I began joining this channel only since last year although I have been on IRC for 15 years. Attended the last ELS virtually. The talk on Extempore blew my mind. I would like to attend this year's too. Perhaps virtually because I don't live in Europe.
6:29:18
hayley
I had hoped to visit last year (from Australia), and also catch the last tour of The Stranglers if possible, but both were stopped by the pandemic. I'll see what I can do for ELS 2022.
6:31:16
spiaggia
hayley: It is worth going. Just putting a face to many of the people we interact with is worth it.
6:32:33
susam
Very nice. I will probably only be a visitor (a lurker). Hoping to participate some day. Although I learnt CL long time ago, it is only recently that I have begun using it seriously for some of my hobby projects.
6:35:04
susam
gin: Yes, Logo has had a lot of Lisp influence. I talked to an LCSI Logo developer sometime back and the LCSI logo (which is the same as Atari Logo and IBM PC Logo) were developer by experienced Lispers. Emacs + an assember written in Lisp + a debugger written in Lisp were their development tools.
6:35:05
spiaggia
susam: I don't know if you habitually go to computing conferences, but you can be a participant without presenting anything, and in fact, most people are. There might be 15 presentations or so, for around 90 participants. The thing about going is not so much about the presentations, but about the discussions with the participants during the breaks, or over meals and coffee breaks.
8:06:14
pve
Hi, is it stylistically ok to use strings in a defpackage form, e.g. (:export "CAT" "MEOW" "PURR" ...)?
8:12:06
beach
pve: I personally think it looks ugly if you then use lower-case letters in the code, which is why I use uninterned symbols instead.
8:14:23
beach
The other problem with strings is that it may not work when the readtable changes. If you use uninterned symbols, there is a better chance that the name of the symbol you use in code is going to be the same as that of the uninterned symbol. I am thinking particularly of Franz "modern mode".
8:18:06
pve
beach: Ok thanks. Now that I think about it, this might even be just a matter of syntax highlighting. I like how the strings stand out a bit among the keywords.
8:20:27
beach
pve: I have said this several times, but let me say it again: Emacs syntax highlighting is mediocre at best. It doesn't take different roles of symbols into account. It seems wrong to highlight all uninterned symbols the same no matter the role, and it seems wrong to highlight all strings the same too.
8:21:00
beach
pve: I use Emacs for Common Lisp programming only because we don't have anything better yet. But we are working on it.
8:23:28
JeromeLon
(let ((*message* *messages*)) (do something that indirectly (and temporarily) changes and uses *messages*))
8:23:56
JeromeLon
I remember getting an sbcl warning about this (using lexical variable for a name that looks like a dynamic one)
8:24:26
JeromeLon
But I am not getting it anymore. Does anyone have any idea what circumstances are triggering it?
8:24:46
beach
JeromeLon: It would be highly unusual to initialize a variable with a name in singular form with a variable in plural form.
8:25:18
pve
beach: Oh, are you saying that, for example, exported symbols in a defpackage form (written as uninterned symbols) could be highlighted differently than uninterned symbols elsewhere in the code?
8:26:03
beach
pve: And the strings used in the :EXPORT clause should be highlighted the same as the uninterned symbols in that clause.
8:26:50
cosimone
there are some emacs theems, such as dracula, that do highlight documentation strings differently with respect to other strings
8:27:08
cosimone
however, using a declare expression beforehand fools it into thinking it's a regular string
8:27:40
JeromeLon
beach: or maybe that was my mistake? yes, it was probably a typo, I can reproduce. Thanks!
8:28:20
beach
Nilby: Because, as I said, if the role is the same, the highlighting should be the same.
8:28:22
mfiano
I do not consider _that_ aspect of Emacs highlighting wrong. I wouldn't want it any other way
8:28:23
cosimone
i think a lot of the logic used to highlight common lisp is the same as the one used for emacs lisp, but i could be wrong
8:28:37
loke[m]
I'll have to check the spec, but I'm pretty sure that the declarations have to come after the docstring.
8:28:51
cosimone
i modified color-identifiers.el a bit to account for common lisp, it does provide a nicer and much richer highlighting
8:30:32
cosimone
loke[m]: according to http://www.lispworks.com/documentation/HyperSpec/Body/m_defun.htm#defun, declarations come before documentation
8:31:18
beach
mfiano: Do you think it is fine that 1. The first DEFMETHOD is highlighted as if it were an operator, and 2. that the second DEFMETHOD is not highlighted the same as the first?
8:31:43
mfiano
beach: I wasn't talking about semantic highlighting. I was talking about the atom type differentiations.
8:32:32
beach
mfiano: So in (defpackage ... (:export "FOO" 'bar) you want FOO and bar highlighted differently?
8:32:44
mfiano
I would make lots of mistakes if my uninterned symbol was the same color as a keyword symbol as an argument to a function for example.
8:34:02
beach
On the other hand, if you do (f :foo :foo) and F is (defun f (&key foo)...) I would definitely want the second :foo to be highlighted differently.
8:35:45
beach
I maintain that the role of a token is more important than its exact syntax. And I maintain that Emacs is unable to take the role into account.
8:35:53
mfiano
Why will you "refuse to make suggestions" and "be quiet" over different opinions? Lisp's main strengths include the flexibility it gives programmers and listening to other opinions is always welcome. That sounds sort of a childish response..