Replies: 1 comment
-
I'm actually working on this, turns out something I'm working on would make a lot of use of having the ability to default arguments at definition for optional args and keyword args, along with allowing a variadic amount of args while using keys simultaneously. Reasoning is I'd end up with a lot of code that does a check on defaults otherwise (assuming the rest of the code I'll be writing follows a similar ordeal). It'll end up being pretty close to what I see in common lisp for this, vs something like described above. Yes, variadic args can interfere with optional or keyword args in any case, the idea I'm using is opt and keyword args can't be used simultaneously, keywords can only eat keyword matches and if variadic contains keyword matches that match keywords then they'll get eaten in the event the keyword isn't specified prior. Same with optionals, they'll just eat the args up till runing out of optionals then the rest will go into the variadic arg. |
Beta Was this translation helpful? Give feedback.
-
Just noting, tried this in the repl, maybe I'm doing it wrong and someone can correct me, but it would seem that this isn't possible (without redefining defn or creating a new kind of defn [defun maybe?])...
The thing I was trying is something like
I think in general the way to maybe handle things like this is to write a macro, that returns a macro that expands to an actual function call...
Basically, you'd define a function with the new macro
defun
, then it would return a macro. So say you do(defun blah [args])
, when you call it it'd create a bindingblah
that is a macro, and that macro would then be expanded anytime you callblah
to call something calledblah_implmenetation
in actuality. So say you did a defun, like the thing I was trying...blah_implementation
's function definition would end up actually being(blah_implementation [a b a2 b2] (print ...))
.Now to take it further, say you want to define another blah that only operates with one argument... the
defun
macro could return a macro that selects ablah
based on arg count and arg type.And yes, blah is a very poor choice for a function name, I lack creativity for names for things that are hypothetical.
Beta Was this translation helpful? Give feedback.
All reactions