libera/#commonlisp - IRC Chatlog
Search
19:18:34
dbotton
If I am passed a function is there a way to determine the number of parameters needed to call that function?
19:21:13
pjb
dbotton: function-lambda-expression, but it may return nil, so nothing standard. Look in swank for implementation specific functions and portability layer.
19:21:41
edgar-rft
dbotton: you an try to analyze the return value of FUNCTION-LAMBDA-EXPRESSION but it's allowed to return NIL
19:23:43
yitzi
dbotton: https://github.com/yitzchak/common-lisp-jupyter/blob/master/src/cl-jupyter/utils.lisp#L7-L20
19:24:00
pjb
(swank:operator-arglist "OPERATOR-ARGLIST" "SWANK") #| --> "(OPERATOR-ARGLIST name package)" |#
19:41:30
yitzi
Why would you not just parse the lambda list? There are plenty of lambda list parsers out there.
20:22:50
pjb
dbotton: introspection is overhead. Not needed in compiled systems runnin on micro-controlers.
20:23:06
pjb
dbotton: remember, CL is an industrial programming language, specified to be efficient.
20:28:28
aeth
but without details, there's no way of telling what alternative that CL already has would make more sense for the problem
2:01:06
hexology
is there some tool that can show me a diff between sexprs? it might be useful when debugging and/or testing a macro, to see what exactly differs between my expected output and my broken stupid macro
2:22:09
lips123mob
hexology: Good question. I would suggest a different route (more practice with macros until it becomes second nature)
2:22:42
lips123mob
As to your question, a naive way would be to compare each list and it’s children recursively and flagging differences
2:23:16
lips123mob
Where this fails is say you are missing an item in one of the lists, but otherwise the two are identical
2:23:42
lips123mob
once you hit the item that fails, that error would cascade down to the rest of the comparison as you would be off by 1
2:24:12
lips123mob
now you could find ways to resolve that, but you are moving into the territory of parsing incomplete data, which is tricky
2:24:36
lips123mob
A simple way would be to check for missing items, and then put a placeholder for them to let the rest of the match work
2:25:02
lips123mob
alternatively look to match each component individually and find what is left over (not matched)…that might work
2:25:34
lips123mob
but ultimately you would want to understand the semantics of what you are trying to write to perform the best possible matching
2:26:22
lips123mob
ultimately to do this right, you would need decent error recovery strategies whilst parsing the lists
2:31:08
hexology
that's a good point about the parsing incomplete data. i assume at some point you either give up, or just let it pinball through your algorithm and make no guarantee about the results
2:32:37
lips123mob
Yes exactly. I think the idea of matching each sub list and “ticking” them off between both lists will get you a reasonable outcome (leaving the ones which don’t appear in the other)
2:33:16
hexology
right. you could probably come up with some rough "edit distance" and adapt the "dynamic time warping" technique for optimal alignment of sequences
2:33:23
lips123mob
yes I think this is where the mythical lisp IDE could help, picking up where forms are left out / incorrect (eg calling a generic method with arguments for which there is no specialisation)
2:34:23
hexology
e.g. pytest in python does a surprisingly good job of showing the diff between what you expected and what you got
2:35:17
hexology
if ML is likely to show up in test frameworks, i would expect that it shows up as something like bayesian black-box optimization in property-based testing
2:35:28
lips123mob
training over a large corpus of lisp code to see likely patterns and then fixing incomplete code based on that to allow error recovery during parsing
2:36:06
hexology
(ironically and 100% unintentionally i pressed enter and failed to complete that message)
2:36:35
lips123mob
a sufficiently smart editor to capture incomplete forms until you jump out of the top level sexp
2:37:03
lips123mob
which could collect a series of information of how the forms are ‘developed,’ from start to finish
2:38:20
lips123mob
its a fascinating subject, alas one needs to some spend some serious time to cover it off. hopefully someone does one day
2:39:04
hexology
i could see something like that being built for a more popular language like python, or perhaps something that needs more "help" in writing correct code like ruby
2:39:43
lips123mob
yes. agree. it can get in your way too - if it pushes you down the path of bad design patterns
2:42:01
lips123mob
yeah, less abstraction / more repetitive code. using it just for error recovery during parsing shouldn’t have that much of an impact, but it might still subtly point you in a direction based on pre-existing paths
2:43:44
lips123mob
have you been writing helper functions that create macro code? I find that helps a lot
4:27:32
hexology
looks like they left, but testing such helper functions is exactly the kind of use case where i'd want an s-expr diff engine!