freenode/#lisp - IRC Chatlog
Search
10:36:20
Josh_2
with the MOP can I create a metaclass that will add slots to my class based on the slot-value of another slot?
10:51:02
Josh_2
basically I would like to have a slot within a class with a set name like 'symbol-slots' then when I (make-instance 'special-class :symbol-slots '(a b c d e)) then I will get an instance with the slots symbol-slots a b c d and e.
10:51:52
Josh_2
so the initarg :symbol-slots would be converted to effective slots and appended to my instance
10:57:14
phoe
this sounds like a method on INITIALIZE-INSTANCE that accepts :SYMBOL-SLOTS and goes CALL-NEXT-METHOD with an appropriately frobbed :DIRECT-SLOTS argument
10:57:55
phoe
like, (defmethod initialize-instance ((class special-class) &rest args &key direct-slots &a-o-k) (call-next-method ...))
10:58:32
phoe
where in ... you remove SYMBOL-SLOTS from the ARGS plist and also pass a modified DIRECT-SLOTS argument
11:01:56
phoe
all you want to do is to modify the way in which the instance is initialized, by means of stuffing more direct slot definitions in there
11:43:56
Josh_2
okay so I have made my new effective slots that I want to append, I just don't know how to append them in make-instance
12:18:54
Josh_2
"The generic function update-instance-for-redefined-class is not intended to be called by programmers."
12:21:45
_death
when you evaluate a defclass it may get called, to update instances for redefined class
12:30:27
jmercouris
it is possible, I'm just suggesting that you may wish to go another route if you will find yourself doing things like this
12:32:24
Josh_2
I was basically just messing around and seeing if I *could* do it because I thought it would be a nice way for users to interact with request objects
12:33:06
Josh_2
instead of having to look through a list they could just set/get from a slot, a slot that is dynamically added depending on some data that is passed
12:35:01
Josh_2
well the slots would have to be appended based on the value of an initarg when calling make-instance
12:42:38
jmercouris
"Stealth Mountain (@StealthMountain) is a Twitter bot with a single, simple purpose: It searches for tweets in which a person has typed the words “sneak peak” when they meant to type “sneak peek,” then publishes a reply informing the author of his error. "
12:43:31
_death
if the objective is to learn about the MOP, then I remember AMOP had an example concerning dynamic slot storage
12:45:46
Josh_2
but they have all their slots predefined but wish to only allocate slots when needed
12:47:16
_death
I see.. well, the last time I did something with the MOP was years ago, so someone else may be of help ;)
13:18:13
jackdaniel
you 1) did not paste the macro itself; 2) you did not state the problem correctly
13:20:03
jackdaniel
and it is quite surprising given that a considerable wall of text has been written ,)
13:21:27
phoe
stirring this further will bring no good to either of you or to #lisp, and right now it's both of you stirring this up
13:22:33
jackdaniel
phoe: hm, I consider myself perfectly calm, what i'm saying is that he should state a question which could be reasoned about (i.e correctly state the problem), not really sure how is this stirring things
13:24:48
jmercouris
I've rewritten and destroyed the macro several times, still not able to achieve what I am trying to...
13:25:59
jmercouris
and in execute-extended-command it would be applying like this: (qrt optional-arguments)
13:27:08
phoe
if these come from the DEFINE-COMMAND lambda list, you might want to use ALEXANDRIA:PARSE-ORDINARY-LAMBDA-LIST to get the required/optional/keyword/whatever arguments and such
13:33:20
phoe
these do not depend on each other so we can generate those separately via mapcar, just like jackdaniel mentioned earlier
13:33:38
jmercouris
OK and then finally you have the actual function %qrt which basically wraps everything in with-result
13:33:39
phoe
my code is just somewhat more verbose to avoid double backquote and make explicit separation of concerns
13:34:05
phoe
yes, the actual body of %qrt generates the full form and splices in the results of subfunctions
13:34:52
phoe
(mostly in hope that this technique is somewhat easy to grok and understand and then repeat and reuse)
13:35:36
phoe
I mean, you could probably read the PCS source if you want more examples of this macro style
13:36:08
phoe
except there I use global functions instead of local ones for even more verbosity and ease of REPL-based testing and twiddling
13:37:13
phoe
you can get rid of the intermediate function and stuff its body inside the macro, and things will work.
13:38:10
phoe
and inside https://github.com/phoe/portable-condition-system/tree/master/src the files of interest are assertions.lisp, handlers.lisp, restarts.lisp
13:38:54
phoe
even though that one is really boring except for report methods, because it expands into DEFCLASS :D
13:51:30
phoe
anyway, I think this is how such situations should be handled - in case of not enough information or a poorly specified problem, 1) please ask for more details instead of stating the obvious, 2) please provide more details even if the obvious was stated
13:53:03
phoe
truth be told, this might have ended with a firestorm, some banhammering, and overall bad smell on #lisp if I weren't here to calm things down a bit
14:28:42
gendl
emacs 27.1 warns that package cl is deprecated if we are requiring it at load time. If we can load .elc files, apparently this warning will not happen.
14:29:10
gendl
jmercouris: this isn't the right channel for slime questions? Is there a #slime channel?
14:29:21
mfiano
File a bug ticket with whoever wrote code using the very old cl library. They should be using cl-lib now.
14:30:31
gendl
just found the #slime channel, thanks. btw it looks like slime depends on 'cl just for two symbols.
15:12:16
mfiano
I see. I didn't have enough interest in the real inferior-lisp to go refresh my memory.
17:15:04
Josh_2
I am already storing an association between strings and symbols, I can just create slots from the symbols and use those within compute-slots
18:17:36
Josh_2
I added :readers to :initargs but my instance that uses these new slots doesn't have any associated readers