libera/#commonlisp - IRC Chatlog
Search
20:09:21
Arcsech
Just discovered https://github.com/marcoheisig/the-cost-of-nothing and spent a few minutes running the standard suite across (sbcl/ccl/abcl/ecl/clisp)
20:09:59
Arcsech
Sample:... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/94b3ea570a9b93202b7564de62678c44cfad3dd3)
20:16:25
Arcsech
The order goes very roughly from slow to fast: clisp, ecl, abcl, ccl, sbcl, with ccl and sbcl being much faster than any of the others (for this super limited benchmark). Might do a bit more exploration along these lines.
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.